Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0a521b

Browse files
authored
Make component stack last argument for deprecation warnings (facebook#16384)
1 parent 1fd3906 commit e0a521b

11 files changed

+75
-93
lines changed

packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.internal.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ describe('ReactDeprecationWarnings', () => {
6464
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
6565
'Warning: Component "Component" contains the string ref "refComponent". ' +
6666
'Support for string refs will be removed in a future major release. ' +
67-
'We recommend using useRef() or createRef() instead.' +
68-
'\n\n' +
69-
' in Component (at **)' +
70-
'\n\n' +
71-
'Learn more about using refs safely here:\n' +
72-
'https://fb.me/react-strict-mode-string-ref',
67+
'We recommend using useRef() or createRef() instead. ' +
68+
'Learn more about using refs safely here: ' +
69+
'https://fb.me/react-strict-mode-string-ref' +
70+
'\n in Component (at **)',
7371
);
7472
});
7573
});

packages/react-dom/src/__tests__/findDOMNode-test.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,12 @@ describe('findDOMNode', () => {
120120
expect(() => (match = ReactDOM.findDOMNode(parent))).toWarnDev([
121121
'Warning: findDOMNode is deprecated in StrictMode. ' +
122122
'findDOMNode was passed an instance of ContainsStrictModeChild which renders StrictMode children. ' +
123-
'Instead, add a ref directly to the element you want to reference.' +
124-
'\n' +
123+
'Instead, add a ref directly to the element you want to reference. ' +
124+
'Learn more about using refs safely here: ' +
125+
'https://fb.me/react-strict-mode-find-node' +
125126
'\n in div (at **)' +
126127
'\n in StrictMode (at **)' +
127-
'\n in ContainsStrictModeChild (at **)' +
128-
'\n' +
129-
'\nLearn more about using refs safely here:' +
130-
'\nhttps://fb.me/react-strict-mode-find-node',
128+
'\n in ContainsStrictModeChild (at **)',
131129
]);
132130
expect(match).toBe(child);
133131
});
@@ -152,14 +150,12 @@ describe('findDOMNode', () => {
152150
expect(() => (match = ReactDOM.findDOMNode(parent))).toWarnDev([
153151
'Warning: findDOMNode is deprecated in StrictMode. ' +
154152
'findDOMNode was passed an instance of IsInStrictMode which is inside StrictMode. ' +
155-
'Instead, add a ref directly to the element you want to reference.' +
156-
'\n' +
153+
'Instead, add a ref directly to the element you want to reference. ' +
154+
'Learn more about using refs safely here: ' +
155+
'https://fb.me/react-strict-mode-find-node' +
157156
'\n in div (at **)' +
158157
'\n in IsInStrictMode (at **)' +
159-
'\n in StrictMode (at **)' +
160-
'\n' +
161-
'\nLearn more about using refs safely here:' +
162-
'\nhttps://fb.me/react-strict-mode-find-node',
158+
'\n in StrictMode (at **)',
163159
]);
164160
expect(match).toBe(child);
165161
});

packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -885,14 +885,12 @@ describe('ReactFabric', () => {
885885
expect(() => (match = ReactFabric.findNodeHandle(parent))).toWarnDev([
886886
'Warning: findNodeHandle is deprecated in StrictMode. ' +
887887
'findNodeHandle was passed an instance of ContainsStrictModeChild which renders StrictMode children. ' +
888-
'Instead, add a ref directly to the element you want to reference.' +
889-
'\n' +
888+
'Instead, add a ref directly to the element you want to reference. ' +
889+
'Learn more about using refs safely here: ' +
890+
'https://fb.me/react-strict-mode-find-node' +
890891
'\n in RCTView (at **)' +
891892
'\n in StrictMode (at **)' +
892-
'\n in ContainsStrictModeChild (at **)' +
893-
'\n' +
894-
'\nLearn more about using refs safely here:' +
895-
'\nhttps://fb.me/react-strict-mode-find-node',
893+
'\n in ContainsStrictModeChild (at **)',
896894
]);
897895
expect(match).toBe(child._nativeTag);
898896
});
@@ -923,14 +921,12 @@ describe('ReactFabric', () => {
923921
expect(() => (match = ReactFabric.findNodeHandle(parent))).toWarnDev([
924922
'Warning: findNodeHandle is deprecated in StrictMode. ' +
925923
'findNodeHandle was passed an instance of IsInStrictMode which is inside StrictMode. ' +
926-
'Instead, add a ref directly to the element you want to reference.' +
927-
'\n' +
924+
'Instead, add a ref directly to the element you want to reference. ' +
925+
'Learn more about using refs safely here: ' +
926+
'https://fb.me/react-strict-mode-find-node' +
928927
'\n in RCTView (at **)' +
929928
'\n in IsInStrictMode (at **)' +
930-
'\n in StrictMode (at **)' +
931-
'\n' +
932-
'\nLearn more about using refs safely here:' +
933-
'\nhttps://fb.me/react-strict-mode-find-node',
929+
'\n in StrictMode (at **)',
934930
]);
935931
expect(match).toBe(child._nativeTag);
936932
});

packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,12 @@ describe('ReactNative', () => {
669669
expect(() => (match = ReactNative.findNodeHandle(parent))).toWarnDev([
670670
'Warning: findNodeHandle is deprecated in StrictMode. ' +
671671
'findNodeHandle was passed an instance of ContainsStrictModeChild which renders StrictMode children. ' +
672-
'Instead, add a ref directly to the element you want to reference.' +
673-
'\n' +
672+
'Instead, add a ref directly to the element you want to reference. ' +
673+
'Learn more about using refs safely here: ' +
674+
'https://fb.me/react-strict-mode-find-node' +
674675
'\n in RCTView (at **)' +
675676
'\n in StrictMode (at **)' +
676-
'\n in ContainsStrictModeChild (at **)' +
677-
'\n' +
678-
'\nLearn more about using refs safely here:' +
679-
'\nhttps://fb.me/react-strict-mode-find-node',
677+
'\n in ContainsStrictModeChild (at **)',
680678
]);
681679
expect(match).toBe(child._nativeTag);
682680
});
@@ -707,14 +705,12 @@ describe('ReactNative', () => {
707705
expect(() => (match = ReactNative.findNodeHandle(parent))).toWarnDev([
708706
'Warning: findNodeHandle is deprecated in StrictMode. ' +
709707
'findNodeHandle was passed an instance of IsInStrictMode which is inside StrictMode. ' +
710-
'Instead, add a ref directly to the element you want to reference.' +
711-
'\n' +
708+
'Instead, add a ref directly to the element you want to reference. ' +
709+
'Learn more about using refs safely here: ' +
710+
'https://fb.me/react-strict-mode-find-node' +
712711
'\n in RCTView (at **)' +
713712
'\n in IsInStrictMode (at **)' +
714-
'\n in StrictMode (at **)' +
715-
'\n' +
716-
'\nLearn more about using refs safely here:' +
717-
'\nhttps://fb.me/react-strict-mode-find-node',
713+
'\n in StrictMode (at **)',
718714
]);
719715
expect(match).toBe(child._nativeTag);
720716
});

packages/react-reconciler/src/ReactChildFiber.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ function coerceRef(
125125
false,
126126
'Component "%s" contains the string ref "%s". Support for string refs ' +
127127
'will be removed in a future major release. We recommend using ' +
128-
'useRef() or createRef() instead.' +
129-
'\n%s' +
130-
'\n\nLearn more about using refs safely here:' +
131-
'\nhttps://fb.me/react-strict-mode-string-ref',
128+
'useRef() or createRef() instead. ' +
129+
'Learn more about using refs safely here: ' +
130+
'https://fb.me/react-strict-mode-string-ref%s',
132131
componentName,
133132
mixedRef,
134133
getStackByFiberInDevAndProd(returnFiber),
@@ -138,10 +137,9 @@ function coerceRef(
138137
false,
139138
'A string ref, "%s", has been found within a strict mode tree. ' +
140139
'String refs are a source of potential bugs and should be avoided. ' +
141-
'We recommend using useRef() or createRef() instead.' +
142-
'\n%s' +
143-
'\n\nLearn more about using refs safely here:' +
144-
'\nhttps://fb.me/react-strict-mode-string-ref',
140+
'We recommend using useRef() or createRef() instead. ' +
141+
'Learn more about using refs safely here: ' +
142+
'https://fb.me/react-strict-mode-string-ref%s',
145143
mixedRef,
146144
getStackByFiberInDevAndProd(returnFiber),
147145
);

packages/react-reconciler/src/ReactFiberReconciler.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,9 @@ function findHostInstanceWithWarning(
261261
false,
262262
'%s is deprecated in StrictMode. ' +
263263
'%s was passed an instance of %s which is inside StrictMode. ' +
264-
'Instead, add a ref directly to the element you want to reference.' +
265-
'\n%s' +
266-
'\n\nLearn more about using refs safely here:' +
267-
'\nhttps://fb.me/react-strict-mode-find-node',
264+
'Instead, add a ref directly to the element you want to reference. ' +
265+
'Learn more about using refs safely here: ' +
266+
'https://fb.me/react-strict-mode-find-node%s',
268267
methodName,
269268
methodName,
270269
componentName,
@@ -275,10 +274,9 @@ function findHostInstanceWithWarning(
275274
false,
276275
'%s is deprecated in StrictMode. ' +
277276
'%s was passed an instance of %s which renders StrictMode children. ' +
278-
'Instead, add a ref directly to the element you want to reference.' +
279-
'\n%s' +
280-
'\n\nLearn more about using refs safely here:' +
281-
'\nhttps://fb.me/react-strict-mode-find-node',
277+
'Instead, add a ref directly to the element you want to reference. ' +
278+
'Learn more about using refs safely here: ' +
279+
'https://fb.me/react-strict-mode-find-node%s',
282280
methodName,
283281
methodName,
284282
componentName,

packages/react-reconciler/src/ReactStrictModeWarnings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ if (__DEV__) {
346346

347347
warningWithoutStack(
348348
false,
349-
'Legacy context API has been detected within a strict-mode tree: %s' +
349+
'Legacy context API has been detected within a strict-mode tree.' +
350350
'\n\nThe old API will be supported in all 16.x releases, but applications ' +
351351
'using it should migrate to the new version.' +
352352
'\n\nPlease update the following components: %s' +
353-
'\n\nLearn more about this warning here:' +
354-
'\nhttps://fb.me/react-legacy-context',
355-
strictRootComponentStack,
353+
'\n\nLearn more about this warning here: https://fb.me/react-legacy-context' +
354+
'%s',
356355
sortedNames,
356+
strictRootComponentStack,
357357
);
358358
},
359359
);

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ describe('ReactIncremental', () => {
19131913
'ShowBoth {"locale":"fr"}',
19141914
]),
19151915
).toWarnDev(
1916-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
1916+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
19171917
'The old API will be supported in all 16.x releases, but applications ' +
19181918
'using it should migrate to the new version.\n\n' +
19191919
'Please update the following components: Intl, ShowBoth, ShowLocale',
@@ -1970,7 +1970,7 @@ describe('ReactIncremental', () => {
19701970
'ShowBoth {"locale":"en"}',
19711971
]),
19721972
).toWarnDev(
1973-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
1973+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
19741974
'The old API will be supported in all 16.x releases, but applications ' +
19751975
'using it should migrate to the new version.\n\n' +
19761976
'Please update the following components: Router, ShowRoute',
@@ -2001,7 +2001,7 @@ describe('ReactIncremental', () => {
20012001

20022002
ReactNoop.render(<Recurse />);
20032003
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2004-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2004+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
20052005
'The old API will be supported in all 16.x releases, but applications ' +
20062006
'using it should migrate to the new version.\n\n' +
20072007
'Please update the following components: Recurse',
@@ -2046,7 +2046,7 @@ describe('ReactIncremental', () => {
20462046
"If you can't use a class try assigning the prototype on the function as a workaround. " +
20472047
'`Recurse.prototype = React.Component.prototype`. ' +
20482048
"Don't use an arrow function since it cannot be called with `new` by React.",
2049-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2049+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
20502050
'The old API will be supported in all 16.x releases, but applications ' +
20512051
'using it should migrate to the new version.\n\n' +
20522052
'Please update the following components: Recurse',
@@ -2114,7 +2114,7 @@ describe('ReactIncremental', () => {
21142114
'ShowLocale {"locale":"ru"}',
21152115
]),
21162116
).toWarnDev(
2117-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2117+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
21182118
'The old API will be supported in all 16.x releases, but applications ' +
21192119
'using it should migrate to the new version.\n\n' +
21202120
'Please update the following components: Intl, ShowLocale',
@@ -2195,7 +2195,7 @@ describe('ReactIncremental', () => {
21952195
</Intl>,
21962196
);
21972197
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2198-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2198+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
21992199
'The old API will be supported in all 16.x releases, but applications ' +
22002200
'using it should migrate to the new version.\n\n' +
22012201
'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
@@ -2289,7 +2289,7 @@ describe('ReactIncremental', () => {
22892289
</Stateful>,
22902290
);
22912291
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2292-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2292+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
22932293
'The old API will be supported in all 16.x releases, but applications ' +
22942294
'using it should migrate to the new version.\n\n' +
22952295
'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
@@ -2360,7 +2360,7 @@ describe('ReactIncremental', () => {
23602360
// Init
23612361
ReactNoop.render(<Root />);
23622362
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2363-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2363+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
23642364
'The old API will be supported in all 16.x releases, but applications ' +
23652365
'using it should migrate to the new version.\n\n' +
23662366
'Please update the following components: Child',
@@ -2412,7 +2412,7 @@ describe('ReactIncremental', () => {
24122412
// Init
24132413
ReactNoop.render(<Root />);
24142414
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2415-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2415+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
24162416
'The old API will be supported in all 16.x releases, but applications ' +
24172417
'using it should migrate to the new version.\n\n' +
24182418
'Please update the following components: ContextProvider',
@@ -2465,7 +2465,7 @@ describe('ReactIncremental', () => {
24652465
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
24662466
[
24672467
'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended',
2468-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2468+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
24692469
'The old API will be supported in all 16.x releases, but applications ' +
24702470
'using it should migrate to the new version.\n\n' +
24712471
'Please update the following components: MyComponent',
@@ -2614,7 +2614,7 @@ describe('ReactIncremental', () => {
26142614
);
26152615

26162616
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2617-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2617+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
26182618
'The old API will be supported in all 16.x releases, but applications ' +
26192619
'using it should migrate to the new version.\n\n' +
26202620
'Please update the following components: Child, TopContextProvider',
@@ -2678,7 +2678,7 @@ describe('ReactIncremental', () => {
26782678
);
26792679

26802680
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2681-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2681+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
26822682
'The old API will be supported in all 16.x releases, but applications ' +
26832683
'using it should migrate to the new version.\n\n' +
26842684
'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
@@ -2751,7 +2751,7 @@ describe('ReactIncremental', () => {
27512751
);
27522752

27532753
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2754-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2754+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
27552755
'The old API will be supported in all 16.x releases, but applications ' +
27562756
'using it should migrate to the new version.\n\n' +
27572757
'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
@@ -2834,7 +2834,7 @@ describe('ReactIncremental', () => {
28342834
);
28352835

28362836
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2837-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
2837+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
28382838
'The old API will be supported in all 16.x releases, but applications ' +
28392839
'using it should migrate to the new version.\n\n' +
28402840
'Please update the following components: Child, MiddleContextProvider, TopContextProvider',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ describe('ReactIncrementalErrorHandling', () => {
11181118
</Provider>,
11191119
);
11201120
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1121-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
1121+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
11221122
'The old API will be supported in all 16.x releases, but ' +
11231123
'applications using it should migrate to the new version.\n\n' +
11241124
'Please update the following components: Connector, Provider',
@@ -1621,7 +1621,7 @@ describe('ReactIncrementalErrorHandling', () => {
16211621
"If you can't use a class try assigning the prototype on the function as a workaround. " +
16221622
'`Provider.prototype = React.Component.prototype`. ' +
16231623
"Don't use an arrow function since it cannot be called with `new` by React.",
1624-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
1624+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
16251625
'The old API will be supported in all 16.x releases, but ' +
16261626
'applications using it should migrate to the new version.\n\n' +
16271627
'Please update the following components: Provider',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ describe('ReactNewContext', () => {
11961196
expect(() => {
11971197
expect(Scheduler).toFlushAndYield(['LegacyProvider', 'App', 'Child']);
11981198
}).toWarnDev(
1199-
'Legacy context API has been detected within a strict-mode tree: \n\n' +
1199+
'Legacy context API has been detected within a strict-mode tree.\n\n' +
12001200
'The old API will be supported in all 16.x releases, but applications ' +
12011201
'using it should migrate to the new version.\n\n' +
12021202
'Please update the following components: LegacyProvider',

0 commit comments

Comments
 (0)