Skip to content

Commit

Permalink
Make component stack last argument for deprecation warnings (#16384)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Aug 13, 2019
1 parent 1fd3906 commit e0a521b
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ describe('ReactDeprecationWarnings', () => {
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
'Warning: Component "Component" contains the string ref "refComponent". ' +
'Support for string refs will be removed in a future major release. ' +
'We recommend using useRef() or createRef() instead.' +
'\n\n' +
' in Component (at **)' +
'\n\n' +
'Learn more about using refs safely here:\n' +
'https://fb.me/react-strict-mode-string-ref',
'We recommend using useRef() or createRef() instead. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-string-ref' +
'\n in Component (at **)',
);
});
});
20 changes: 8 additions & 12 deletions packages/react-dom/src/__tests__/findDOMNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,12 @@ describe('findDOMNode', () => {
expect(() => (match = ReactDOM.findDOMNode(parent))).toWarnDev([
'Warning: findDOMNode is deprecated in StrictMode. ' +
'findDOMNode was passed an instance of ContainsStrictModeChild which renders StrictMode children. ' +
'Instead, add a ref directly to the element you want to reference.' +
'\n' +
'Instead, add a ref directly to the element you want to reference. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in div (at **)' +
'\n in StrictMode (at **)' +
'\n in ContainsStrictModeChild (at **)' +
'\n' +
'\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-find-node',
'\n in ContainsStrictModeChild (at **)',
]);
expect(match).toBe(child);
});
Expand All @@ -152,14 +150,12 @@ describe('findDOMNode', () => {
expect(() => (match = ReactDOM.findDOMNode(parent))).toWarnDev([
'Warning: findDOMNode is deprecated in StrictMode. ' +
'findDOMNode was passed an instance of IsInStrictMode which is inside StrictMode. ' +
'Instead, add a ref directly to the element you want to reference.' +
'\n' +
'Instead, add a ref directly to the element you want to reference. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in div (at **)' +
'\n in IsInStrictMode (at **)' +
'\n in StrictMode (at **)' +
'\n' +
'\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-find-node',
'\n in StrictMode (at **)',
]);
expect(match).toBe(child);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,12 @@ describe('ReactFabric', () => {
expect(() => (match = ReactFabric.findNodeHandle(parent))).toWarnDev([
'Warning: findNodeHandle is deprecated in StrictMode. ' +
'findNodeHandle was passed an instance of ContainsStrictModeChild which renders StrictMode children. ' +
'Instead, add a ref directly to the element you want to reference.' +
'\n' +
'Instead, add a ref directly to the element you want to reference. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in StrictMode (at **)' +
'\n in ContainsStrictModeChild (at **)' +
'\n' +
'\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-find-node',
'\n in ContainsStrictModeChild (at **)',
]);
expect(match).toBe(child._nativeTag);
});
Expand Down Expand Up @@ -923,14 +921,12 @@ describe('ReactFabric', () => {
expect(() => (match = ReactFabric.findNodeHandle(parent))).toWarnDev([
'Warning: findNodeHandle is deprecated in StrictMode. ' +
'findNodeHandle was passed an instance of IsInStrictMode which is inside StrictMode. ' +
'Instead, add a ref directly to the element you want to reference.' +
'\n' +
'Instead, add a ref directly to the element you want to reference. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in IsInStrictMode (at **)' +
'\n in StrictMode (at **)' +
'\n' +
'\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-find-node',
'\n in StrictMode (at **)',
]);
expect(match).toBe(child._nativeTag);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,12 @@ describe('ReactNative', () => {
expect(() => (match = ReactNative.findNodeHandle(parent))).toWarnDev([
'Warning: findNodeHandle is deprecated in StrictMode. ' +
'findNodeHandle was passed an instance of ContainsStrictModeChild which renders StrictMode children. ' +
'Instead, add a ref directly to the element you want to reference.' +
'\n' +
'Instead, add a ref directly to the element you want to reference. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in StrictMode (at **)' +
'\n in ContainsStrictModeChild (at **)' +
'\n' +
'\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-find-node',
'\n in ContainsStrictModeChild (at **)',
]);
expect(match).toBe(child._nativeTag);
});
Expand Down Expand Up @@ -707,14 +705,12 @@ describe('ReactNative', () => {
expect(() => (match = ReactNative.findNodeHandle(parent))).toWarnDev([
'Warning: findNodeHandle is deprecated in StrictMode. ' +
'findNodeHandle was passed an instance of IsInStrictMode which is inside StrictMode. ' +
'Instead, add a ref directly to the element you want to reference.' +
'\n' +
'Instead, add a ref directly to the element you want to reference. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in IsInStrictMode (at **)' +
'\n in StrictMode (at **)' +
'\n' +
'\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-find-node',
'\n in StrictMode (at **)',
]);
expect(match).toBe(child._nativeTag);
});
Expand Down
14 changes: 6 additions & 8 deletions packages/react-reconciler/src/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ function coerceRef(
false,
'Component "%s" contains the string ref "%s". Support for string refs ' +
'will be removed in a future major release. We recommend using ' +
'useRef() or createRef() instead.' +
'\n%s' +
'\n\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-string-ref',
'useRef() or createRef() instead. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-string-ref%s',
componentName,
mixedRef,
getStackByFiberInDevAndProd(returnFiber),
Expand All @@ -138,10 +137,9 @@ function coerceRef(
false,
'A string ref, "%s", has been found within a strict mode tree. ' +
'String refs are a source of potential bugs and should be avoided. ' +
'We recommend using useRef() or createRef() instead.' +
'\n%s' +
'\n\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-string-ref',
'We recommend using useRef() or createRef() instead. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-string-ref%s',
mixedRef,
getStackByFiberInDevAndProd(returnFiber),
);
Expand Down
14 changes: 6 additions & 8 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,9 @@ function findHostInstanceWithWarning(
false,
'%s is deprecated in StrictMode. ' +
'%s was passed an instance of %s which is inside StrictMode. ' +
'Instead, add a ref directly to the element you want to reference.' +
'\n%s' +
'\n\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-find-node',
'Instead, add a ref directly to the element you want to reference. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node%s',
methodName,
methodName,
componentName,
Expand All @@ -275,10 +274,9 @@ function findHostInstanceWithWarning(
false,
'%s is deprecated in StrictMode. ' +
'%s was passed an instance of %s which renders StrictMode children. ' +
'Instead, add a ref directly to the element you want to reference.' +
'\n%s' +
'\n\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-find-node',
'Instead, add a ref directly to the element you want to reference. ' +
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node%s',
methodName,
methodName,
componentName,
Expand Down
8 changes: 4 additions & 4 deletions packages/react-reconciler/src/ReactStrictModeWarnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ if (__DEV__) {

warningWithoutStack(
false,
'Legacy context API has been detected within a strict-mode tree: %s' +
'Legacy context API has been detected within a strict-mode tree.' +
'\n\nThe old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.' +
'\n\nPlease update the following components: %s' +
'\n\nLearn more about this warning here:' +
'\nhttps://fb.me/react-legacy-context',
strictRootComponentStack,
'\n\nLearn more about this warning here: https://fb.me/react-legacy-context' +
'%s',
sortedNames,
strictRootComponentStack,
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ describe('ReactIncremental', () => {
'ShowBoth {"locale":"fr"}',
]),
).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: Intl, ShowBoth, ShowLocale',
Expand Down Expand Up @@ -1970,7 +1970,7 @@ describe('ReactIncremental', () => {
'ShowBoth {"locale":"en"}',
]),
).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: Router, ShowRoute',
Expand Down Expand Up @@ -2001,7 +2001,7 @@ describe('ReactIncremental', () => {

ReactNoop.render(<Recurse />);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: Recurse',
Expand Down Expand Up @@ -2046,7 +2046,7 @@ describe('ReactIncremental', () => {
"If you can't use a class try assigning the prototype on the function as a workaround. " +
'`Recurse.prototype = React.Component.prototype`. ' +
"Don't use an arrow function since it cannot be called with `new` by React.",
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: Recurse',
Expand Down Expand Up @@ -2114,7 +2114,7 @@ describe('ReactIncremental', () => {
'ShowLocale {"locale":"ru"}',
]),
).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: Intl, ShowLocale',
Expand Down Expand Up @@ -2195,7 +2195,7 @@ describe('ReactIncremental', () => {
</Intl>,
);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
Expand Down Expand Up @@ -2289,7 +2289,7 @@ describe('ReactIncremental', () => {
</Stateful>,
);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
Expand Down Expand Up @@ -2360,7 +2360,7 @@ describe('ReactIncremental', () => {
// Init
ReactNoop.render(<Root />);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: Child',
Expand Down Expand Up @@ -2412,7 +2412,7 @@ describe('ReactIncremental', () => {
// Init
ReactNoop.render(<Root />);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: ContextProvider',
Expand Down Expand Up @@ -2465,7 +2465,7 @@ describe('ReactIncremental', () => {
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
[
'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended',
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: MyComponent',
Expand Down Expand Up @@ -2614,7 +2614,7 @@ describe('ReactIncremental', () => {
);

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

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

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

expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ describe('ReactIncrementalErrorHandling', () => {
</Provider>,
);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but ' +
'applications using it should migrate to the new version.\n\n' +
'Please update the following components: Connector, Provider',
Expand Down Expand Up @@ -1621,7 +1621,7 @@ describe('ReactIncrementalErrorHandling', () => {
"If you can't use a class try assigning the prototype on the function as a workaround. " +
'`Provider.prototype = React.Component.prototype`. ' +
"Don't use an arrow function since it cannot be called with `new` by React.",
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but ' +
'applications using it should migrate to the new version.\n\n' +
'Please update the following components: Provider',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ describe('ReactNewContext', () => {
expect(() => {
expect(Scheduler).toFlushAndYield(['LegacyProvider', 'App', 'Child']);
}).toWarnDev(
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Legacy context API has been detected within a strict-mode tree.\n\n' +
'The old API will be supported in all 16.x releases, but applications ' +
'using it should migrate to the new version.\n\n' +
'Please update the following components: LegacyProvider',
Expand Down
Loading

0 comments on commit e0a521b

Please sign in to comment.