Skip to content

Commit d90987f

Browse files
committed
Changed unsafe warning method to improove clarity.
This is based on a suggestion from Jed Watson that the UNSAFE_* prefix in the warning message was a little confusing
1 parent 2d8730c commit d90987f

File tree

9 files changed

+32
-30
lines changed

9 files changed

+32
-30
lines changed

packages/react-call-return/src/__tests__/ReactCallReturn-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ describe('ReactCallReturn', () => {
291291
</Call>,
292292
);
293293
expect(ReactNoop.flush).toWarnDev(
294-
'UNSAFE_componentWillMount: Please update the following components ' +
294+
'componentWillMount: Please update the following components ' +
295295
'to use componentDidMount instead: Return',
296296
);
297297

packages/react-reconciler/src/ReactDebugAsyncWarnings.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ if (__DEV__) {
5757
fiber.type[DID_WARN_KEY] = true;
5858
});
5959

60+
const formatted = lifecycle.replace('UNSAFE_', '');
6061
const suggestion = LIFECYCLE_SUGGESTIONS[lifecycle];
62+
const sortedComponentNames = Array.from(componentNames)
63+
.sort()
64+
.join(', ');
6165

6266
lifecyclesWarningMesages.push(
63-
`${lifecycle}: Please update the following components to use ` +
64-
`${suggestion} instead: ${Array.from(componentNames)
65-
.sort()
66-
.join(', ')}`,
67+
`${formatted}: Please update the following components to use ` +
68+
`${suggestion} instead: ${sortedComponentNames}`,
6769
);
6870
}
6971
});

packages/react-reconciler/src/__tests__/ReactIncremental-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ describe('ReactIncremental', () => {
23362336

23372337
ReactNoop.render(<MyComponent />);
23382338
expect(ReactNoop.flush).toWarnDev(
2339-
'UNSAFE_componentWillReceiveProps: Please update the following components ' +
2339+
'componentWillReceiveProps: Please update the following components ' +
23402340
'to use static getDerivedStateFromProps instead: MyComponent',
23412341
);
23422342

packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('ReactIncrementalErrorLogging', () => {
4949

5050
expect(() => {
5151
expect(ReactNoop.flushDeferredPri).toWarnDev([
52-
'UNSAFE_componentWillMount: Please update the following components ' +
52+
'componentWillMount: Please update the following components ' +
5353
'to use componentDidMount instead: ErrorThrowingComponent',
5454
'The above error occurred in the <ErrorThrowingComponent> component:\n' +
5555
' in ErrorThrowingComponent (at **)\n' +

packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ describe('ReactDebugFiberPerf', () => {
255255
);
256256
addComment('Should not print a warning');
257257
expect(ReactNoop.flush).toWarnDev([
258-
'UNSAFE_componentWillMount: Please update the following components ' +
258+
'componentWillMount: Please update the following components ' +
259259
'to use componentDidMount instead: NotCascading' +
260-
'\n\nUNSAFE_componentWillReceiveProps: Please update the following components ' +
260+
'\n\ncomponentWillReceiveProps: Please update the following components ' +
261261
'to use static getDerivedStateFromProps instead: NotCascading',
262262
]);
263263
ReactNoop.render(
@@ -294,11 +294,11 @@ describe('ReactDebugFiberPerf', () => {
294294
ReactNoop.render(<AllLifecycles />);
295295
addComment('Mount');
296296
expect(ReactNoop.flush).toWarnDev(
297-
'UNSAFE_componentWillMount: Please update the following components ' +
297+
'componentWillMount: Please update the following components ' +
298298
'to use componentDidMount instead: AllLifecycles' +
299-
'\n\nUNSAFE_componentWillReceiveProps: Please update the following components ' +
299+
'\n\ncomponentWillReceiveProps: Please update the following components ' +
300300
'to use static getDerivedStateFromProps instead: AllLifecycles' +
301-
'\n\nUNSAFE_componentWillUpdate: Please update the following components ' +
301+
'\n\ncomponentWillUpdate: Please update the following components ' +
302302
'to use componentDidUpdate instead: AllLifecycles',
303303
);
304304
ReactNoop.render(<AllLifecycles />);

packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('ReactIncrementalReflection', () => {
6060

6161
// Render the rest and commit the updates.
6262
expect(ReactNoop.flush).toWarnDev(
63-
'UNSAFE_componentWillMount: Please update the following components ' +
63+
'componentWillMount: Please update the following components ' +
6464
'to use componentDidMount instead: Component',
6565
);
6666

@@ -101,7 +101,7 @@ describe('ReactIncrementalReflection', () => {
101101

102102
ReactNoop.render(<Foo mount={true} />);
103103
expect(ReactNoop.flush).toWarnDev(
104-
'UNSAFE_componentWillMount: Please update the following components ' +
104+
'componentWillMount: Please update the following components ' +
105105
'to use componentDidMount instead: Component',
106106
);
107107

@@ -191,9 +191,9 @@ describe('ReactIncrementalReflection', () => {
191191
expect(ReactNoop.findInstance(classInstance)).toBe(null);
192192

193193
expect(ReactNoop.flush).toWarnDev(
194-
'UNSAFE_componentWillMount: Please update the following components ' +
194+
'componentWillMount: Please update the following components ' +
195195
'to use componentDidMount instead: Component' +
196-
'\n\nUNSAFE_componentWillUpdate: Please update the following components ' +
196+
'\n\ncomponentWillUpdate: Please update the following components ' +
197197
'to use componentDidUpdate instead: Component',
198198
);
199199

packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ describe('ReactIncrementalScheduling', () => {
347347

348348
ReactNoop.render(<Foo step={1} />);
349349
expect(ReactNoop.flush).toWarnDev(
350-
'UNSAFE_componentWillReceiveProps: Please update the following components ' +
350+
'componentWillReceiveProps: Please update the following components ' +
351351
'to use static getDerivedStateFromProps instead: Foo',
352352
);
353353

packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ describe('ReactIncrementalUpdates', () => {
308308
}
309309
ReactNoop.render(<Foo />);
310310
expect(ReactNoop.flush).toWarnDev(
311-
'UNSAFE_componentWillReceiveProps: Please update the following components ' +
311+
'componentWillReceiveProps: Please update the following components ' +
312312
'to use static getDerivedStateFromProps instead: Foo',
313313
);
314314

packages/react/src/__tests__/ReactAsyncClassComponent-test.internal.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ describe('ReactAsyncClassComponent', () => {
184184
'Unsafe lifecycle methods were found within the following async tree:' +
185185
'\n in AsyncRoot (at **)' +
186186
'\n in SyncRoot (at **)' +
187-
'\n\nUNSAFE_componentWillMount: Please update the following components ' +
187+
'\n\ncomponentWillMount: Please update the following components ' +
188188
'to use componentDidMount instead: AsyncRoot' +
189-
'\n\nUNSAFE_componentWillReceiveProps: Please update the following components ' +
189+
'\n\ncomponentWillReceiveProps: Please update the following components ' +
190190
'to use static getDerivedStateFromProps instead: Bar, Foo' +
191-
'\n\nUNSAFE_componentWillUpdate: Please update the following components ' +
191+
'\n\ncomponentWillUpdate: Please update the following components ' +
192192
'to use componentDidUpdate instead: AsyncRoot' +
193193
'\n\nLearn more about this warning here:' +
194194
'\nhttps://fb.me/react-async-component-lifecycle-hooks',
@@ -238,11 +238,11 @@ describe('ReactAsyncClassComponent', () => {
238238
'Unsafe lifecycle methods were found within the following async tree:' +
239239
'\n in AsyncRoot (at **)' +
240240
'\n in SyncRoot (at **)' +
241-
'\n\nUNSAFE_componentWillMount: Please update the following components ' +
241+
'\n\ncomponentWillMount: Please update the following components ' +
242242
'to use componentDidMount instead: AsyncRoot, Parent' +
243-
'\n\nUNSAFE_componentWillReceiveProps: Please update the following components ' +
243+
'\n\ncomponentWillReceiveProps: Please update the following components ' +
244244
'to use static getDerivedStateFromProps instead: Child, Parent' +
245-
'\n\nUNSAFE_componentWillUpdate: Please update the following components ' +
245+
'\n\ncomponentWillUpdate: Please update the following components ' +
246246
'to use componentDidUpdate instead: AsyncRoot, Parent' +
247247
'\n\nLearn more about this warning here:' +
248248
'\nhttps://fb.me/react-async-component-lifecycle-hooks',
@@ -313,13 +313,13 @@ describe('ReactAsyncClassComponent', () => {
313313
'\n in AsyncRootOne (at **)' +
314314
'\n in div (at **)' +
315315
'\n in SyncRoot (at **)' +
316-
'\n\nUNSAFE_componentWillMount: Please update the following components ' +
316+
'\n\ncomponentWillMount: Please update the following components ' +
317317
'to use componentDidMount instead: Bar, Foo',
318318
'Unsafe lifecycle methods were found within the following async tree:' +
319319
'\n in AsyncRootTwo (at **)' +
320320
'\n in div (at **)' +
321321
'\n in SyncRoot (at **)' +
322-
'\n\nUNSAFE_componentWillMount: Please update the following components ' +
322+
'\n\ncomponentWillMount: Please update the following components ' +
323323
'to use componentDidMount instead: Baz',
324324
]);
325325

@@ -353,7 +353,7 @@ describe('ReactAsyncClassComponent', () => {
353353
}).toWarnDev(
354354
'Unsafe lifecycle methods were found within the following async tree:' +
355355
'\n in AsyncRoot (at **)' +
356-
'\n\nUNSAFE_componentWillMount: Please update the following components ' +
356+
'\n\ncomponentWillMount: Please update the following components ' +
357357
'to use componentDidMount instead: Foo' +
358358
'\n\nLearn more about this warning here:' +
359359
'\nhttps://fb.me/react-async-component-lifecycle-hooks',
@@ -362,7 +362,7 @@ describe('ReactAsyncClassComponent', () => {
362362
expect(() => rendered.update(<AsyncRoot foo={false} />)).toWarnDev(
363363
'Unsafe lifecycle methods were found within the following async tree:' +
364364
'\n in AsyncRoot (at **)' +
365-
'\n\nUNSAFE_componentWillMount: Please update the following components ' +
365+
'\n\ncomponentWillMount: Please update the following components ' +
366366
'to use componentDidMount instead: Bar' +
367367
'\n\nLearn more about this warning here:' +
368368
'\nhttps://fb.me/react-async-component-lifecycle-hooks',
@@ -411,13 +411,13 @@ describe('ReactAsyncClassComponent', () => {
411411
}).toWarnDev([
412412
'Unsafe lifecycle methods were found within the following async tree:' +
413413
'\n in AsyncRoot (at **)' +
414-
'\n\nUNSAFE_componentWillMount: Please update the following components ' +
414+
'\n\ncomponentWillMount: Please update the following components ' +
415415
'to use componentDidMount instead: Foo' +
416416
'\n\nLearn more about this warning here:' +
417417
'\nhttps://fb.me/react-async-component-lifecycle-hooks',
418418
'Unsafe lifecycle methods were found within the following async tree:' +
419419
'\n in AsyncRoot (at **)' +
420-
'\n\nUNSAFE_componentWillMount: Please update the following components ' +
420+
'\n\ncomponentWillMount: Please update the following components ' +
421421
'to use componentDidMount instead: Bar' +
422422
'\n\nLearn more about this warning here:' +
423423
'\nhttps://fb.me/react-async-component-lifecycle-hooks',

0 commit comments

Comments
 (0)