Make component stack last argument for deprecation warnings (#16384)
Dan Abramov committed
Aug 13, 2019 at 23:25 UTC
e0a521b02ad54b840ee66637f956b65db4dbe51c
11 files changed
+75
-93
packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.internal.js
+4
-6
@@ -64,12 +64,10 @@ describe('ReactDeprecationWarnings', () => {
64
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
65
'Warning: Component "Component" contains the string ref "refComponent". ' +
66
'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 **)',
71
);
72
});
73
});
packages/react-dom/src/__tests__/findDOMNode-test.js
+8
-12
@@ -120,14 +120,12 @@ describe('findDOMNode', () => {
120
expect(() => (match = ReactDOM.findDOMNode(parent))).toWarnDev([
121
'Warning: findDOMNode is deprecated in StrictMode. ' +
122
'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' +
126
'\n in div (at **)' +
127
'\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 **)',
129
]);
130
expect(match).toBe(child);
131
});
@@ -152,14 +150,12 @@ describe('findDOMNode', () => {
150
expect(() => (match = ReactDOM.findDOMNode(parent))).toWarnDev([
151
'Warning: findDOMNode is deprecated in StrictMode. ' +
152
'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' +
156
'\n in div (at **)' +
157
'\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 **)',
159
]);
160
expect(match).toBe(child);
161
});
packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js
+8
-12
@@ -885,14 +885,12 @@ describe('ReactFabric', () => {
885
expect(() => (match = ReactFabric.findNodeHandle(parent))).toWarnDev([
886
'Warning: findNodeHandle is deprecated in StrictMode. ' +
887
'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' +
891
'\n in RCTView (at **)' +
892
'\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 **)',
894
]);
895
expect(match).toBe(child._nativeTag);
896
});
@@ -923,14 +921,12 @@ describe('ReactFabric', () => {
921
expect(() => (match = ReactFabric.findNodeHandle(parent))).toWarnDev([
922
'Warning: findNodeHandle is deprecated in StrictMode. ' +
923
'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' +
927
'\n in RCTView (at **)' +
928
'\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 **)',
930
]);
931
expect(match).toBe(child._nativeTag);
932
});
packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js
+8
-12
@@ -669,14 +669,12 @@ describe('ReactNative', () => {
669
expect(() => (match = ReactNative.findNodeHandle(parent))).toWarnDev([
670
'Warning: findNodeHandle is deprecated in StrictMode. ' +
671
'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' +
675
'\n in RCTView (at **)' +
676
'\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 **)',
678
]);
679
expect(match).toBe(child._nativeTag);
680
});
@@ -707,14 +705,12 @@ describe('ReactNative', () => {
705
expect(() => (match = ReactNative.findNodeHandle(parent))).toWarnDev([
706
'Warning: findNodeHandle is deprecated in StrictMode. ' +
707
'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' +
711
'\n in RCTView (at **)' +
712
'\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 **)',
714
]);
715
expect(match).toBe(child._nativeTag);
716
});
packages/react-reconciler/src/ReactChildFiber.js
+6
-8
@@ -125,10 +125,9 @@ function coerceRef(
125
false,
126
'Component "%s" contains the string ref "%s". Support for string refs ' +
127
'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',
131
componentName,
132
mixedRef,
133
getStackByFiberInDevAndProd(returnFiber),
@@ -138,10 +137,9 @@ function coerceRef(
137
false,
138
'A string ref, "%s", has been found within a strict mode tree. ' +
139
'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',
143
mixedRef,
144
getStackByFiberInDevAndProd(returnFiber),
145
);
packages/react-reconciler/src/ReactFiberReconciler.js
+6
-8
@@ -261,10 +261,9 @@ function findHostInstanceWithWarning(
261
false,
262
'%s is deprecated in StrictMode. ' +
263
'%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',
267
methodName,
268
methodName,
269
componentName,
@@ -275,10 +274,9 @@ function findHostInstanceWithWarning(
274
false,
275
'%s is deprecated in StrictMode. ' +
276
'%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',
280
methodName,
281
methodName,
282
componentName,
packages/react-reconciler/src/ReactStrictModeWarnings.js
+4
-4
@@ -346,14 +346,14 @@ if (__DEV__) {
346
347
warningWithoutStack(
348
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.' +
350
'\n\nThe old API will be supported in all 16.x releases, but applications ' +
351
'using it should migrate to the new version.' +
352
'\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',
355
sortedNames,
356
+ strictRootComponentStack,
357
);
358
},
359
);
packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js
+14
-14
@@ -1913,7 +1913,7 @@ describe('ReactIncremental', () => {
1913
'ShowBoth {"locale":"fr"}',
1914
]),
1915
).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' +
1917
'The old API will be supported in all 16.x releases, but applications ' +
1918
'using it should migrate to the new version.\n\n' +
1919
'Please update the following components: Intl, ShowBoth, ShowLocale',
@@ -1970,7 +1970,7 @@ describe('ReactIncremental', () => {
1970
'ShowBoth {"locale":"en"}',
1971
]),
1972
).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' +
1974
'The old API will be supported in all 16.x releases, but applications ' +
1975
'using it should migrate to the new version.\n\n' +
1976
'Please update the following components: Router, ShowRoute',
@@ -2001,7 +2001,7 @@ describe('ReactIncremental', () => {
2001
2002
ReactNoop.render(<Recurse />);
2003
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' +
2005
'The old API will be supported in all 16.x releases, but applications ' +
2006
'using it should migrate to the new version.\n\n' +
2007
'Please update the following components: Recurse',
@@ -2046,7 +2046,7 @@ describe('ReactIncremental', () => {
2046
"If you can't use a class try assigning the prototype on the function as a workaround. " +
2047
'`Recurse.prototype = React.Component.prototype`. ' +
2048
"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' +
2050
'The old API will be supported in all 16.x releases, but applications ' +
2051
'using it should migrate to the new version.\n\n' +
2052
'Please update the following components: Recurse',
@@ -2114,7 +2114,7 @@ describe('ReactIncremental', () => {
2114
'ShowLocale {"locale":"ru"}',
2115
]),
2116
).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' +
2118
'The old API will be supported in all 16.x releases, but applications ' +
2119
'using it should migrate to the new version.\n\n' +
2120
'Please update the following components: Intl, ShowLocale',
@@ -2195,7 +2195,7 @@ describe('ReactIncremental', () => {
2195
</Intl>,
2196
);
2197
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' +
2199
'The old API will be supported in all 16.x releases, but applications ' +
2200
'using it should migrate to the new version.\n\n' +
2201
'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
@@ -2289,7 +2289,7 @@ describe('ReactIncremental', () => {
2289
</Stateful>,
2290
);
2291
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' +
2293
'The old API will be supported in all 16.x releases, but applications ' +
2294
'using it should migrate to the new version.\n\n' +
2295
'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
@@ -2360,7 +2360,7 @@ describe('ReactIncremental', () => {
2360
// Init
2361
ReactNoop.render(<Root />);
2362
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' +
2364
'The old API will be supported in all 16.x releases, but applications ' +
2365
'using it should migrate to the new version.\n\n' +
2366
'Please update the following components: Child',
@@ -2412,7 +2412,7 @@ describe('ReactIncremental', () => {
2412
// Init
2413
ReactNoop.render(<Root />);
2414
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' +
2416
'The old API will be supported in all 16.x releases, but applications ' +
2417
'using it should migrate to the new version.\n\n' +
2418
'Please update the following components: ContextProvider',
@@ -2465,7 +2465,7 @@ describe('ReactIncremental', () => {
2465
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2466
[
2467
'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' +
2469
'The old API will be supported in all 16.x releases, but applications ' +
2470
'using it should migrate to the new version.\n\n' +
2471
'Please update the following components: MyComponent',
@@ -2614,7 +2614,7 @@ describe('ReactIncremental', () => {
2614
);
2615
2616
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' +
2618
'The old API will be supported in all 16.x releases, but applications ' +
2619
'using it should migrate to the new version.\n\n' +
2620
'Please update the following components: Child, TopContextProvider',
@@ -2678,7 +2678,7 @@ describe('ReactIncremental', () => {
2678
);
2679
2680
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' +
2682
'The old API will be supported in all 16.x releases, but applications ' +
2683
'using it should migrate to the new version.\n\n' +
2684
'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
@@ -2751,7 +2751,7 @@ describe('ReactIncremental', () => {
2751
);
2752
2753
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' +
2755
'The old API will be supported in all 16.x releases, but applications ' +
2756
'using it should migrate to the new version.\n\n' +
2757
'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
@@ -2834,7 +2834,7 @@ describe('ReactIncremental', () => {
2834
);
2835
2836
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' +
2838
'The old API will be supported in all 16.x releases, but applications ' +
2839
'using it should migrate to the new version.\n\n' +
2840
'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js
+2
-2
@@ -1118,7 +1118,7 @@ describe('ReactIncrementalErrorHandling', () => {
1118
</Provider>,
1119
);
1120
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' +
1122
'The old API will be supported in all 16.x releases, but ' +
1123
'applications using it should migrate to the new version.\n\n' +
1124
'Please update the following components: Connector, Provider',
@@ -1621,7 +1621,7 @@ describe('ReactIncrementalErrorHandling', () => {
1621
"If you can't use a class try assigning the prototype on the function as a workaround. " +
1622
'`Provider.prototype = React.Component.prototype`. ' +
1623
"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' +
1625
'The old API will be supported in all 16.x releases, but ' +
1626
'applications using it should migrate to the new version.\n\n' +
1627
'Please update the following components: Provider',
packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js
+1
-1
@@ -1196,7 +1196,7 @@ describe('ReactNewContext', () => {
1196
expect(() => {
1197
expect(Scheduler).toFlushAndYield(['LegacyProvider', 'App', 'Child']);
1198
}).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' +
1200
'The old API will be supported in all 16.x releases, but applications ' +
1201
'using it should migrate to the new version.\n\n' +
1202
'Please update the following components: LegacyProvider',
packages/react/src/__tests__/ReactStrictMode-test.internal.js
+14
-14
@@ -693,11 +693,11 @@ Please update the following components: Parent`,
693
}).toWarnDev(
694
'Warning: A string ref, "somestring", has been found within a strict mode tree. ' +
695
'String refs are a source of potential bugs and should be avoided. ' +
696
- 'We recommend using useRef() or createRef() instead.\n\n' +
696
+ 'We recommend using useRef() or createRef() instead. ' +
697
+ 'Learn more about using refs safely here: ' +
698
+ 'https://fb.me/react-strict-mode-string-ref\n' +
699
' in StrictMode (at **)\n' +
698
- ' in OuterComponent (at **)\n\n' +
699
- 'Learn more about using refs safely here:\n' +
700
- 'https://fb.me/react-strict-mode-string-ref',
700
+ ' in OuterComponent (at **)',
701
);
702
703
// Dedup
@@ -735,12 +735,12 @@ Please update the following components: Parent`,
735
}).toWarnDev(
736
'Warning: A string ref, "somestring", has been found within a strict mode tree. ' +
737
'String refs are a source of potential bugs and should be avoided. ' +
738
- 'We recommend using useRef() or createRef() instead.\n\n' +
738
+ 'We recommend using useRef() or createRef() instead. ' +
739
+ 'Learn more about using refs safely here: ' +
740
+ 'https://fb.me/react-strict-mode-string-ref\n' +
741
' in InnerComponent (at **)\n' +
742
' in StrictMode (at **)\n' +
741
- ' in OuterComponent (at **)\n\n' +
742
- 'Learn more about using refs safely here:\n' +
743
- 'https://fb.me/react-strict-mode-string-ref',
743
+ ' in OuterComponent (at **)',
744
);
745
746
// Dedup
@@ -813,16 +813,16 @@ Please update the following components: Parent`,
813
expect(() => {
814
rendered = ReactTestRenderer.create(<Root />);
815
}).toWarnDev(
816
- 'Warning: Legacy context API has been detected within a strict-mode tree: ' +
817
- '\n in StrictMode (at **)' +
818
- '\n in div (at **)' +
819
- '\n in Root (at **)' +
816
+ 'Warning: Legacy context API has been detected within a strict-mode tree.' +
817
'\n\nThe old API will be supported in all 16.x releases, but applications ' +
818
'using it should migrate to the new version.' +
819
'\n\nPlease update the following components: ' +
820
'FunctionalLegacyContextConsumer, LegacyContextConsumer, LegacyContextProvider' +
824
- '\n\nLearn more about this warning here:' +
825
- '\nhttps://fb.me/react-legacy-context',
821
+ '\n\nLearn more about this warning here: ' +
822
+ 'https://fb.me/react-legacy-context' +
823
+ '\n in StrictMode (at **)' +
824
+ '\n in div (at **)' +
825
+ '\n in Root (at **)',
826
);
827
828
// Dedupe