diff --git a/packages/create-subscription/src/createSubscription.js b/packages/create-subscription/src/createSubscription.js index f0130dd868e0..0403762a059b 100644 --- a/packages/create-subscription/src/createSubscription.js +++ b/packages/create-subscription/src/createSubscription.js @@ -9,7 +9,7 @@ import React from 'react'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; type Unsubscribe = () => void; @@ -38,12 +38,10 @@ export function createSubscription( if (__DEV__) { if (typeof getCurrentValue !== 'function') { - warningWithoutStack( - 'Subscription must specify a getCurrentValue function', - ); + warning('Subscription must specify a getCurrentValue function'); } if (typeof subscribe !== 'function') { - warningWithoutStack('Subscription must specify a subscribe function'); + warning('Subscription must specify a subscribe function'); } } diff --git a/packages/legacy-events/EventPluginUtils.js b/packages/legacy-events/EventPluginUtils.js index 22f1d7c357b2..ac78119b8d0b 100644 --- a/packages/legacy-events/EventPluginUtils.js +++ b/packages/legacy-events/EventPluginUtils.js @@ -7,7 +7,7 @@ import {invokeGuardedCallbackAndCatchFirstError} from 'shared/ReactErrorUtils'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; export let getFiberCurrentPropsFromNode = null; export let getInstanceFromNode = null; @@ -23,7 +23,7 @@ export function setComponentTree( getNodeFromInstance = getNodeFromInstanceImpl; if (__DEV__) { if (!getNodeFromInstance || !getInstanceFromNode) { - warningWithoutStack( + warning( 'EventPluginUtils.setComponentTree(...): Injected ' + 'module is missing getNodeFromInstance or getInstanceFromNode.', ); @@ -52,7 +52,7 @@ if (__DEV__) { : 0; if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) { - warningWithoutStack('EventPluginUtils: Invalid `event`.'); + warning('EventPluginUtils: Invalid `event`.'); } }; } diff --git a/packages/legacy-events/EventPropagators.js b/packages/legacy-events/EventPropagators.js index 022b968307d8..02069849bb22 100644 --- a/packages/legacy-events/EventPropagators.js +++ b/packages/legacy-events/EventPropagators.js @@ -10,7 +10,7 @@ import { traverseTwoPhase, traverseEnterLeave, } from 'shared/ReactTreeTraversal'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {getListener} from './EventPluginHub'; import accumulateInto from './accumulateInto'; @@ -47,7 +47,7 @@ function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) { function accumulateDirectionalDispatches(inst, phase, event) { if (__DEV__) { if (!inst) { - warningWithoutStack('Dispatching inst must not be null'); + warning('Dispatching inst must not be null'); } } const listener = listenerAtPhase(inst, event, phase); diff --git a/packages/legacy-events/ResponderTouchHistoryStore.js b/packages/legacy-events/ResponderTouchHistoryStore.js index 0b02db652aba..a892aeb324f9 100644 --- a/packages/legacy-events/ResponderTouchHistoryStore.js +++ b/packages/legacy-events/ResponderTouchHistoryStore.js @@ -8,7 +8,7 @@ */ import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {isStartish, isMoveish, isEndish} from './ResponderTopLevelEventTypes'; @@ -96,7 +96,7 @@ function getTouchIdentifier({identifier}: Touch): number { invariant(identifier != null, 'Touch object is missing identifier.'); if (__DEV__) { if (identifier > MAX_TOUCH_BANK) { - warningWithoutStack( + warning( 'Touch identifier %s is greater than maximum supported %s which causes ' + 'performance issues backfilling array locations for all of the indices.', identifier, @@ -202,7 +202,7 @@ const ResponderTouchHistoryStore = { if (__DEV__) { const activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch]; if (activeRecord == null || !activeRecord.touchActive) { - warningWithoutStack('Cannot find single active touch.'); + warning('Cannot find single active touch.'); } } } diff --git a/packages/legacy-events/SyntheticEvent.js b/packages/legacy-events/SyntheticEvent.js index 393f4cfda576..840da2e109c1 100644 --- a/packages/legacy-events/SyntheticEvent.js +++ b/packages/legacy-events/SyntheticEvent.js @@ -8,7 +8,7 @@ /* eslint valid-typeof: 0 */ import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; const EVENT_POOL_SIZE = 10; @@ -284,7 +284,7 @@ function getPooledWarningPropertyDefinition(propName, getVal) { function warn(action, result) { if (__DEV__) { - warningWithoutStack( + warning( "This synthetic event is reused for performance reasons. If you're seeing this, " + "you're %s `%s` on a released/nullified synthetic event. %s. " + 'If you must keep the original synthetic event around, use event.persist(). ' + diff --git a/packages/react-cache/src/ReactCache.js b/packages/react-cache/src/ReactCache.js index b0960cf94b86..242bc7d32a7b 100644 --- a/packages/react-cache/src/ReactCache.js +++ b/packages/react-cache/src/ReactCache.js @@ -8,7 +8,7 @@ */ import React from 'react'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {createLRU} from './LRU'; @@ -71,7 +71,7 @@ function identityHashFn(input) { input !== undefined && input !== null ) { - warningWithoutStack( + warning( 'Invalid key type. Expected a string, number, symbol, or boolean, ' + 'but instead received: %s' + '\n\nTo use non-primitive values as keys, you must pass a hash ' + diff --git a/packages/react-cache/src/__tests__/ReactCache-test.internal.js b/packages/react-cache/src/__tests__/ReactCache-test.internal.js index f7be9de09306..726c1d840b45 100644 --- a/packages/react-cache/src/__tests__/ReactCache-test.internal.js +++ b/packages/react-cache/src/__tests__/ReactCache-test.internal.js @@ -172,15 +172,12 @@ describe('ReactCache', () => { if (__DEV__) { expect(() => { expect(Scheduler).toFlushAndYield(['App', 'Loading...']); - }).toWarnDev( - [ - 'Invalid key type. Expected a string, number, symbol, or ' + - 'boolean, but instead received: Hi,100\n\n' + - 'To use non-primitive values as keys, you must pass a hash ' + - 'function as the second argument to createResource().', - ], - {withoutStack: true}, - ); + }).toWarnDev([ + 'Invalid key type. Expected a string, number, symbol, or ' + + 'boolean, but instead received: Hi,100\n\n' + + 'To use non-primitive values as keys, you must pass a hash ' + + 'function as the second argument to createResource().', + ]); } else { expect(Scheduler).toFlushAndYield(['App', 'Loading...']); } diff --git a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js index 1984224875b2..8b0b0899ac53 100644 --- a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js +++ b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js @@ -215,7 +215,6 @@ describe('ReactComponentLifeCycle', () => { 'StatefulComponent: It is not recommended to assign props directly to state ' + "because updates to props won't be reflected in state. " + 'In most cases, it is better to use props directly.', - {withoutStack: true}, ); }); @@ -240,7 +239,6 @@ describe('ReactComponentLifeCycle', () => { 'This is a no-op, but it might indicate a bug in your application. ' + 'Instead, assign to `this.state` directly or define a `state = {};` ' + 'class property with the desired state in the StatefulComponent component.', - {withoutStack: true}, ); // Check deduplication; (no extra warnings should be logged). @@ -271,9 +269,7 @@ describe('ReactComponentLifeCycle', () => { expect(() => { const instance = ReactTestUtils.renderIntoDocument(element); expect(instance._isMounted()).toBeTruthy(); - }).toWarnDev('Component is accessing isMounted inside its render()', { - withoutStack: true, - }); + }).toWarnDev('Component is accessing isMounted inside its render()'); }); it('should correctly determine if a null component is mounted', () => { @@ -300,9 +296,7 @@ describe('ReactComponentLifeCycle', () => { expect(() => { const instance = ReactTestUtils.renderIntoDocument(element); expect(instance._isMounted()).toBeTruthy(); - }).toWarnDev('Component is accessing isMounted inside its render()', { - withoutStack: true, - }); + }).toWarnDev('Component is accessing isMounted inside its render()'); }); it('isMounted should return false when unmounted', () => { @@ -340,9 +334,7 @@ describe('ReactComponentLifeCycle', () => { expect(() => { ReactTestUtils.renderIntoDocument(); - }).toWarnDev('Component is accessing findDOMNode inside its render()', { - withoutStack: true, - }); + }).toWarnDev('Component is accessing findDOMNode inside its render()'); }); it('should carry through each of the phases of setup', () => { @@ -408,7 +400,6 @@ describe('ReactComponentLifeCycle', () => { instance = ReactDOM.render(, container); }).toWarnDev( 'LifeCycleComponent is accessing isMounted inside its render() function', - {withoutStack: true}, ); // getInitialState @@ -705,7 +696,6 @@ describe('ReactComponentLifeCycle', () => { expect(() => { expect(() => ReactDOM.render(, container)).toWarnDev( 'Unsafe legacy lifecycles will not be called for components using new component APIs.', - {withoutStack: true}, ); }).toLowPriorityWarnDev( [ @@ -744,7 +734,6 @@ describe('ReactComponentLifeCycle', () => { ReactDOM.render(, container), ).toWarnDev( 'Unsafe legacy lifecycles will not be called for components using new component APIs.', - {withoutStack: true}, ); }).toLowPriorityWarnDev( [ @@ -780,7 +769,6 @@ describe('ReactComponentLifeCycle', () => { const container = document.createElement('div'); expect(() => ReactDOM.render(, container)).toWarnDev( 'Unsafe legacy lifecycles will not be called for components using new component APIs.', - {withoutStack: true}, ); ReactDOM.render(, container); }); @@ -812,7 +800,6 @@ describe('ReactComponentLifeCycle', () => { ' componentWillUpdate\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); }).toLowPriorityWarnDev( [ @@ -839,7 +826,6 @@ describe('ReactComponentLifeCycle', () => { ' UNSAFE_componentWillMount\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); class WillMountAndUpdate extends React.Component { @@ -864,7 +850,6 @@ describe('ReactComponentLifeCycle', () => { ' UNSAFE_componentWillUpdate\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); }).toLowPriorityWarnDev(['componentWillMount has been renamed'], { withoutStack: true, @@ -888,7 +873,6 @@ describe('ReactComponentLifeCycle', () => { ' componentWillReceiveProps\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); }).toLowPriorityWarnDev(['componentWillReceiveProps has been renamed'], { withoutStack: true, @@ -921,7 +905,6 @@ describe('ReactComponentLifeCycle', () => { ' componentWillUpdate\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); }).toLowPriorityWarnDev( [ @@ -947,7 +930,6 @@ describe('ReactComponentLifeCycle', () => { ' UNSAFE_componentWillMount\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); class WillMountAndUpdate extends React.Component { @@ -971,7 +953,6 @@ describe('ReactComponentLifeCycle', () => { ' UNSAFE_componentWillUpdate\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); }).toLowPriorityWarnDev(['componentWillMount has been renamed'], { withoutStack: true, @@ -994,7 +975,6 @@ describe('ReactComponentLifeCycle', () => { ' componentWillReceiveProps\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); }).toLowPriorityWarnDev(['componentWillReceiveProps has been renamed'], { withoutStack: true, @@ -1045,7 +1025,6 @@ describe('ReactComponentLifeCycle', () => { "If you can't use a class try assigning the prototype on the function as a workaround. " + '`Parent.prototype = React.Component.prototype`. ' + "Don't use an arrow function since it cannot be called with `new` by React.", - {withoutStack: true}, ); ReactDOM.render( c && log.push('ref')} />, div); @@ -1074,7 +1053,6 @@ describe('ReactComponentLifeCycle', () => { expect(() => ReactDOM.render(, div)).toWarnDev( 'MyComponent.getDerivedStateFromProps(): A valid state object (or null) must ' + 'be returned. You have returned undefined.', - {withoutStack: true}, ); // De-duped @@ -1097,7 +1075,6 @@ describe('ReactComponentLifeCycle', () => { 'undefined. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `MyComponent`. ' + 'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.', - {withoutStack: true}, ); // De-duped @@ -1366,7 +1343,6 @@ describe('ReactComponentLifeCycle', () => { expect(() => ReactDOM.render(, div)).toWarnDev( 'MyComponent.getSnapshotBeforeUpdate(): A snapshot value (or null) must ' + 'be returned. You have returned undefined.', - {withoutStack: true}, ); // De-duped @@ -1387,7 +1363,6 @@ describe('ReactComponentLifeCycle', () => { expect(() => ReactDOM.render(, div)).toWarnDev( 'MyComponent: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', - {withoutStack: true}, ); // De-duped diff --git a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js index 7766944ec6e7..cede35d72a55 100644 --- a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js @@ -124,7 +124,6 @@ describe('ReactCompositeComponent', () => { "If you can't use a class try assigning the prototype on the function as a workaround. " + '`Child.prototype = React.Component.prototype`. ' + "Don't use an arrow function since it cannot be called with `new` by React.", - {withoutStack: true}, ); expect(el.textContent).toBe('test'); @@ -287,7 +286,6 @@ describe('ReactCompositeComponent', () => { 'This is a no-op, but it might indicate a bug in your application. ' + 'Instead, assign to `this.state` directly or define a `state = {};` ' + 'class property with the desired state in the MyComponent component.', - {withoutStack: true}, ); // No additional warning should be recorded @@ -312,7 +310,6 @@ describe('ReactCompositeComponent', () => { 'This is a no-op, but it might indicate a bug in your application. ' + 'Instead, assign to `this.state` directly or define a `state = {};` ' + 'class property with the desired state in the MyComponent component.', - {withoutStack: true}, ); // No additional warning should be recorded @@ -440,7 +437,6 @@ describe('ReactCompositeComponent', () => { 'Warning: The component appears to have a render method, ' + "but doesn't extend React.Component. This is likely to cause errors. " + 'Change ClassWithRenderNotExtended to extend React.Component instead.', - {withoutStack: true}, ); // Test deduplication @@ -475,7 +471,6 @@ describe('ReactCompositeComponent', () => { }).toWarnDev( 'Cannot update during an existing state transition (such as within ' + '`render`). Render methods should be a pure function of props and state.', - {withoutStack: true}, ); // The setState call is queued and then executed as a second pass. This @@ -523,7 +518,6 @@ describe('ReactCompositeComponent', () => { instance = ReactDOM.render(, container); }).toWarnDev( 'Warning: setState(...): Cannot call setState() inside getChildContext()', - {withoutStack: true}, ); expect(renderPasses).toBe(2); @@ -600,7 +594,6 @@ describe('ReactCompositeComponent', () => { expect(() => instance.setState({bogus: true})).toWarnDev( 'Warning: Component.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', - {withoutStack: true}, ); }); @@ -617,7 +610,6 @@ describe('ReactCompositeComponent', () => { 'Warning: Component has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', - {withoutStack: true}, ); }); @@ -636,7 +628,6 @@ describe('ReactCompositeComponent', () => { 'If you meant to update the state in response to changing props, ' + 'use componentWillReceiveProps(). If you meant to fetch data or ' + 'run side-effects or mutations after React has updated the UI, use componentDidUpdate().', - {withoutStack: true}, ); }); @@ -655,7 +646,6 @@ describe('ReactCompositeComponent', () => { expect(() => ReactTestUtils.renderIntoDocument()).toWarnDev( 'Warning: Setting defaultProps as an instance property on Component is not supported ' + 'and will be ignored. Instead, define defaultProps as a static property on Component.', - {withoutStack: true}, ); }); @@ -1146,7 +1136,6 @@ describe('ReactCompositeComponent', () => { 'triggering nested component updates from render is not allowed. If ' + 'necessary, trigger nested updates in componentDidUpdate.\n\nCheck the ' + 'render method of Outer.', - {withoutStack: true}, ); }); @@ -1438,7 +1427,6 @@ describe('ReactCompositeComponent', () => { expect(() => ReactDOM.render(, container)).toWarnDev( 'Foo(...): When calling super() in `Foo`, make sure to pass ' + "up the same props that your component's constructor was passed.", - {withoutStack: true}, ); }); @@ -1737,17 +1725,14 @@ describe('ReactCompositeComponent', () => { expect(() => { ReactTestUtils.renderIntoDocument(); }).toThrow(); - }).toWarnDev( - [ - // Expect two errors because invokeGuardedCallback will dispatch an error event, - // Causing the warning to be logged again. - 'Warning: RenderTextInvalidConstructor(...): No `render` method found on the returned component instance: ' + - 'did you accidentally return an object from the constructor?', - 'Warning: RenderTextInvalidConstructor(...): No `render` method found on the returned component instance: ' + - 'did you accidentally return an object from the constructor?', - ], - {withoutStack: true}, - ); + }).toWarnDev([ + // Expect two errors because invokeGuardedCallback will dispatch an error event, + // Causing the warning to be logged again. + 'Warning: RenderTextInvalidConstructor(...): No `render` method found on the returned component instance: ' + + 'did you accidentally return an object from the constructor?', + 'Warning: RenderTextInvalidConstructor(...): No `render` method found on the returned component instance: ' + + 'did you accidentally return an object from the constructor?', + ]); }); it('should warn about reassigning this.props while rendering', () => { @@ -1776,17 +1761,14 @@ describe('ReactCompositeComponent', () => { expect(() => { ReactTestUtils.renderIntoDocument(); }).toThrow(); - }).toWarnDev( - [ - // Expect two errors because invokeGuardedCallback will dispatch an error event, - // Causing the warning to be logged again. - 'Warning: RenderTestUndefinedRender(...): No `render` method found on the returned ' + - 'component instance: you may have forgotten to define `render`.', - 'Warning: RenderTestUndefinedRender(...): No `render` method found on the returned ' + - 'component instance: you may have forgotten to define `render`.', - ], - {withoutStack: true}, - ); + }).toWarnDev([ + // Expect two errors because invokeGuardedCallback will dispatch an error event, + // Causing the warning to be logged again. + 'Warning: RenderTestUndefinedRender(...): No `render` method found on the returned ' + + 'component instance: you may have forgotten to define `render`.', + 'Warning: RenderTestUndefinedRender(...): No `render` method found on the returned ' + + 'component instance: you may have forgotten to define `render`.', + ]); }); // Regression test for accidental breaking change diff --git a/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js b/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js index 3c28f4833768..4bee754661d0 100644 --- a/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js +++ b/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js @@ -410,7 +410,6 @@ describe('ReactCompositeComponent-state', () => { 'Warning: Test.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's constructor). " + 'Use setState instead.', - {withoutStack: true}, ); expect(ops).toEqual([ @@ -452,7 +451,6 @@ describe('ReactCompositeComponent-state', () => { 'Warning: Test.componentWillMount(): Assigning directly to ' + "this.state is deprecated (except inside a component's constructor). " + 'Use setState instead.', - {withoutStack: true}, ); expect(ops).toEqual([ @@ -480,7 +478,6 @@ describe('ReactCompositeComponent-state', () => { "If you can't use a class try assigning the prototype on the function as a workaround. " + '`Child.prototype = React.Component.prototype`. ' + "Don't use an arrow function since it cannot be called with `new` by React.", - {withoutStack: true}, ); expect(el.textContent).toBe('count:123'); diff --git a/packages/react-dom/src/__tests__/ReactDOMRoot-test.js b/packages/react-dom/src/__tests__/ReactDOMRoot-test.js index 6f4efc14f9bd..bade522f652c 100644 --- a/packages/react-dom/src/__tests__/ReactDOMRoot-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMRoot-test.js @@ -81,9 +81,7 @@ describe('ReactDOMRoot', () => { , ); - expect(() => Scheduler.unstable_flushAll()).toWarnDev('Extra attributes', { - withoutStack: true, - }); + expect(() => Scheduler.unstable_flushAll()).toWarnDev('Extra attributes'); }); it('does not clear existing children', async () => { diff --git a/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js b/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js index 4aed0e0246a6..2cd1dbe32531 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js @@ -183,7 +183,6 @@ describe('ReactDOMServerLifecycles', () => { expect(() => ReactDOMServer.renderToString()).toWarnDev( 'Component.getDerivedStateFromProps(): A valid state object (or null) must ' + 'be returned. You have returned undefined.', - {withoutStack: true}, ); // De-duped @@ -205,7 +204,6 @@ describe('ReactDOMServerLifecycles', () => { 'undefined. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `Component`. ' + 'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.', - {withoutStack: true}, ); // De-duped @@ -229,9 +227,7 @@ describe('ReactDOMServerLifecycles', () => { expect(() => ReactDOMServer.renderToString(), - ).toLowPriorityWarnDev('componentWillMount has been renamed', { - withoutStack: true, - }); + ).toLowPriorityWarnDev('componentWillMount has been renamed'); expect(log).toEqual(['componentWillMount', 'UNSAFE_componentWillMount']); }); @@ -266,7 +262,6 @@ describe('ReactDOMServerLifecycles', () => { 'usually means you called setState() outside componentWillMount() on ' + 'the server. This is a no-op.\n\n' + 'Please check the code for the Outer component.', - {withoutStack: true}, ); }); @@ -286,9 +281,7 @@ describe('ReactDOMServerLifecycles', () => { expect(() => ReactDOMServer.renderToString(), - ).toLowPriorityWarnDev('componentWillMount has been renamed', { - withoutStack: true, - }); + ).toLowPriorityWarnDev('componentWillMount has been renamed'); }); it('should warn about deprecated lifecycle hooks', () => { @@ -301,9 +294,7 @@ describe('ReactDOMServerLifecycles', () => { expect(() => ReactDOMServer.renderToString(), - ).toLowPriorityWarnDev('componentWillMount has been renamed', { - withoutStack: true, - }); + ).toLowPriorityWarnDev('componentWillMount has been renamed'); // De-duped ReactDOMServer.renderToString(); diff --git a/packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.internal.js b/packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.internal.js index ce89d56e23fb..cf24ee3d8286 100644 --- a/packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactDeprecationWarnings-test.internal.js @@ -44,7 +44,6 @@ describe('ReactDeprecationWarnings', () => { 'Warning: FunctionalComponent: Support for defaultProps ' + 'will be removed from function components in a future major ' + 'release. Use JavaScript default parameters instead.', - {withoutStack: true}, ); }); diff --git a/packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js b/packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js index 3dea42709a9f..dce7a696979f 100644 --- a/packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js @@ -815,7 +815,6 @@ describe('ReactErrorBoundaries', () => { "If you can't use a class try assigning the prototype on the function as a workaround. " + '`BrokenComponentWillMountWithContext.prototype = React.Component.prototype`. ' + "Don't use an arrow function since it cannot be called with `new` by React.", - {withoutStack: true}, ); expect(container.firstChild.textContent).toBe('Caught an error: Hello.'); @@ -2244,7 +2243,6 @@ describe('ReactErrorBoundaries', () => { }).toWarnDev( 'InvalidErrorBoundary: Error boundaries should implement getDerivedStateFromError(). ' + 'In that method, return a state update to display an error message or fallback UI.', - {withoutStack: true}, ); expect(container.textContent).toBe(''); }); diff --git a/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js b/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js index 685a1cffb97e..db36eca037ff 100644 --- a/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js @@ -111,7 +111,6 @@ describe('ReactFunctionComponent', () => { ).toWarnDev( 'FunctionComponentWithChildContext: Function ' + 'components do not support getDerivedStateFromProps.', - {withoutStack: true}, ); }); @@ -134,7 +133,6 @@ describe('ReactFunctionComponent', () => { ).toWarnDev( 'FunctionComponentWithChildContext(...): childContextTypes cannot ' + 'be defined on a function component.', - {withoutStack: true}, ); }); diff --git a/packages/react-dom/src/__tests__/ReactLegacyContextDisabled-test.internal.js b/packages/react-dom/src/__tests__/ReactLegacyContextDisabled-test.internal.js index f788748aa909..337eb4a2646e 100644 --- a/packages/react-dom/src/__tests__/ReactLegacyContextDisabled-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactLegacyContextDisabled-test.internal.js @@ -90,17 +90,14 @@ describe('ReactLegacyContextDisabled', () => { , container, ); - }).toWarnDev( - [ - 'LegacyProvider uses the legacy childContextTypes API which is no longer supported. ' + - 'Use React.createContext() instead.', - 'LegacyClsConsumer uses the legacy contextTypes API which is no longer supported. ' + - 'Use React.createContext() with static contextType instead.', - 'LegacyFnConsumer uses the legacy contextTypes API which is no longer supported. ' + - 'Use React.createContext() with React.useContext() instead.', - ], - {withoutStack: true}, - ); + }).toWarnDev([ + 'LegacyProvider uses the legacy childContextTypes API which is no longer supported. ' + + 'Use React.createContext() instead.', + 'LegacyClsConsumer uses the legacy contextTypes API which is no longer supported. ' + + 'Use React.createContext() with static contextType instead.', + 'LegacyFnConsumer uses the legacy contextTypes API which is no longer supported. ' + + 'Use React.createContext() with React.useContext() instead.', + ]); expect(container.textContent).toBe('{}undefinedundefined'); expect(lifecycleContextLog).toEqual([]); diff --git a/packages/react-dom/src/__tests__/ReactLegacyErrorBoundaries-test.internal.js b/packages/react-dom/src/__tests__/ReactLegacyErrorBoundaries-test.internal.js index 30a6d0c30ba6..85c024431efe 100644 --- a/packages/react-dom/src/__tests__/ReactLegacyErrorBoundaries-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactLegacyErrorBoundaries-test.internal.js @@ -847,7 +847,6 @@ describe('ReactLegacyErrorBoundaries', () => { "If you can't use a class try assigning the prototype on the function as a workaround. " + '`BrokenComponentWillMountWithContext.prototype = React.Component.prototype`. ' + "Don't use an arrow function since it cannot be called with `new` by React.", - {withoutStack: true}, ); expect(container.firstChild.textContent).toBe('Caught an error: Hello.'); }); @@ -2117,7 +2116,6 @@ describe('ReactLegacyErrorBoundaries', () => { ); }).toWarnDev( 'ErrorBoundary: Error boundaries should implement getDerivedStateFromError()', - {withoutStack: true}, ); expect(container.firstChild.textContent).toBe('Sibling'); expect(log).toEqual([ diff --git a/packages/react-dom/src/__tests__/ReactMount-test.js b/packages/react-dom/src/__tests__/ReactMount-test.js index e99db093d5ac..2511ad0e6a9e 100644 --- a/packages/react-dom/src/__tests__/ReactMount-test.js +++ b/packages/react-dom/src/__tests__/ReactMount-test.js @@ -137,7 +137,6 @@ describe('ReactMount', () => { expect(() => ReactDOM.hydrate(
, container)).toWarnDev( 'Did not expect server HTML to contain the text node " " in .', - {withoutStack: true}, ); }); @@ -175,7 +174,6 @@ describe('ReactMount', () => { ).toWarnDev( 'Server: "This markup contains an nbsp entity:   server text" ' + 'Client: "This markup contains an nbsp entity:   client text"', - {withoutStack: true}, ); }); diff --git a/packages/react-dom/src/__tests__/ReactRenderDocument-test.js b/packages/react-dom/src/__tests__/ReactRenderDocument-test.js index 32903540eba5..161911152060 100644 --- a/packages/react-dom/src/__tests__/ReactRenderDocument-test.js +++ b/packages/react-dom/src/__tests__/ReactRenderDocument-test.js @@ -203,9 +203,7 @@ describe('rendering React components at document', () => { 'with ReactDOM.hydrate() if you want React to attach to the server HTML.', {withoutStack: true}, ); - }).toWarnDev('Warning: Text content did not match.', { - withoutStack: true, - }); + }).toWarnDev('Warning: Text content did not match.'); }); it('should throw on full document render w/ no markup', () => { @@ -373,7 +371,6 @@ describe('rendering React components at document', () => { container.textContent = 'potato'; expect(() => ReactDOM.hydrate(
parsnip
, container)).toWarnDev( 'Expected server HTML to contain a matching
in
.', - {withoutStack: true}, ); expect(container.textContent).toBe('parsnip'); }); @@ -399,9 +396,7 @@ describe('rendering React components at document', () => { expect(() => ReactDOM.hydrate(, testDocument), - ).toWarnDev('Warning: Text content did not match.', { - withoutStack: true, - }); + ).toWarnDev('Warning: Text content did not match.'); expect(testDocument.body.innerHTML).toBe('Hello world'); }); @@ -424,9 +419,7 @@ describe('rendering React components at document', () => { // getTestDocument() has an extra that we didn't render. expect(() => ReactDOM.hydrate(, testDocument), - ).toWarnDev('Did not expect server HTML to contain a in .', { - withoutStack: true, - }); + ).toWarnDev('Did not expect server HTML to contain a in .'); expect(testDocument.body.innerHTML).toBe('Hello world'); }); diff --git a/packages/react-dom/src/__tests__/ReactServerRendering-test.js b/packages/react-dom/src/__tests__/ReactServerRendering-test.js index 54edfacb846d..5a80060abe8a 100644 --- a/packages/react-dom/src/__tests__/ReactServerRendering-test.js +++ b/packages/react-dom/src/__tests__/ReactServerRendering-test.js @@ -856,7 +856,6 @@ describe('ReactDOMServer', () => { 'Warning: The component appears to have a render method, ' + "but doesn't extend React.Component. This is likely to cause errors. " + 'Change ClassWithRenderNotExtended to extend React.Component instead.', - {withoutStack: true}, ); // Test deduplication @@ -1022,7 +1021,6 @@ describe('ReactDOMServer', () => { 'Warning: ComponentA defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext(). ' + 'Did you accidentally pass the Context.Consumer instead?', - {withoutStack: true}, ); // Warnings should be deduped by component type @@ -1034,7 +1032,6 @@ describe('ReactDOMServer', () => { 'Warning: ComponentB defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext(). ' + 'Did you accidentally pass the Context.Provider instead?', - {withoutStack: true}, ); }); @@ -1072,7 +1069,6 @@ describe('ReactDOMServer', () => { 'This can be caused by a typo or by mixing up named and default imports. ' + 'This can also happen due to a circular dependency, ' + 'so try moving the createContext() call to a separate file.', - {withoutStack: true}, ); }); @@ -1096,7 +1092,6 @@ describe('ReactDOMServer', () => { 'Foo defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext(). ' + 'However, it is set to an object with keys {x, y}.', - {withoutStack: true}, ); }); @@ -1116,7 +1111,6 @@ describe('ReactDOMServer', () => { 'Foo defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext(). ' + 'However, it is set to a string.', - {withoutStack: true}, ); }); }); diff --git a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js index 64ed76d90b5b..81969a89d54b 100644 --- a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js +++ b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js @@ -104,9 +104,7 @@ describe('ReactDOMServerHydration', () => { element.innerHTML = lastMarkup; expect(() => { instance = ReactDOM.render(, element); - }).toWarnDev('Text content did not match. Server: "x" Client: "y"', { - withoutStack: true, - }); + }).toWarnDev('Text content did not match. Server: "x" Client: "y"'); expect(mountCount).toEqual(4); expect(element.innerHTML.length > 0).toBe(true); expect(element.innerHTML).not.toEqual(lastMarkup); @@ -189,9 +187,7 @@ describe('ReactDOMServerHydration', () => { element.innerHTML = lastMarkup; expect(() => { instance = ReactDOM.hydrate(, element); - }).toWarnDev('Text content did not match. Server: "x" Client: "y"', { - withoutStack: true, - }); + }).toWarnDev('Text content did not match. Server: "x" Client: "y"'); expect(mountCount).toEqual(4); expect(element.innerHTML.length > 0).toBe(true); expect(element.innerHTML).not.toEqual(lastMarkup); @@ -254,7 +250,6 @@ describe('ReactDOMServerHydration', () => { ReactDOM.hydrate(, element), ).toWarnDev( 'Warning: Text content did not match. Server: "server" Client: "client"', - {withoutStack: true}, ); expect(element.firstChild.focus).not.toHaveBeenCalled(); @@ -279,7 +274,6 @@ describe('ReactDOMServerHydration', () => { 'Warning: Prop `style` did not match. Server: ' + '"text-decoration:none;color:black;height:10px" Client: ' + '"text-decoration:none;color:white;height:10px"', - {withoutStack: true}, ); }); @@ -327,7 +321,6 @@ describe('ReactDOMServerHydration', () => { 'Warning: Prop `style` did not match. Server: ' + '"text-decoration: none; color: black; height: 10px;" Client: ' + '"text-decoration:none;color:black;height:10px"', - {withoutStack: true}, ); }); @@ -362,14 +355,12 @@ describe('ReactDOMServerHydration', () => { const element = document.createElement('div'); expect(() => { element.innerHTML = ReactDOMServer.renderToString(markup); - }).toLowPriorityWarnDev(['componentWillMount has been renamed'], { - withoutStack: true, - }); + }).toLowPriorityWarnDev('componentWillMount has been renamed'); expect(element.textContent).toBe('Hi'); expect(() => { ReactDOM.hydrate(markup, element); - }).toLowPriorityWarnDev(['componentWillMount has been renamed'], { + }).toLowPriorityWarnDev('componentWillMount has been renamed', { withoutStack: true, }); expect(element.textContent).toBe('Hi'); diff --git a/packages/react-dom/src/__tests__/ReactUpdates-test.js b/packages/react-dom/src/__tests__/ReactUpdates-test.js index 461581a3755b..3ccd799519de 100644 --- a/packages/react-dom/src/__tests__/ReactUpdates-test.js +++ b/packages/react-dom/src/__tests__/ReactUpdates-test.js @@ -1231,7 +1231,6 @@ describe('ReactUpdates', () => { const container = document.createElement('div'); expect(() => ReactDOM.render(, container)).toWarnDev( 'Cannot update during an existing state transition', - {withoutStack: true}, ); expect(ops).toEqual(['base: 0, memoized: 0', 'base: 1, memoized: 1']); }); diff --git a/packages/react-dom/src/__tests__/refs-test.js b/packages/react-dom/src/__tests__/refs-test.js index 7cc764bdefda..c1ab653229e0 100644 --- a/packages/react-dom/src/__tests__/refs-test.js +++ b/packages/react-dom/src/__tests__/refs-test.js @@ -175,7 +175,6 @@ describe('factory components', () => { "If you can't use a class try assigning the prototype on the function as a workaround. " + '`Comp.prototype = React.Component.prototype`. ' + "Don't use an arrow function since it cannot be called with `new` by React.", - {withoutStack: true}, ); expect(inst.refs.elemRef.tagName).toBe('DIV'); }); diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index b2ae182b4512..759d87e3bc7d 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -53,8 +53,8 @@ import { } from 'legacy-events/EventPropagators'; import ReactVersion from 'shared/ReactVersion'; import invariant from 'shared/invariant'; -import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import lowPriorityWarning from 'shared/lowPriorityWarning'; +import warning from 'shared/warning'; import {exposeConcurrentModeAPIs} from 'shared/ReactFeatureFlags'; import { @@ -92,7 +92,7 @@ if (__DEV__) { typeof Set.prototype.clear !== 'function' || typeof Set.prototype.forEach !== 'function' ) { - warningWithoutStack( + warning( 'React depends on Map and Set built-in types. Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills', ); @@ -144,7 +144,7 @@ const ReactDOM: Object = { if (__DEV__) { if (!didWarnAboutUnstableCreatePortal) { didWarnAboutUnstableCreatePortal = true; - lowPriorityWarningWithoutStack( + lowPriorityWarning( 'The ReactDOM.unstable_createPortal() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactDOM.createPortal() instead. It has the exact same API, ' + diff --git a/packages/react-dom/src/client/ReactDOMComponent.js b/packages/react-dom/src/client/ReactDOMComponent.js index c348cb9a7c6c..8f3448162bba 100644 --- a/packages/react-dom/src/client/ReactDOMComponent.js +++ b/packages/react-dom/src/client/ReactDOMComponent.js @@ -10,9 +10,8 @@ // TODO: direct imports like some-package/src/* are bad. Fix me. import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber'; import {registrationNameModules} from 'legacy-events/EventPluginRegistry'; -import warning from 'shared/warning'; import {canUseDOM} from 'shared/ExecutionEnvironment'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import endsWith from 'shared/endsWith'; import {setListenToResponderEventTypes} from '../events/DOMEventResponderSystem'; @@ -184,7 +183,7 @@ if (__DEV__) { return; } didWarnInvalidHydration = true; - warningWithoutStack( + warning( 'Text content did not match. Server: "%s" Client: "%s"', normalizedServerText, normalizedClientText, @@ -209,7 +208,7 @@ if (__DEV__) { return; } didWarnInvalidHydration = true; - warningWithoutStack( + warning( 'Prop `%s` did not match. Server: %s Client: %s', propName, JSON.stringify(normalizedServerValue), @@ -226,7 +225,7 @@ if (__DEV__) { attributeNames.forEach(function(name) { names.push(name); }); - warningWithoutStack('Extra attributes from the server: %s', names); + warning('Extra attributes from the server: %s', names); }; warnForInvalidEventListener = function(registrationName, listener) { @@ -1211,7 +1210,7 @@ export function warnForDeletedHydratableElement( return; } didWarnInvalidHydration = true; - warningWithoutStack( + warning( 'Did not expect server HTML to contain a <%s> in <%s>.', child.nodeName.toLowerCase(), parentNode.nodeName.toLowerCase(), @@ -1228,7 +1227,7 @@ export function warnForDeletedHydratableText( return; } didWarnInvalidHydration = true; - warningWithoutStack( + warning( 'Did not expect server HTML to contain the text node "%s" in <%s>.', child.nodeValue, parentNode.nodeName.toLowerCase(), @@ -1246,7 +1245,7 @@ export function warnForInsertedHydratedElement( return; } didWarnInvalidHydration = true; - warningWithoutStack( + warning( 'Expected server HTML to contain a matching <%s> in <%s>.', tag, parentNode.nodeName.toLowerCase(), @@ -1270,7 +1269,7 @@ export function warnForInsertedHydratedText( return; } didWarnInvalidHydration = true; - warningWithoutStack( + warning( 'Expected server HTML to contain a matching text node for "%s" in <%s>.', text, parentNode.nodeName.toLowerCase(), diff --git a/packages/react-dom/src/client/ReactDOMLegacy.js b/packages/react-dom/src/client/ReactDOMLegacy.js index afae54941475..27d78788d48d 100644 --- a/packages/react-dom/src/client/ReactDOMLegacy.js +++ b/packages/react-dom/src/client/ReactDOMLegacy.js @@ -38,8 +38,8 @@ import { } from 'react-reconciler/inline.dom'; import getComponentName from 'shared/getComponentName'; import invariant from 'shared/invariant'; -import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import lowPriorityWarning from 'shared/lowPriorityWarning'; +import warning from 'shared/warning'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import {has as hasInstance} from 'shared/ReactInstanceMap'; @@ -56,7 +56,7 @@ if (__DEV__) { ); if (hostInstance) { if (hostInstance.parentNode !== container) { - warningWithoutStack( + warning( 'render(...): It looks like the React-rendered content of this ' + 'container was removed without using React. This is not ' + 'supported and will cause errors. Instead, call ' + @@ -71,7 +71,7 @@ if (__DEV__) { const hasNonRootReactChild = !!(rootEl && getInstanceFromNode(rootEl)); if (hasNonRootReactChild && !isRootRenderedBySomeReact) { - warningWithoutStack( + warning( 'render(...): Replacing React-rendered children with a new root ' + 'component. If you intended to update the children of this node, ' + 'you should instead have the existing children update their state ' + @@ -84,7 +84,7 @@ if (__DEV__) { ((container: any): Element).tagName && ((container: any): Element).tagName.toUpperCase() === 'BODY' ) { - warningWithoutStack( + warning( 'render(): Rendering components directly into document.body is ' + 'discouraged, since its children are often manipulated by third-party ' + 'scripts and browser extensions. This may lead to subtle ' + @@ -134,7 +134,7 @@ function legacyCreateRootFromDOMContainer( (rootSibling: any).hasAttribute(ROOT_ATTRIBUTE_NAME) ) { warned = true; - warningWithoutStack( + warning( 'render(): Target node has markup rendered by React, but there ' + 'are unrelated nodes as well. This is most commonly caused by ' + 'white-space inserted around server-rendered markup.', @@ -147,7 +147,7 @@ function legacyCreateRootFromDOMContainer( if (__DEV__) { if (shouldHydrate && !forceHydrate && !warnedAboutHydrateAPI) { warnedAboutHydrateAPI = true; - lowPriorityWarningWithoutStack( + lowPriorityWarning( 'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' + 'will stop working in React v17. Replace the ReactDOM.render() call ' + 'with ReactDOM.hydrate() if you want React to attach to the server HTML.', @@ -222,7 +222,7 @@ export function findDOMNode( if (owner !== null && owner.stateNode !== null) { const warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender; if (!warnedAboutRefsInRender) { - warningWithoutStack( + warning( '%s is accessing findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + @@ -260,7 +260,7 @@ export function hydrate( isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined; if (isModernRoot) { - warningWithoutStack( + warning( 'You are calling ReactDOM.hydrate() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. ' + 'Did you mean to call createRoot(container, {hydrate: true}).render(element)?', @@ -291,7 +291,7 @@ export function render( isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined; if (isModernRoot) { - warningWithoutStack( + warning( 'You are calling ReactDOM.render() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. ' + 'Did you mean to call root.render(element)?', @@ -341,7 +341,7 @@ export function unmountComponentAtNode(container: DOMContainer) { isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined; if (isModernRoot) { - warningWithoutStack( + warning( 'You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. Did you mean to call root.unmount()?', ); @@ -353,7 +353,7 @@ export function unmountComponentAtNode(container: DOMContainer) { const rootEl = getReactRootElementInContainer(container); const renderedByDifferentReact = rootEl && !getInstanceFromNode(rootEl); if (renderedByDifferentReact) { - warningWithoutStack( + warning( "unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by another copy of React.', ); @@ -382,7 +382,7 @@ export function unmountComponentAtNode(container: DOMContainer) { !!container.parentNode._reactRootContainer; if (hasNonRootReactChild) { - warningWithoutStack( + warning( "unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by React and is not a top-level container. %s', isContainerReactRoot diff --git a/packages/react-dom/src/client/ReactDOMRoot.js b/packages/react-dom/src/client/ReactDOMRoot.js index 77e618393563..c9fbde50c7f5 100644 --- a/packages/react-dom/src/client/ReactDOMRoot.js +++ b/packages/react-dom/src/client/ReactDOMRoot.js @@ -44,7 +44,7 @@ import { import {createContainer, updateContainer} from 'react-reconciler/inline.dom'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {BlockingRoot, ConcurrentRoot, LegacyRoot} from 'shared/ReactRootTags'; function ReactDOMRoot(container: DOMContainer, options: void | RootOptions) { @@ -157,7 +157,7 @@ export function warnOnInvalidCallback( ): void { if (__DEV__) { if (callback !== null && typeof callback !== 'function') { - warningWithoutStack( + warning( '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, @@ -171,12 +171,12 @@ function warnIfReactDOMContainerInDEV(container) { if (__DEV__) { if (isContainerMarkedAsRoot(container)) { if (container._reactRootContainer) { - warningWithoutStack( + warning( 'You are calling ReactDOM.createRoot() on a container that was previously ' + 'passed to ReactDOM.render(). This is not supported.', ); } else { - warningWithoutStack( + warning( 'You are calling ReactDOM.createRoot() on a container that ' + 'has already been passed to createRoot() before. Instead, call ' + 'root.render() on the existing root instead if you want to update it.', diff --git a/packages/react-dom/src/client/validateDOMNesting.js b/packages/react-dom/src/client/validateDOMNesting.js index 8e3df7fd435b..2520ccbe6d6a 100644 --- a/packages/react-dom/src/client/validateDOMNesting.js +++ b/packages/react-dom/src/client/validateDOMNesting.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; // TODO: direct imports like some-package/src/* are bad. Fix me. import {getCurrentFiberStackInDev} from 'react-reconciler/src/ReactCurrentFiber'; @@ -412,7 +412,7 @@ if (__DEV__) { if (childText != null) { if (childTag != null) { - warningWithoutStack( + warning( 'validateDOMNesting: when childText is passed, childTag should be null', ); } @@ -462,21 +462,19 @@ if (__DEV__) { ' Add a , or to your code to match the DOM tree generated by ' + 'the browser.'; } - warningWithoutStack( - 'validateDOMNesting(...): %s cannot appear as a child of <%s>.%s%s%s', + warning( + 'validateDOMNesting(...): %s cannot appear as a child of <%s>.%s%s', tagDisplayName, ancestorTag, whitespaceInfo, info, - addendum, ); } else { - warningWithoutStack( + warning( 'validateDOMNesting(...): %s cannot appear as a descendant of ' + - '<%s>.%s', + '<%s>.', tagDisplayName, ancestorTag, - addendum, ); } }; diff --git a/packages/react-dom/src/events/SimpleEventPlugin.js b/packages/react-dom/src/events/SimpleEventPlugin.js index 0a57bfe074c9..43c970ccf22d 100644 --- a/packages/react-dom/src/events/SimpleEventPlugin.js +++ b/packages/react-dom/src/events/SimpleEventPlugin.js @@ -29,7 +29,7 @@ import {accumulateTwoPhaseDispatches} from 'legacy-events/EventPropagators'; import SyntheticEvent from 'legacy-events/SyntheticEvent'; import * as DOMTopLevelEventTypes from './DOMTopLevelEventTypes'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import SyntheticAnimationEvent from './SyntheticAnimationEvent'; import SyntheticClipboardEvent from './SyntheticClipboardEvent'; @@ -342,7 +342,7 @@ const SimpleEventPlugin: PluginModule & { default: if (__DEV__) { if (knownHTMLTopLevelTypes.indexOf(topLevelType) === -1) { - warningWithoutStack( + warning( 'SimpleEventPlugin: Unhandled event type, `%s`. This warning ' + 'is likely caused by a bug in React. Please file an issue.', topLevelType, diff --git a/packages/react-dom/src/server/ReactPartialRenderer.js b/packages/react-dom/src/server/ReactPartialRenderer.js index 4f4a27b3b9d1..070fd25eddc7 100644 --- a/packages/react-dom/src/server/ReactPartialRenderer.js +++ b/packages/react-dom/src/server/ReactPartialRenderer.js @@ -15,9 +15,8 @@ import type {ReactProvider, ReactContext} from 'shared/ReactTypes'; import React from 'react'; import invariant from 'shared/invariant'; import getComponentName from 'shared/getComponentName'; -import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; +import lowPriorityWarning from 'shared/lowPriorityWarning'; import warning from 'shared/warning'; -import warningWithoutStack from 'shared/warningWithoutStack'; import describeComponentFrame from 'shared/describeComponentFrame'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import { @@ -270,7 +269,7 @@ function warnNoop( return; } - warningWithoutStack( + warning( '%s(...): Can only update a mounting component. ' + 'This usually means you called %s() outside componentWillMount() on the server. ' + 'This is a no-op.\n\nPlease check the code for the %s component.', @@ -473,7 +472,7 @@ function resolve( if (inst.state === null || inst.state === undefined) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutUninitializedState[componentName]) { - warningWithoutStack( + warning( '`%s` uses `getDerivedStateFromProps` but its initial state is ' + '%s. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `%s`. ' + @@ -497,7 +496,7 @@ function resolve( if (partialState === undefined) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutUndefinedDerivedState[componentName]) { - warningWithoutStack( + warning( '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName, @@ -520,7 +519,7 @@ function resolve( const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutBadClass[componentName]) { - warningWithoutStack( + warning( "The <%s /> component appears to have a render method, but doesn't extend React.Component. " + 'This is likely to cause errors. Change %s to extend React.Component instead.', componentName, @@ -544,7 +543,7 @@ function resolve( if (__DEV__) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutModulePatternComponent[componentName]) { - warningWithoutStack( + warning( 'The <%s /> component appears to be a function component that returns a class instance. ' + 'Change %s to a class that extends React.Component instead. ' + "If you can't use a class try assigning the prototype on the function as a workaround. " + @@ -580,7 +579,7 @@ function resolve( const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutDeprecatedWillMount[componentName]) { - lowPriorityWarningWithoutStack( + lowPriorityWarning( // keep this warning in sync with ReactStrictModeWarning.js 'componentWillMount has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + @@ -656,7 +655,7 @@ function resolve( if (__DEV__) { let childContextTypes = Component.childContextTypes; if (childContextTypes !== undefined) { - warningWithoutStack( + warning( '%s uses the legacy childContextTypes API which is no longer supported. ' + 'Use React.createContext() instead.', getComponentName(Component) || 'Unknown', @@ -678,7 +677,7 @@ function resolve( } } else { if (__DEV__) { - warningWithoutStack( + warning( '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', getComponentName(Component) || 'Unknown', @@ -797,7 +796,7 @@ class ReactDOMServerRenderer { const index = this.contextIndex; if (__DEV__) { if (index < 0 || provider !== (this.contextProviderStack: any)[index]) { - warningWithoutStack('Unexpected pop.'); + warning('Unexpected pop.'); } } diff --git a/packages/react-dom/src/server/ReactPartialRendererContext.js b/packages/react-dom/src/server/ReactPartialRendererContext.js index ecf22ba3e674..7fa750c4aed6 100644 --- a/packages/react-dom/src/server/ReactPartialRendererContext.js +++ b/packages/react-dom/src/server/ReactPartialRendererContext.js @@ -14,7 +14,7 @@ import {disableLegacyContext} from 'shared/ReactFeatureFlags'; import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import getComponentName from 'shared/getComponentName'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import checkPropTypes from 'prop-types/checkPropTypes'; let ReactDebugCurrentFrame; @@ -112,7 +112,7 @@ export function processContext( Object.keys(contextType).join(', ') + '}.'; } - warningWithoutStack( + warning( '%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(type) || 'Component', @@ -128,7 +128,7 @@ export function processContext( if (disableLegacyContext) { if (__DEV__) { if (type.contextTypes) { - warningWithoutStack( + warning( '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with static contextType instead.', getComponentName(type) || 'Unknown', @@ -149,7 +149,7 @@ export function processContext( if (disableLegacyContext) { if (__DEV__) { if (type.contextTypes) { - warningWithoutStack( + warning( '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with React.useContext() instead.', getComponentName(type) || 'Unknown', diff --git a/packages/react-dom/src/test-utils/ReactTestUtils.js b/packages/react-dom/src/test-utils/ReactTestUtils.js index 6ded9eb1979e..55b203447312 100644 --- a/packages/react-dom/src/test-utils/ReactTestUtils.js +++ b/packages/react-dom/src/test-utils/ReactTestUtils.js @@ -17,7 +17,7 @@ import { } from 'shared/ReactWorkTags'; import SyntheticEvent from 'legacy-events/SyntheticEvent'; import invariant from 'shared/invariant'; -import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; +import lowPriorityWarning from 'shared/lowPriorityWarning'; import {ELEMENT_NODE} from '../shared/HTMLNodeType'; import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes'; import {PLUGIN_EVENT_SYSTEM} from 'legacy-events/EventSystemFlags'; @@ -362,7 +362,7 @@ const ReactTestUtils = { if (__DEV__) { if (!hasWarnedAboutDeprecatedMockComponent) { hasWarnedAboutDeprecatedMockComponent = true; - lowPriorityWarningWithoutStack( + lowPriorityWarning( 'ReactTestUtils.mockComponent() is deprecated. ' + 'Use shallow rendering or jest.mock() instead.\n\n' + 'See https://fb.me/test-utils-mock-component for more information.', diff --git a/packages/react-dom/src/test-utils/ReactTestUtilsAct.js b/packages/react-dom/src/test-utils/ReactTestUtilsAct.js index d0a9740b094d..ce72da89dac0 100644 --- a/packages/react-dom/src/test-utils/ReactTestUtilsAct.js +++ b/packages/react-dom/src/test-utils/ReactTestUtilsAct.js @@ -9,7 +9,7 @@ import type {Thenable} from 'react-reconciler/src/ReactFiberWorkLoop'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import ReactDOM from 'react-dom'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import enqueueTask from 'shared/enqueueTask'; @@ -102,7 +102,7 @@ function act(callback: () => Thenable) { if (__DEV__) { if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) { // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned - warningWithoutStack( + warning( 'You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ', ); @@ -134,7 +134,7 @@ function act(callback: () => Thenable) { .then(() => {}) .then(() => { if (called === false) { - warningWithoutStack( + warning( 'You called act(async () => ...) without await. ' + 'This could lead to unexpected testing behaviour, interleaving multiple act ' + 'calls and mixing their scopes. You should - await act(async () => ...);', @@ -182,7 +182,7 @@ function act(callback: () => Thenable) { } else { if (__DEV__) { if (result !== undefined) { - warningWithoutStack( + warning( 'The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result, @@ -210,7 +210,7 @@ function act(callback: () => Thenable) { return { then(resolve: () => void) { if (__DEV__) { - warningWithoutStack( + warning( 'Do not await the result of calling act(...) with sync logic, it is not a Promise.', ); } diff --git a/packages/react-native-renderer/src/NativeMethodsMixin.js b/packages/react-native-renderer/src/NativeMethodsMixin.js index 35adddba19ad..af34be73d9b0 100644 --- a/packages/react-native-renderer/src/NativeMethodsMixin.js +++ b/packages/react-native-renderer/src/NativeMethodsMixin.js @@ -29,7 +29,7 @@ import { warnForStyleProps, } from './NativeMethodsMixinUtils'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; export default function( findNodeHandle: any => ?number, @@ -180,7 +180,7 @@ export default function( if (maybeInstance.canonical) { if (__DEV__) { - warningWithoutStack( + warning( 'Warning: measureLayout on components using NativeMethodsMixin ' + 'or ReactNative.NativeComponent is not currently supported in Fabric. ' + 'measureLayout must be called on a native ref. Consider using forwardRef.', @@ -199,7 +199,7 @@ export default function( if (relativeNode == null) { if (__DEV__) { - warningWithoutStack( + warning( 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.', ); } @@ -246,7 +246,7 @@ export default function( if (maybeInstance.canonical) { if (__DEV__) { - warningWithoutStack( + warning( 'Warning: setNativeProps is not currently supported in Fabric', ); } diff --git a/packages/react-native-renderer/src/ReactFabric.js b/packages/react-native-renderer/src/ReactFabric.js index 9f0a408d9938..e108aba1afb0 100644 --- a/packages/react-native-renderer/src/ReactFabric.js +++ b/packages/react-native-renderer/src/ReactFabric.js @@ -37,7 +37,7 @@ import {getInspectorDataForViewTag} from './ReactNativeFiberInspector'; import {LegacyRoot} from 'shared/ReactRootTags'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import getComponentName from 'shared/getComponentName'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; const {dispatchCommand: fabricDispatchCommand} = nativeFabricUIManager; @@ -50,7 +50,7 @@ function findHostInstance_DEPRECATED( const owner = ReactCurrentOwner.current; if (owner !== null && owner.stateNode !== null) { if (!owner.stateNode._warnedAboutRefsInRender) { - warningWithoutStack( + warning( '%s is accessing findNodeHandle inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + @@ -97,7 +97,7 @@ function findNodeHandle(componentOrHandle: any): ?number { const owner = ReactCurrentOwner.current; if (owner !== null && owner.stateNode !== null) { if (!owner.stateNode._warnedAboutRefsInRender) { - warningWithoutStack( + warning( '%s is accessing findNodeHandle inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + @@ -169,7 +169,7 @@ const ReactFabric: ReactFabricType = { if (invalid) { if (__DEV__) { if (invalid) { - warningWithoutStack( + warning( "dispatchCommand was called with a ref that isn't a " + 'native component. Use React.forwardRef to get access to the underlying native component', ); diff --git a/packages/react-native-renderer/src/ReactFabricHostConfig.js b/packages/react-native-renderer/src/ReactFabricHostConfig.js index 3ce0c76e0392..8a599fe462d4 100644 --- a/packages/react-native-renderer/src/ReactFabricHostConfig.js +++ b/packages/react-native-renderer/src/ReactFabricHostConfig.js @@ -25,7 +25,7 @@ import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils'; import {create, diff} from './ReactNativeAttributePayload'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {dispatchEvent} from './ReactFabricEventEmitter'; import { @@ -159,7 +159,7 @@ class ReactFabricHostComponent { !(relativeToNativeNode instanceof ReactFabricHostComponent) ) { if (__DEV__) { - warningWithoutStack( + warning( 'Warning: ref.measureLayout must be called with a ref to a native component.', ); } @@ -177,9 +177,7 @@ class ReactFabricHostComponent { setNativeProps(nativeProps: Object) { if (__DEV__) { - warningWithoutStack( - 'Warning: setNativeProps is not currently supported in Fabric', - ); + warning('Warning: setNativeProps is not currently supported in Fabric'); } return; diff --git a/packages/react-native-renderer/src/ReactNativeComponent.js b/packages/react-native-renderer/src/ReactNativeComponent.js index f5bef79fc67a..c7e44f26dc7f 100644 --- a/packages/react-native-renderer/src/ReactNativeComponent.js +++ b/packages/react-native-renderer/src/ReactNativeComponent.js @@ -26,7 +26,7 @@ import { import {create} from './ReactNativeAttributePayload'; import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; export default function( findNodeHandle: any => ?number, @@ -191,7 +191,7 @@ export default function( if (maybeInstance.canonical) { if (__DEV__) { - warningWithoutStack( + warning( 'Warning: measureLayout on components using NativeMethodsMixin ' + 'or ReactNative.NativeComponent is not currently supported in Fabric. ' + 'measureLayout must be called on a native ref. Consider using forwardRef.', @@ -210,7 +210,7 @@ export default function( if (relativeNode == null) { if (__DEV__) { - warningWithoutStack( + warning( 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.', ); } @@ -257,7 +257,7 @@ export default function( if (maybeInstance.canonical) { if (__DEV__) { - warningWithoutStack( + warning( 'Warning: setNativeProps is not currently supported in Fabric', ); } diff --git a/packages/react-native-renderer/src/ReactNativeEventEmitter.js b/packages/react-native-renderer/src/ReactNativeEventEmitter.js index b8597d395434..32592c3e8026 100644 --- a/packages/react-native-renderer/src/ReactNativeEventEmitter.js +++ b/packages/react-native-renderer/src/ReactNativeEventEmitter.js @@ -14,7 +14,7 @@ import { } from 'legacy-events/EventPluginHub'; import {registrationNameModules} from 'legacy-events/EventPluginRegistry'; import {batchedUpdates} from 'legacy-events/ReactGenericBatching'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags'; import {getInstanceFromNode} from './ReactNativeComponentTree'; @@ -184,9 +184,7 @@ export function receiveTouches( if (target !== null && target !== undefined) { if (target < 1) { if (__DEV__) { - warningWithoutStack( - 'A view is reporting that a touch occurred on tag zero.', - ); + warning('A view is reporting that a touch occurred on tag zero.'); } } else { rootNodeID = target; diff --git a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js index ffb52a9d8bfa..8850f830bb7e 100644 --- a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js +++ b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js @@ -28,7 +28,7 @@ import { warnForStyleProps, } from './NativeMethodsMixinUtils'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; /** * This component defines the same methods as NativeMethodsMixin but without the @@ -86,7 +86,7 @@ class ReactNativeFiberHostComponent { if (relativeNode == null) { if (__DEV__) { - warningWithoutStack( + warning( 'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.', ); } diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 2fa52b9e1a84..550e63609c5d 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -43,7 +43,7 @@ import {getInspectorDataForViewTag} from './ReactNativeFiberInspector'; import {LegacyRoot} from 'shared/ReactRootTags'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import getComponentName from 'shared/getComponentName'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner; @@ -54,7 +54,7 @@ function findHostInstance_DEPRECATED( const owner = ReactCurrentOwner.current; if (owner !== null && owner.stateNode !== null) { if (!owner.stateNode._warnedAboutRefsInRender) { - warningWithoutStack( + warning( '%s is accessing findNodeHandle inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + @@ -101,7 +101,7 @@ function findNodeHandle(componentOrHandle: any): ?number { const owner = ReactCurrentOwner.current; if (owner !== null && owner.stateNode !== null) { if (!owner.stateNode._warnedAboutRefsInRender) { - warningWithoutStack( + warning( '%s is accessing findNodeHandle inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + @@ -176,7 +176,7 @@ const ReactNativeRenderer: ReactNativeType = { if (handle._nativeTag == null) { if (__DEV__) { if (handle._nativeTag == null) { - warningWithoutStack( + warning( "dispatchCommand was called with a ref that isn't a " + 'native component. Use React.forwardRef to get access to the underlying native component', ); diff --git a/packages/react-noop-renderer/src/createReactNoop.js b/packages/react-noop-renderer/src/createReactNoop.js index 14a1d6af4210..d39252e28099 100644 --- a/packages/react-noop-renderer/src/createReactNoop.js +++ b/packages/react-noop-renderer/src/createReactNoop.js @@ -25,7 +25,7 @@ import {createPortal} from 'shared/ReactPortal'; import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols'; import enqueueTask from 'shared/enqueueTask'; import ReactSharedInternals from 'shared/ReactSharedInternals'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {ConcurrentRoot, BlockingRoot, LegacyRoot} from 'shared/ReactRootTags'; type Container = { @@ -661,7 +661,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { if (__DEV__) { if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) { // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned - warningWithoutStack( + warning( 'You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ', ); @@ -693,7 +693,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { .then(() => {}) .then(() => { if (called === false) { - warningWithoutStack( + warning( 'You called act(async () => ...) without await. ' + 'This could lead to unexpected testing behaviour, interleaving multiple act ' + 'calls and mixing their scopes. You should - await act(async () => ...);', @@ -741,7 +741,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { } else { if (__DEV__) { if (result !== undefined) { - warningWithoutStack( + warning( 'The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result, @@ -770,7 +770,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { return { then(resolve: () => void) { if (__DEV__) { - warningWithoutStack( + warning( 'Do not await the result of calling act(...) with sync logic, it is not a Promise.', ); } diff --git a/packages/react-reconciler/src/ReactChildFiber.js b/packages/react-reconciler/src/ReactChildFiber.js index aa41c36b3d18..b2e862536417 100644 --- a/packages/react-reconciler/src/ReactChildFiber.js +++ b/packages/react-reconciler/src/ReactChildFiber.js @@ -29,7 +29,6 @@ import { } from 'shared/ReactWorkTags'; import invariant from 'shared/invariant'; import warning from 'shared/warning'; -import warningWithoutStack from 'shared/warningWithoutStack'; import {warnAboutStringRefs} from 'shared/ReactFeatureFlags'; import { @@ -120,7 +119,7 @@ function coerceRef( const componentName = getComponentName(returnFiber.type) || 'Component'; if (!didWarnAboutStringRefs[componentName]) { if (warnAboutStringRefs) { - warningWithoutStack( + warning( '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. ' + @@ -131,7 +130,7 @@ function coerceRef( getStackByFiberInDevAndProd(returnFiber), ); } else { - warningWithoutStack( + warning( '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. ' + diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index cc9d04b8a295..15ab7d0d4fe5 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -28,7 +28,7 @@ import type {HookType} from './ReactFiberHooks'; import type {SuspenseInstance} from './ReactFiberHostConfig'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import { enableProfilerTimer, enableFundamentalAPI, @@ -805,7 +805,7 @@ function createFiberFromProfiler( typeof pendingProps.id !== 'string' || typeof pendingProps.onRender !== 'function' ) { - warningWithoutStack( + warning( 'Profiler must specify an "id" string and "onRender" function as props', ); } diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index 173529b824c2..ada9a09c2a30 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -72,7 +72,6 @@ import ReactStrictModeWarnings from './ReactStrictModeWarnings'; import {refineResolvedLazyComponent} from 'shared/ReactLazyComponent'; import {REACT_LAZY_TYPE, getIteratorFn} from 'shared/ReactSymbols'; import warning from 'shared/warning'; -import warningWithoutStack from 'shared/warningWithoutStack'; import { setCurrentPhase, getCurrentFiberOwnerNameInDevOrNull, @@ -1257,7 +1256,7 @@ function mountIndeterminateComponent( const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutBadClass[componentName]) { - warningWithoutStack( + warning( "The <%s /> component appears to have a render method, but doesn't extend React.Component. " + 'This is likely to cause errors. Change %s to extend React.Component instead.', componentName, @@ -1302,7 +1301,7 @@ function mountIndeterminateComponent( if (__DEV__) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutModulePatternComponent[componentName]) { - warningWithoutStack( + warning( 'The <%s /> component appears to be a function component that returns a class instance. ' + 'Change %s to a class that extends React.Component instead. ' + "If you can't use a class try assigning the prototype on the function as a workaround. " + @@ -1363,7 +1362,7 @@ function mountIndeterminateComponent( workInProgress.tag = FunctionComponent; if (__DEV__) { if (disableLegacyContext && Component.contextTypes) { - warningWithoutStack( + warning( '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with React.useContext() instead.', getComponentName(Component) || 'Unknown', @@ -1399,7 +1398,7 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) { if (__DEV__) { if (Component) { if (Component.childContextTypes) { - warningWithoutStack( + warning( '%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component', ); @@ -1435,7 +1434,7 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) { - warningWithoutStack( + warning( '%s: Support for defaultProps will be removed from function components ' + 'in a future major release. Use JavaScript default parameters instead.', componentName, @@ -1448,7 +1447,7 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutGetDerivedStateOnFunctionComponent[componentName]) { - warningWithoutStack( + warning( '%s: Function components do not support getDerivedStateFromProps.', componentName, ); @@ -1463,7 +1462,7 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) { const componentName = getComponentName(Component) || 'Unknown'; if (!didWarnAboutContextTypeOnFunctionComponent[componentName]) { - warningWithoutStack( + warning( '%s: Function components do not support contextType.', componentName, ); @@ -2630,7 +2629,7 @@ function updateContextConsumer( if (__DEV__) { if (typeof render !== 'function') { - warningWithoutStack( + warning( 'A context consumer was rendered with multiple children, or a child ' + "that isn't a function. A context consumer expects a single child " + 'that is a function. If you did pass a function, make sure there ' + diff --git a/packages/react-reconciler/src/ReactFiberClassComponent.js b/packages/react-reconciler/src/ReactFiberClassComponent.js index 185256bf24e4..112beebda2d9 100644 --- a/packages/react-reconciler/src/ReactFiberClassComponent.js +++ b/packages/react-reconciler/src/ReactFiberClassComponent.js @@ -24,7 +24,7 @@ import {get as getInstance, set as setInstance} from 'shared/ReactInstanceMap'; import shallowEqual from 'shared/shallowEqual'; import getComponentName from 'shared/getComponentName'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols'; import {startPhaseTimer, stopPhaseTimer} from './ReactDebugFiberPerf'; @@ -95,7 +95,7 @@ if (__DEV__) { const key = `${callerName}_${(callback: any)}`; if (!didWarnOnInvalidCallback.has(key)) { didWarnOnInvalidCallback.add(key); - warningWithoutStack( + warning( '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, @@ -109,7 +109,7 @@ if (__DEV__) { const componentName = getComponentName(type) || 'Component'; if (!didWarnAboutUndefinedDerivedState.has(componentName)) { didWarnAboutUndefinedDerivedState.add(componentName); - warningWithoutStack( + warning( '%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName, @@ -273,7 +273,7 @@ function checkShouldComponentUpdate( if (__DEV__) { if (shouldUpdate === undefined) { - warningWithoutStack( + warning( '%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', getComponentName(ctor) || 'Component', @@ -301,13 +301,13 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { if (!renderPresent) { if (ctor.prototype && typeof ctor.prototype.render === 'function') { - warningWithoutStack( + warning( '%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name, ); } else { - warningWithoutStack( + warning( '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name, @@ -320,7 +320,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { !instance.getInitialState.isReactClassApproved && !instance.state ) { - warningWithoutStack( + warning( 'getInitialState was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Did you mean to define a state property instead?', @@ -331,7 +331,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { instance.getDefaultProps && !instance.getDefaultProps.isReactClassApproved ) { - warningWithoutStack( + warning( 'getDefaultProps was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Use a static property to define defaultProps instead.', @@ -339,14 +339,14 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { ); } if (instance.propTypes) { - warningWithoutStack( + warning( 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name, ); } if (instance.contextType) { - warningWithoutStack( + warning( 'contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name, @@ -355,14 +355,14 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { if (disableLegacyContext) { if (ctor.childContextTypes) { - warningWithoutStack( + warning( '%s uses the legacy childContextTypes API which is no longer supported. ' + 'Use React.createContext() instead.', name, ); } if (ctor.contextTypes) { - warningWithoutStack( + warning( '%s uses the legacy contextTypes API which is no longer supported. ' + 'Use React.createContext() with static contextType instead.', name, @@ -370,7 +370,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { } } else { if (instance.contextTypes) { - warningWithoutStack( + warning( 'contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name, @@ -383,7 +383,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { !didWarnAboutContextTypeAndContextTypes.has(ctor) ) { didWarnAboutContextTypeAndContextTypes.add(ctor); - warningWithoutStack( + warning( '%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name, @@ -392,7 +392,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { } if (typeof instance.componentShouldUpdate === 'function') { - warningWithoutStack( + warning( '%s has a method called ' + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + 'The name is phrased as a question because the function is ' + @@ -405,7 +405,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined' ) { - warningWithoutStack( + warning( '%s has a method called shouldComponentUpdate(). ' + 'shouldComponentUpdate should not be used when extending React.PureComponent. ' + 'Please extend React.Component if shouldComponentUpdate is used.', @@ -413,7 +413,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { ); } if (typeof instance.componentDidUnmount === 'function') { - warningWithoutStack( + warning( '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', @@ -421,7 +421,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { ); } if (typeof instance.componentDidReceiveProps === 'function') { - warningWithoutStack( + warning( '%s has a method called ' + 'componentDidReceiveProps(). But there is no such lifecycle method. ' + 'If you meant to update the state in response to changing props, ' + @@ -431,14 +431,14 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { ); } if (typeof instance.componentWillRecieveProps === 'function') { - warningWithoutStack( + warning( '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name, ); } if (typeof instance.UNSAFE_componentWillRecieveProps === 'function') { - warningWithoutStack( + warning( '%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name, @@ -446,7 +446,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { } const hasMutatedProps = instance.props !== newProps; if (instance.props !== undefined && hasMutatedProps) { - warningWithoutStack( + warning( '%s(...): When calling super() in `%s`, make sure to pass ' + "up the same props that your component's constructor was passed.", name, @@ -454,7 +454,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { ); } if (instance.defaultProps) { - warningWithoutStack( + warning( 'Setting defaultProps as an instance property on %s is not supported and will be ignored.' + ' Instead, define defaultProps as a static property on %s.', name, @@ -468,7 +468,7 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor) ) { didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor); - warningWithoutStack( + warning( '%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor), @@ -476,21 +476,21 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { } if (typeof instance.getDerivedStateFromProps === 'function') { - warningWithoutStack( + warning( '%s: getDerivedStateFromProps() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name, ); } if (typeof instance.getDerivedStateFromError === 'function') { - warningWithoutStack( + warning( '%s: getDerivedStateFromError() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name, ); } if (typeof ctor.getSnapshotBeforeUpdate === 'function') { - warningWithoutStack( + warning( '%s: getSnapshotBeforeUpdate() is defined as a static method ' + 'and will be ignored. Instead, declare it as an instance method.', name, @@ -498,13 +498,13 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) { } const state = instance.state; if (state && (typeof state !== 'object' || isArray(state))) { - warningWithoutStack('%s.state: must be set to an object or null', name); + warning('%s.state: must be set to an object or null', name); } if ( typeof instance.getChildContext === 'function' && typeof ctor.childContextTypes !== 'object' ) { - warningWithoutStack( + warning( '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name, @@ -566,7 +566,7 @@ function constructClassInstance( Object.keys(contextType).join(', ') + '}.'; } - warningWithoutStack( + warning( '%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', @@ -610,7 +610,7 @@ function constructClassInstance( const componentName = getComponentName(ctor) || 'Component'; if (!didWarnAboutUninitializedState.has(componentName)) { didWarnAboutUninitializedState.add(componentName); - warningWithoutStack( + warning( '`%s` uses `getDerivedStateFromProps` but its initial state is ' + '%s. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `%s`. ' + @@ -670,7 +670,7 @@ function constructClassInstance( : 'getSnapshotBeforeUpdate()'; if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(componentName)) { didWarnAboutLegacyLifecyclesAndDerivedState.add(componentName); - warningWithoutStack( + warning( 'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' + '%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + @@ -712,7 +712,7 @@ function callComponentWillMount(workInProgress, instance) { if (oldState !== instance.state) { if (__DEV__) { - warningWithoutStack( + warning( '%s.componentWillMount(): Assigning directly to this.state is ' + "deprecated (except inside a component's " + 'constructor). Use setState instead.', @@ -745,7 +745,7 @@ function callComponentWillReceiveProps( getComponentName(workInProgress.type) || 'Component'; if (!didWarnAboutStateAssignmentForComponent.has(componentName)) { didWarnAboutStateAssignmentForComponent.add(componentName); - warningWithoutStack( + warning( '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', @@ -790,7 +790,7 @@ function mountClassInstance( const componentName = getComponentName(ctor) || 'Component'; if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) { didWarnAboutDirectlyAssigningPropsToState.add(componentName); - warningWithoutStack( + warning( '%s: It is not recommended to assign props directly to state ' + "because updates to props won't be reflected in state. " + 'In most cases, it is better to use props directly.', diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.js b/packages/react-reconciler/src/ReactFiberCommitWork.js index e2faf7e7718e..b884a5fd5e26 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.js @@ -67,7 +67,6 @@ import { } from 'shared/ReactSideEffectTags'; import getComponentName from 'shared/getComponentName'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; import warning from 'shared/warning'; import {onCommitUnmount} from './ReactFiberDevToolsHook'; @@ -302,7 +301,7 @@ function commitBeforeMutationLifeCycles( >); if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) { didWarnSet.add(finishedWork.type); - warningWithoutStack( + warning( '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type), @@ -381,7 +380,7 @@ function commitHookEffectList( } else { addendum = ' You returned: ' + destroy; } - warningWithoutStack( + warning( 'An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s%s', addendum, @@ -713,7 +712,7 @@ function commitAttachRef(finishedWork: Fiber) { } else { if (__DEV__) { if (!ref.hasOwnProperty('current')) { - warningWithoutStack( + warning( 'Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().%s', getComponentName(finishedWork.type), diff --git a/packages/react-reconciler/src/ReactFiberContext.js b/packages/react-reconciler/src/ReactFiberContext.js index 3da11ce98ec7..3187dcfc6d8a 100644 --- a/packages/react-reconciler/src/ReactFiberContext.js +++ b/packages/react-reconciler/src/ReactFiberContext.js @@ -15,7 +15,7 @@ import {disableLegacyContext} from 'shared/ReactFeatureFlags'; import {ClassComponent, HostRoot} from 'shared/ReactWorkTags'; import getComponentName from 'shared/getComponentName'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import checkPropTypes from 'prop-types/checkPropTypes'; import {setCurrentPhase, getCurrentFiberStackInDev} from './ReactCurrentFiber'; @@ -198,7 +198,7 @@ function processChildContext( if (!warnedAboutMissingGetChildContext[componentName]) { warnedAboutMissingGetChildContext[componentName] = true; - warningWithoutStack( + warning( '%s.childContextTypes is specified but there is no getChildContext() method ' + 'on the instance. You can either define getChildContext() on %s or remove ' + 'childContextTypes from it.', diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.js index aacaa284d25b..944890dc3022 100644 --- a/packages/react-reconciler/src/ReactFiberDevToolsHook.js +++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.js @@ -17,7 +17,7 @@ import type {ExpirationTime} from './ReactFiberExpirationTime'; import type {ReactNodeList} from 'shared/ReactTypes'; import {DidCapture} from 'shared/ReactSideEffectTags'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void; @@ -43,7 +43,7 @@ export function injectInternals(internals: Object): boolean { } if (!hook.supportsFiber) { if (__DEV__) { - warningWithoutStack( + warning( 'The installed version of React DevTools is too old and will not work ' + 'with the current version of React. Please update React DevTools. ' + 'https://fb.me/react-devtools', @@ -64,10 +64,7 @@ export function injectInternals(internals: Object): boolean { } catch (err) { if (__DEV__ && !hasLoggedError) { hasLoggedError = true; - warningWithoutStack( - 'React instrumentation encountered an error: %s', - err, - ); + warning('React instrumentation encountered an error: %s', err); } } }; @@ -90,10 +87,7 @@ export function injectInternals(internals: Object): boolean { if (__DEV__) { if (!hasLoggedError) { hasLoggedError = true; - warningWithoutStack( - 'React instrumentation encountered an error: %s', - err, - ); + warning('React instrumentation encountered an error: %s', err); } } } @@ -105,10 +99,7 @@ export function injectInternals(internals: Object): boolean { if (__DEV__) { if (!hasLoggedError) { hasLoggedError = true; - warningWithoutStack( - 'React instrumentation encountered an error: %s', - err, - ); + warning('React instrumentation encountered an error: %s', err); } } } @@ -116,10 +107,7 @@ export function injectInternals(internals: Object): boolean { } catch (err) { // Catch all errors because it is unsafe to throw during initialization. if (__DEV__) { - warningWithoutStack( - 'React instrumentation encountered an error: %s.', - err, - ); + warning('React instrumentation encountered an error: %s.', err); } } // DevTools exists diff --git a/packages/react-reconciler/src/ReactFiberNewContext.js b/packages/react-reconciler/src/ReactFiberNewContext.js index 37a699772950..dcc75e06a545 100644 --- a/packages/react-reconciler/src/ReactFiberNewContext.js +++ b/packages/react-reconciler/src/ReactFiberNewContext.js @@ -18,7 +18,6 @@ export type ContextDependency = { next: ContextDependency | null, }; -import warningWithoutStack from 'shared/warningWithoutStack'; import {isPrimaryRenderer} from './ReactFiberHostConfig'; import {createCursor, push, pop} from './ReactFiberStack'; import MAX_SIGNED_31_BIT_INT from './maxSigned31BitInt'; @@ -90,7 +89,7 @@ export function pushProvider(providerFiber: Fiber, nextValue: T): void { context._currentRenderer !== null && context._currentRenderer !== rendererSigil ) { - warningWithoutStack( + warning( 'Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.', ); @@ -107,7 +106,7 @@ export function pushProvider(providerFiber: Fiber, nextValue: T): void { context._currentRenderer2 !== null && context._currentRenderer2 !== rendererSigil ) { - warningWithoutStack( + warning( 'Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.', ); diff --git a/packages/react-reconciler/src/ReactFiberReconciler.js b/packages/react-reconciler/src/ReactFiberReconciler.js index 5dcafba8be47..6b44f180847f 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.js @@ -37,7 +37,7 @@ import { } from 'shared/ReactWorkTags'; import getComponentName from 'shared/getComponentName'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import {getPublicInstance} from './ReactFiberHostConfig'; @@ -181,7 +181,7 @@ function findHostInstanceWithWarning( if (!didWarnAboutFindNodeInStrictMode[componentName]) { didWarnAboutFindNodeInStrictMode[componentName] = true; if (fiber.mode & StrictMode) { - warningWithoutStack( + warning( '%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. ' + @@ -193,7 +193,7 @@ function findHostInstanceWithWarning( getStackByFiberInDevAndProd(hostFiber), ); } else { - warningWithoutStack( + warning( '%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. ' + @@ -260,7 +260,7 @@ export function updateContainer( !didWarnAboutNestedUpdates ) { didWarnAboutNestedUpdates = true; - warningWithoutStack( + warning( 'Render methods should be a pure function of props and state; ' + 'triggering nested component updates from render is not allowed. ' + 'If necessary, trigger nested updates in componentDidUpdate.\n\n' + @@ -279,7 +279,7 @@ export function updateContainer( if (callback !== null) { if (__DEV__) { if (typeof callback !== 'function') { - warningWithoutStack( + warning( 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback, diff --git a/packages/react-reconciler/src/ReactFiberStack.js b/packages/react-reconciler/src/ReactFiberStack.js index 4d5413e3cb9a..bd9677492d7c 100644 --- a/packages/react-reconciler/src/ReactFiberStack.js +++ b/packages/react-reconciler/src/ReactFiberStack.js @@ -9,7 +9,7 @@ import type {Fiber} from './ReactFiber'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; export type StackCursor = { current: T, @@ -38,14 +38,14 @@ function isEmpty(): boolean { function pop(cursor: StackCursor, fiber: Fiber): void { if (index < 0) { if (__DEV__) { - warningWithoutStack('Unexpected pop.'); + warning('Unexpected pop.'); } return; } if (__DEV__) { if (fiber !== fiberStack[index]) { - warningWithoutStack('Unexpected Fiber popped.'); + warning('Unexpected Fiber popped.'); } } @@ -75,9 +75,7 @@ function push(cursor: StackCursor, value: T, fiber: Fiber): void { function checkThatStackIsEmpty() { if (__DEV__) { if (index !== -1) { - warningWithoutStack( - 'Expected an empty stack. Something was not reset properly.', - ); + warning('Expected an empty stack. Something was not reset properly.'); } } } diff --git a/packages/react-reconciler/src/ReactFiberThrow.js b/packages/react-reconciler/src/ReactFiberThrow.js index 9559dfd6c4c3..fdc562c2a219 100644 --- a/packages/react-reconciler/src/ReactFiberThrow.js +++ b/packages/react-reconciler/src/ReactFiberThrow.js @@ -16,7 +16,7 @@ import type {Thenable} from './ReactFiberWorkLoop'; import type {SuspenseContext} from './ReactFiberSuspenseContext'; import getComponentName from 'shared/getComponentName'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import { ClassComponent, HostRoot, @@ -125,7 +125,7 @@ function createClassErrorUpdate( // then it needs to call setState to recover from errors. // If no state update is scheduled then the boundary will swallow the error. if (fiber.expirationTime !== Sync) { - warningWithoutStack( + warning( '%s: Error boundaries should implement getDerivedStateFromError(). ' + 'In that method, return a state update to display an error message or fallback UI.', getComponentName(fiber.type) || 'Unknown', diff --git a/packages/react-reconciler/src/ReactFiberTreeReflection.js b/packages/react-reconciler/src/ReactFiberTreeReflection.js index 59f5fda12bd7..e82169f1b995 100644 --- a/packages/react-reconciler/src/ReactFiberTreeReflection.js +++ b/packages/react-reconciler/src/ReactFiberTreeReflection.js @@ -12,7 +12,7 @@ import type {Container, SuspenseInstance} from './ReactFiberHostConfig'; import type {SuspenseState} from './ReactFiberSuspenseComponent'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {get as getInstance} from 'shared/ReactInstanceMap'; import ReactSharedInternals from 'shared/ReactSharedInternals'; @@ -98,7 +98,7 @@ export function isMounted(component: React$Component): boolean { const ownerFiber: Fiber = owner; const instance = ownerFiber.stateNode; if (!instance._warnedAboutRefsInRender) { - warningWithoutStack( + warning( '%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.js b/packages/react-reconciler/src/ReactFiberWorkLoop.js index d6ff926bd9b3..81ad6e77f3dc 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.js @@ -30,7 +30,6 @@ import { } from 'shared/ReactFeatureFlags'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import invariant from 'shared/invariant'; -import warning from 'shared/warning'; import { scheduleCallback, @@ -151,7 +150,7 @@ import { } from './ReactProfilerTimer'; // DEV stuff -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import getComponentName from 'shared/getComponentName'; import ReactStrictModeWarnings from './ReactStrictModeWarnings'; import { @@ -2595,7 +2594,7 @@ function warnAboutUpdateOnUnmountedFiberInDEV(fiber) { } else { didWarnStateUpdateForUnmountedComponent = new Set([componentName]); } - warningWithoutStack( + warning( "Can't perform a React state update on an unmounted component. This " + 'is a no-op, but it indicates a memory leak in your application. To ' + 'fix, cancel all subscriptions and asynchronous tasks in %s.%s', @@ -2686,7 +2685,7 @@ function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) { if (didWarnAboutUpdateInGetChildContext) { return; } - warningWithoutStack( + warning( 'setState(...): Cannot call setState() inside getChildContext()', ); didWarnAboutUpdateInGetChildContext = true; @@ -2695,7 +2694,7 @@ function warnAboutInvalidUpdatesOnClassComponentsInDEV(fiber) { if (didWarnAboutUpdateInRender) { return; } - warningWithoutStack( + warning( 'Cannot update during an existing state transition (such as ' + 'within `render`). Render methods should be a pure function of ' + 'props and state.', @@ -2717,7 +2716,7 @@ export function warnIfNotScopedWithMatchingAct(fiber: Fiber): void { IsSomeRendererActing.current === true && IsThisRendererActing.current !== true ) { - warningWithoutStack( + warning( "It looks like you're using the wrong act() around your test interactions.\n" + 'Be sure to use the matching version of act() corresponding to your renderer:\n\n' + '// for react-dom:\n' + @@ -2744,7 +2743,7 @@ export function warnIfNotCurrentlyActingEffectsInDEV(fiber: Fiber): void { IsSomeRendererActing.current === false && IsThisRendererActing.current === false ) { - warningWithoutStack( + warning( 'An update to %s ran an effect, but was not wrapped in act(...).\n\n' + 'When testing, code that causes React state updates should be ' + 'wrapped into act(...):\n\n' + @@ -2771,7 +2770,7 @@ function warnIfNotCurrentlyActingUpdatesInDEV(fiber: Fiber): void { IsSomeRendererActing.current === false && IsThisRendererActing.current === false ) { - warningWithoutStack( + warning( 'An update to %s inside a test was not wrapped in act(...).\n\n' + 'When testing, code that causes React state updates should be ' + 'wrapped into act(...):\n\n' + @@ -2807,7 +2806,7 @@ export function warnIfUnmockedScheduler(fiber: Fiber) { ) { if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) { didWarnAboutUnmockedScheduler = true; - warningWithoutStack( + warning( 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' + 'to guarantee consistent behaviour across tests and browsers. ' + 'For example, with jest: \n' + @@ -2816,7 +2815,7 @@ export function warnIfUnmockedScheduler(fiber: Fiber) { ); } else if (warnAboutUnmockedScheduler === true) { didWarnAboutUnmockedScheduler = true; - warningWithoutStack( + warning( 'Starting from React v17, the "scheduler" module will need to be mocked ' + 'to guarantee consistent behaviour across tests and browsers. ' + 'For example, with jest: \n' + @@ -2926,7 +2925,7 @@ function flushSuspensePriorityWarningInDEV() { componentsThatTriggeredHighPriSuspend = null; if (componentNames.length > 0) { - warningWithoutStack( + warning( '%s triggered a user-blocking update that suspended.' + '\n\n' + 'The fix is to split the update into multiple parts: a user-blocking ' + diff --git a/packages/react-reconciler/src/ReactStrictModeWarnings.js b/packages/react-reconciler/src/ReactStrictModeWarnings.js index e839bab4393e..75495c572f09 100644 --- a/packages/react-reconciler/src/ReactStrictModeWarnings.js +++ b/packages/react-reconciler/src/ReactStrictModeWarnings.js @@ -13,8 +13,8 @@ import {getStackByFiberInDevAndProd} from './ReactCurrentFiber'; import getComponentName from 'shared/getComponentName'; import {StrictMode} from './ReactTypeOfMode'; -import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import lowPriorityWarning from 'shared/lowPriorityWarning'; +import warning from 'shared/warning'; type FiberArray = Array; type FiberToFiberComponentsMap = Map; @@ -191,7 +191,7 @@ if (__DEV__) { const sortedNames = setToSortedString( UNSAFE_componentWillMountUniqueNames, ); - warningWithoutStack( + warning( 'Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' + @@ -204,7 +204,7 @@ if (__DEV__) { const sortedNames = setToSortedString( UNSAFE_componentWillReceivePropsUniqueNames, ); - warningWithoutStack( + warning( 'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + @@ -221,7 +221,7 @@ if (__DEV__) { const sortedNames = setToSortedString( UNSAFE_componentWillUpdateUniqueNames, ); - warningWithoutStack( + warning( 'Using UNSAFE_componentWillUpdate in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + @@ -234,7 +234,7 @@ if (__DEV__) { if (componentWillMountUniqueNames.size > 0) { const sortedNames = setToSortedString(componentWillMountUniqueNames); - lowPriorityWarningWithoutStack( + lowPriorityWarning( 'componentWillMount has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' + @@ -252,7 +252,7 @@ if (__DEV__) { componentWillReceivePropsUniqueNames, ); - lowPriorityWarningWithoutStack( + lowPriorityWarning( 'componentWillReceiveProps has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + @@ -271,7 +271,7 @@ if (__DEV__) { if (componentWillUpdateUniqueNames.size > 0) { const sortedNames = setToSortedString(componentWillUpdateUniqueNames); - lowPriorityWarningWithoutStack( + lowPriorityWarning( 'componentWillUpdate has been renamed, and is not recommended for use. ' + 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + @@ -296,7 +296,7 @@ if (__DEV__) { ) => { const strictRoot = findStrictRoot(fiber); if (strictRoot === null) { - warningWithoutStack( + warning( 'Expected to find a StrictMode component in a strict mode tree. ' + 'This error is likely caused by a bug in React. Please file an issue.', ); @@ -337,7 +337,7 @@ if (__DEV__) { strictRoot, ); - warningWithoutStack( + warning( '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.' + diff --git a/packages/react-reconciler/src/ReactUpdateQueue.js b/packages/react-reconciler/src/ReactUpdateQueue.js index 95457776b8cb..e4d83d7f39f6 100644 --- a/packages/react-reconciler/src/ReactUpdateQueue.js +++ b/packages/react-reconciler/src/ReactUpdateQueue.js @@ -105,7 +105,7 @@ import { } from './ReactFiberWorkLoop'; import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {getCurrentPriorityLevel} from './SchedulerWithReactIntegration'; export type Update = { @@ -228,7 +228,7 @@ export function enqueueUpdate(fiber: Fiber, update: Update) { currentlyProcessingQueue === sharedQueue && !didWarnUpdateInsideUpdate ) { - warningWithoutStack( + warning( 'An update (setState, replaceState, or forceUpdate) was scheduled ' + 'from inside an update function. Update functions should be pure, ' + 'with zero side-effects. Consider using componentDidUpdate or a ' + diff --git a/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js b/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js index 6bc4871e4c68..d83cf235ee4c 100644 --- a/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js @@ -1349,7 +1349,6 @@ describe('ReactHooks', () => { "If you can't use a class try assigning the prototype on the function as a workaround. " + '`Factory.prototype = React.Component.prototype`. ' + "Don't use an arrow function since it cannot be called with `new` by React.", - {withoutStack: true}, ); expect(renderCount).toBe(1); renderCount = 0; diff --git a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js index 5e60e235ac43..4b13251a2de0 100644 --- a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js @@ -201,7 +201,6 @@ describe('ReactHooksWithNoopRenderer', () => { "If you can't use a class try assigning the prototype on the function as a workaround. " + '`Counter.prototype = React.Component.prototype`. ' + "Don't use an arrow function since it cannot be called with `new` by React.", - {withoutStack: true}, ); // Confirm that a subsequent hook works properly. diff --git a/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js index d4448cf8c0ec..4b9378a6166b 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js @@ -2051,7 +2051,7 @@ describe('ReactIncremental', () => { 'using it should migrate to the new version.\n\n' + 'Please update the following components: Recurse', ], - {withoutStack: true}, + {withoutStack: 1}, ); expect(ops).toEqual([ 'Recurse {}', @@ -2426,7 +2426,6 @@ describe('ReactIncremental', () => { }); expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Error boundaries should implement getDerivedStateFromError()', - {withoutStack: true}, ); }); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js index 65fffe631da6..fde539884c8d 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js @@ -1657,7 +1657,7 @@ describe('ReactIncrementalErrorHandling', () => { 'applications using it should migrate to the new version.\n\n' + 'Please update the following components: Provider', ], - {withoutStack: true}, + {withoutStack: 1}, ); }); }); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.internal.js index 7d199e2522d9..43963c5f9bf4 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.internal.js @@ -388,7 +388,6 @@ describe('ReactIncrementalUpdates', () => { 'from inside an update function. Update functions should be pure, ' + 'with zero side-effects. Consider using componentDidUpdate or a ' + 'callback.', - {withoutStack: true}, ); expect(ops).toEqual([ // Initial render diff --git a/packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js b/packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js index b08aa0762df4..2d7eb4d098d7 100644 --- a/packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js @@ -1481,15 +1481,10 @@ describe('ReactNewContext', () => { } ReactNoop.render(); - expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( - [ - 'Context can only be read while React is rendering', - 'Cannot update during an existing state transition', - ], - { - withoutStack: 1, - }, - ); + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev([ + 'Context can only be read while React is rendering', + 'Cannot update during an existing state transition', + ]); }); }); diff --git a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js index b9110d8cc79a..32f4513ecab4 100644 --- a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js +++ b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js @@ -1320,7 +1320,6 @@ describe('ReactFreshIntegration', () => { }).toWarnDev( 'The component appears to be a function component ' + 'that returns a class instance.', - {withoutStack: true}, ); const el = container.firstChild; expect(el.textContent).toBe('A1'); diff --git a/packages/react-test-renderer/src/ReactTestRendererAct.js b/packages/react-test-renderer/src/ReactTestRendererAct.js index d999c4cccde1..3e097abfc48c 100644 --- a/packages/react-test-renderer/src/ReactTestRendererAct.js +++ b/packages/react-test-renderer/src/ReactTestRendererAct.js @@ -14,7 +14,7 @@ import { IsThisRendererActing, } from 'react-reconciler/inline.test'; import ReactSharedInternals from 'shared/ReactSharedInternals'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import enqueueTask from 'shared/enqueueTask'; import * as Scheduler from 'scheduler'; @@ -83,7 +83,7 @@ function act(callback: () => Thenable) { if (__DEV__) { if (actingUpdatesScopeDepth > previousActingUpdatesScopeDepth) { // if it's _less than_ previousActingUpdatesScopeDepth, then we can assume the 'other' one has warned - warningWithoutStack( + warning( 'You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ', ); @@ -115,7 +115,7 @@ function act(callback: () => Thenable) { .then(() => {}) .then(() => { if (called === false) { - warningWithoutStack( + warning( 'You called act(async () => ...) without await. ' + 'This could lead to unexpected testing behaviour, interleaving multiple act ' + 'calls and mixing their scopes. You should - await act(async () => ...);', @@ -163,7 +163,7 @@ function act(callback: () => Thenable) { } else { if (__DEV__) { if (result !== undefined) { - warningWithoutStack( + warning( 'The callback passed to act(...) function ' + 'must return undefined, or a Promise. You returned %s', result, @@ -191,7 +191,7 @@ function act(callback: () => Thenable) { return { then(resolve: () => void) { if (__DEV__) { - warningWithoutStack( + warning( 'Do not await the result of calling act(...) with sync logic, it is not a Promise.', ); } diff --git a/packages/react/src/ReactBaseClasses.js b/packages/react/src/ReactBaseClasses.js index 8c2410519678..c160e10d2e0a 100644 --- a/packages/react/src/ReactBaseClasses.js +++ b/packages/react/src/ReactBaseClasses.js @@ -6,7 +6,7 @@ */ import invariant from 'shared/invariant'; -import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; +import lowPriorityWarning from 'shared/lowPriorityWarning'; import ReactNoopUpdateQueue from './ReactNoopUpdateQueue'; @@ -105,7 +105,7 @@ if (__DEV__) { const defineDeprecationWarning = function(methodName, info) { Object.defineProperty(Component.prototype, methodName, { get: function() { - lowPriorityWarningWithoutStack( + lowPriorityWarning( '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1], diff --git a/packages/react/src/ReactContext.js b/packages/react/src/ReactContext.js index e59c73e34a48..970a35f7be5f 100644 --- a/packages/react/src/ReactContext.js +++ b/packages/react/src/ReactContext.js @@ -11,7 +11,6 @@ import {REACT_PROVIDER_TYPE, REACT_CONTEXT_TYPE} from 'shared/ReactSymbols'; import type {ReactContext} from 'shared/ReactTypes'; -import warningWithoutStack from 'shared/warningWithoutStack'; import warning from 'shared/warning'; export function createContext( @@ -26,7 +25,7 @@ export function createContext( calculateChangedBits !== null && typeof calculateChangedBits !== 'function' ) { - warningWithoutStack( + warning( 'createContext: Expected the optional second argument to be a ' + 'function. Instead received: %s', calculateChangedBits, diff --git a/packages/react/src/ReactElement.js b/packages/react/src/ReactElement.js index 21fe0f050c26..f23b589dbec1 100644 --- a/packages/react/src/ReactElement.js +++ b/packages/react/src/ReactElement.js @@ -6,7 +6,7 @@ */ import invariant from 'shared/invariant'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols'; import ReactCurrentOwner from './ReactCurrentOwner'; @@ -51,7 +51,7 @@ function defineKeyPropWarningGetter(props, displayName) { if (__DEV__) { if (!specialPropKeyWarningShown) { specialPropKeyWarningShown = true; - warningWithoutStack( + warning( '%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + @@ -73,7 +73,7 @@ function defineRefPropWarningGetter(props, displayName) { if (__DEV__) { if (!specialPropRefWarningShown) { specialPropRefWarningShown = true; - warningWithoutStack( + warning( '%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index f222c55d7275..35fd62f2cf57 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -12,7 +12,7 @@ * that support it. */ -import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; +import lowPriorityWarning from 'shared/lowPriorityWarning'; import isValidElementType from 'shared/isValidElementType'; import getComponentName from 'shared/getComponentName'; import { @@ -24,7 +24,6 @@ import { } from 'shared/ReactSymbols'; import checkPropTypes from 'prop-types/checkPropTypes'; import warning from 'shared/warning'; -import warningWithoutStack from 'shared/warningWithoutStack'; import ReactCurrentOwner from './ReactCurrentOwner'; import { @@ -225,7 +224,7 @@ function validatePropTypes(element) { setCurrentlyValidatingElement(null); } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) { propTypesMisspellWarningShown = true; - warningWithoutStack( + warning( 'Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', name || 'Unknown', ); @@ -234,7 +233,7 @@ function validatePropTypes(element) { typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved ) { - warningWithoutStack( + warning( 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.', ); @@ -484,7 +483,7 @@ export function createFactoryWithValidation(type) { Object.defineProperty(validatedFactory, 'type', { enumerable: false, get: function() { - lowPriorityWarningWithoutStack( + lowPriorityWarning( 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.', ); diff --git a/packages/react/src/ReactNoopUpdateQueue.js b/packages/react/src/ReactNoopUpdateQueue.js index a0ab257dff18..8301c14d4964 100644 --- a/packages/react/src/ReactNoopUpdateQueue.js +++ b/packages/react/src/ReactNoopUpdateQueue.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; const didWarnStateUpdateForUnmountedComponent = {}; @@ -19,7 +19,7 @@ function warnNoop(publicInstance, callerName) { if (didWarnStateUpdateForUnmountedComponent[warningKey]) { return; } - warningWithoutStack( + warning( "Can't call %s on a component that is not yet mounted. " + 'This is a no-op, but it might indicate a bug in your application. ' + 'Instead, assign to `this.state` directly or define a `state = {};` ' + diff --git a/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee b/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee index b7835f834339..1601b20e9a73 100644 --- a/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee +++ b/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee @@ -55,7 +55,7 @@ describe 'ReactCoffeeScriptClass', -> # A failed component renders twice in DEV 'No `render` method found on the returned component instance', 'No `render` method found on the returned component instance', - ], {withoutStack: true}) + ]) undefined it 'renders a simple stateless component with prop', -> @@ -126,7 +126,7 @@ describe 'ReactCoffeeScriptClass', -> {} expect(-> ReactDOM.render(React.createElement(Foo, foo: 'foo'), container) - ).toWarnDev 'Foo: getDerivedStateFromProps() is defined as an instance method and will be ignored. Instead, declare it as a static method.', {withoutStack: true} + ).toWarnDev 'Foo: getDerivedStateFromProps() is defined as an instance method and will be ignored. Instead, declare it as a static method.' undefined it 'warns if getDerivedStateFromError is not static', -> @@ -137,7 +137,7 @@ describe 'ReactCoffeeScriptClass', -> {} expect(-> ReactDOM.render(React.createElement(Foo, foo: 'foo'), container) - ).toWarnDev 'Foo: getDerivedStateFromError() is defined as an instance method and will be ignored. Instead, declare it as a static method.', {withoutStack: true} + ).toWarnDev 'Foo: getDerivedStateFromError() is defined as an instance method and will be ignored. Instead, declare it as a static method.' undefined it 'warns if getSnapshotBeforeUpdate is static', -> @@ -148,7 +148,7 @@ describe 'ReactCoffeeScriptClass', -> {} expect(-> ReactDOM.render(React.createElement(Foo, foo: 'foo'), container) - ).toWarnDev 'Foo: getSnapshotBeforeUpdate() is defined as a static method and will be ignored. Instead, declare it as an instance method.', {withoutStack: true} + ).toWarnDev 'Foo: getSnapshotBeforeUpdate() is defined as a static method and will be ignored. Instead, declare it as an instance method.' undefined it 'warns if state not initialized before static getDerivedStateFromProps', -> @@ -168,7 +168,7 @@ describe 'ReactCoffeeScriptClass', -> 'undefined. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `Foo`. ' + 'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.' - ), {withoutStack: true} + ) undefined it 'updates initial state with values returned by static getDerivedStateFromProps', -> @@ -267,7 +267,7 @@ describe 'ReactCoffeeScriptClass', -> expect(-> test React.createElement(Foo), 'SPAN', '' - ).toWarnDev('Foo.state: must be set to an object or null', {withoutStack: true}) + ).toWarnDev('Foo.state: must be set to an object or null') undefined it 'should render with null in the initial state property', -> @@ -415,7 +415,7 @@ describe 'ReactCoffeeScriptClass', -> 'propTypes was defined as an instance property on Foo.', 'contextTypes was defined as an instance property on Foo.', 'contextType was defined as an instance property on Foo.', - ], {withoutStack: true}) + ]) expect(getInitialStateWasCalled).toBe false expect(getDefaultPropsWasCalled).toBe false undefined @@ -451,8 +451,7 @@ describe 'ReactCoffeeScriptClass', -> ).toWarnDev( 'Warning: NamedComponent has a method called componentShouldUpdate(). Did you mean shouldComponentUpdate()? The name is phrased as a - question because the function is expected to return a value.', - {withoutStack: true} + question because the function is expected to return a value.' ) undefined @@ -469,8 +468,7 @@ describe 'ReactCoffeeScriptClass', -> test React.createElement(NamedComponent), 'SPAN', 'foo' ).toWarnDev( 'Warning: NamedComponent has a method called componentWillRecieveProps(). - Did you mean componentWillReceiveProps()?', - {withoutStack: true} + Did you mean componentWillReceiveProps()?' ) undefined @@ -487,8 +485,7 @@ describe 'ReactCoffeeScriptClass', -> test React.createElement(NamedComponent), 'SPAN', 'foo' ).toWarnDev( 'Warning: NamedComponent has a method called UNSAFE_componentWillRecieveProps(). - Did you mean UNSAFE_componentWillReceiveProps()?', - {withoutStack: true} + Did you mean UNSAFE_componentWillReceiveProps()?' ) undefined diff --git a/packages/react/src/__tests__/ReactContextValidator-test.js b/packages/react/src/__tests__/ReactContextValidator-test.js index bc935753b6e5..3700132e671c 100644 --- a/packages/react/src/__tests__/ReactContextValidator-test.js +++ b/packages/react/src/__tests__/ReactContextValidator-test.js @@ -296,7 +296,6 @@ describe('ReactContextValidator', () => { 'Warning: ComponentA.childContextTypes is specified but there is no ' + 'getChildContext() method on the instance. You can either define ' + 'getChildContext() on ComponentA or remove childContextTypes from it.', - {withoutStack: true}, ); // Warnings should be deduped by component type @@ -306,7 +305,6 @@ describe('ReactContextValidator', () => { 'Warning: ComponentB.childContextTypes is specified but there is no ' + 'getChildContext() method on the instance. You can either define ' + 'getChildContext() on ComponentB or remove childContextTypes from it.', - {withoutStack: true}, ); }); @@ -350,16 +348,13 @@ describe('ReactContextValidator', () => { expect(() => ReactTestUtils.renderIntoDocument(), - ).toWarnDev( - [ - 'Warning: MiddleMissingContext.childContextTypes is specified but there is no ' + - 'getChildContext() method on the instance. You can either define getChildContext() ' + - 'on MiddleMissingContext or remove childContextTypes from it.', - 'Warning: Failed context type: The context `bar` is marked as required ' + - 'in `ChildContextConsumer`, but its value is `undefined`.', - ], - {withoutStack: 1}, - ); + ).toWarnDev([ + 'Warning: MiddleMissingContext.childContextTypes is specified but there is no ' + + 'getChildContext() method on the instance. You can either define getChildContext() ' + + 'on MiddleMissingContext or remove childContextTypes from it.', + 'Warning: Failed context type: The context `bar` is marked as required ' + + 'in `ChildContextConsumer`, but its value is `undefined`.', + ]); expect(childContext.bar).toBeUndefined(); expect(childContext.foo).toBe('FOO'); }); @@ -516,7 +511,6 @@ describe('ReactContextValidator', () => { ).toWarnDev( 'Warning: ComponentA declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', - {withoutStack: true}, ); // Warnings should be deduped by component type @@ -535,7 +529,6 @@ describe('ReactContextValidator', () => { ).toWarnDev( 'Warning: ComponentB declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', - {withoutStack: true}, ); }); @@ -562,7 +555,6 @@ describe('ReactContextValidator', () => { 'Warning: ComponentA defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext(). ' + 'Did you accidentally pass the Context.Consumer instead?', - {withoutStack: true}, ); // Warnings should be deduped by component type @@ -574,7 +566,6 @@ describe('ReactContextValidator', () => { 'Warning: ComponentB defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext(). ' + 'Did you accidentally pass the Context.Provider instead?', - {withoutStack: true}, ); }); @@ -611,7 +602,6 @@ describe('ReactContextValidator', () => { 'This can be caused by a typo or by mixing up named and default imports. ' + 'This can also happen due to a circular dependency, ' + 'so try moving the createContext() call to a separate file.', - {withoutStack: true}, ); }); @@ -635,7 +625,6 @@ describe('ReactContextValidator', () => { 'Foo defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext(). ' + 'However, it is set to an object with keys {x, y}.', - {withoutStack: true}, ); }); @@ -655,7 +644,6 @@ describe('ReactContextValidator', () => { 'Foo defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext(). ' + 'However, it is set to a string.', - {withoutStack: true}, ); }); @@ -674,7 +662,6 @@ describe('ReactContextValidator', () => { expect(() => ReactTestUtils.renderIntoDocument()).toWarnDev( 'Warning: ComponentA: Function components do not support contextType.', - {withoutStack: true}, ); // Warnings should be deduped by component type @@ -682,7 +669,6 @@ describe('ReactContextValidator', () => { expect(() => ReactTestUtils.renderIntoDocument()).toWarnDev( 'Warning: ComponentB: Function components do not support contextType.', - {withoutStack: true}, ); }); }); diff --git a/packages/react/src/__tests__/ReactES6Class-test.js b/packages/react/src/__tests__/ReactES6Class-test.js index bc4d33d24417..74f7ee48fc33 100644 --- a/packages/react/src/__tests__/ReactES6Class-test.js +++ b/packages/react/src/__tests__/ReactES6Class-test.js @@ -59,16 +59,13 @@ describe('ReactES6Class', () => { class Foo extends React.Component {} expect(() => expect(() => ReactDOM.render(, container)).toThrow(), - ).toWarnDev( - [ - // A failed component renders twice in DEV - 'Warning: Foo(...): No `render` method found on the returned component ' + - 'instance: you may have forgotten to define `render`.', - 'Warning: Foo(...): No `render` method found on the returned component ' + - 'instance: you may have forgotten to define `render`.', - ], - {withoutStack: true}, - ); + ).toWarnDev([ + // A failed component renders twice in DEV + 'Warning: Foo(...): No `render` method found on the returned component ' + + 'instance: you may have forgotten to define `render`.', + 'Warning: Foo(...): No `render` method found on the returned component ' + + 'instance: you may have forgotten to define `render`.', + ]); }); it('renders a simple stateless component with prop', () => { @@ -143,7 +140,6 @@ describe('ReactES6Class', () => { expect(() => ReactDOM.render(, container)).toWarnDev( 'Foo: getDerivedStateFromProps() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', - {withoutStack: true}, ); }); @@ -159,7 +155,6 @@ describe('ReactES6Class', () => { expect(() => ReactDOM.render(, container)).toWarnDev( 'Foo: getDerivedStateFromError() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', - {withoutStack: true}, ); }); @@ -173,7 +168,6 @@ describe('ReactES6Class', () => { expect(() => ReactDOM.render(, container)).toWarnDev( 'Foo: getSnapshotBeforeUpdate() is defined as a static method ' + 'and will be ignored. Instead, declare it as an instance method.', - {withoutStack: true}, ); }); @@ -194,7 +188,6 @@ describe('ReactES6Class', () => { 'undefined. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `Foo`. ' + 'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.', - {withoutStack: true}, ); }); @@ -300,7 +293,6 @@ describe('ReactES6Class', () => { } expect(() => test(, 'SPAN', '')).toWarnDev( 'Foo.state: must be set to an object or null', - {withoutStack: true}, ); }); }); @@ -451,16 +443,13 @@ describe('ReactES6Class', () => { } } - expect(() => test(, 'SPAN', 'foo')).toWarnDev( - [ - 'getInitialState was defined on Foo, a plain JavaScript class.', - 'getDefaultProps was defined on Foo, a plain JavaScript class.', - 'propTypes was defined as an instance property on Foo.', - 'contextType was defined as an instance property on Foo.', - 'contextTypes was defined as an instance property on Foo.', - ], - {withoutStack: true}, - ); + expect(() => test(, 'SPAN', 'foo')).toWarnDev([ + 'getInitialState was defined on Foo, a plain JavaScript class.', + 'getDefaultProps was defined on Foo, a plain JavaScript class.', + 'propTypes was defined as an instance property on Foo.', + 'contextType was defined as an instance property on Foo.', + 'contextTypes was defined as an instance property on Foo.', + ]); expect(getInitialStateWasCalled).toBe(false); expect(getDefaultPropsWasCalled).toBe(false); }); @@ -493,7 +482,6 @@ describe('ReactES6Class', () => { 'NamedComponent has a method called componentShouldUpdate(). Did you ' + 'mean shouldComponentUpdate()? The name is phrased as a question ' + 'because the function is expected to return a value.', - {withoutStack: true}, ); }); @@ -511,7 +499,6 @@ describe('ReactES6Class', () => { 'Warning: ' + 'NamedComponent has a method called componentWillRecieveProps(). Did ' + 'you mean componentWillReceiveProps()?', - {withoutStack: true}, ); }); @@ -529,7 +516,6 @@ describe('ReactES6Class', () => { 'Warning: ' + 'NamedComponent has a method called UNSAFE_componentWillRecieveProps(). ' + 'Did you mean UNSAFE_componentWillReceiveProps()?', - {withoutStack: true}, ); }); diff --git a/packages/react/src/__tests__/ReactElement-test.js b/packages/react/src/__tests__/ReactElement-test.js index a495c8bbd5ee..f339c38b781d 100644 --- a/packages/react/src/__tests__/ReactElement-test.js +++ b/packages/react/src/__tests__/ReactElement-test.js @@ -80,7 +80,6 @@ describe('ReactElement', () => { 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', - {withoutStack: true}, ); }); @@ -116,7 +115,6 @@ describe('ReactElement', () => { 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', - {withoutStack: true}, ); }); diff --git a/packages/react/src/__tests__/ReactElementJSX-test.internal.js b/packages/react/src/__tests__/ReactElementJSX-test.internal.js index 23135d15de8e..aadbb69c4638 100644 --- a/packages/react/src/__tests__/ReactElementJSX-test.internal.js +++ b/packages/react/src/__tests__/ReactElementJSX-test.internal.js @@ -211,7 +211,6 @@ describe('ReactElement.jsx', () => { 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', - {withoutStack: true}, ); }); @@ -257,7 +256,6 @@ describe('ReactElement.jsx', () => { 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', - {withoutStack: true}, ); }); diff --git a/packages/react/src/__tests__/ReactPureComponent-test.js b/packages/react/src/__tests__/ReactPureComponent-test.js index 144e7e279317..d61779783af1 100644 --- a/packages/react/src/__tests__/ReactPureComponent-test.js +++ b/packages/react/src/__tests__/ReactPureComponent-test.js @@ -79,7 +79,6 @@ describe('ReactPureComponent', () => { 'Component has a method called shouldComponentUpdate(). ' + 'shouldComponentUpdate should not be used when extending React.PureComponent. ' + 'Please extend React.Component if shouldComponentUpdate is used.', - {withoutStack: true}, ); ReactDOM.render(, container); expect(renders).toBe(2); @@ -114,7 +113,6 @@ describe('ReactPureComponent', () => { 'PureComponent has a method called shouldComponentUpdate(). ' + 'shouldComponentUpdate should not be used when extending React.PureComponent. ' + 'Please extend React.Component if shouldComponentUpdate is used.', - {withoutStack: true}, ); }); }); diff --git a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts index e79ab7f49675..6cbcc046d387 100644 --- a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts +++ b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts @@ -332,7 +332,7 @@ describe('ReactTypeScriptClass', function() { 'component instance: you may have forgotten to define `render`.', 'Warning: Empty(...): No `render` method found on the returned ' + 'component instance: you may have forgotten to define `render`.', - ], {withoutStack: true}); + ]); }); it('renders a simple stateless component with prop', function() { @@ -392,8 +392,7 @@ describe('ReactTypeScriptClass', function() { ReactDOM.render(React.createElement(Foo, {foo: 'foo'}), container); }).toWarnDev( 'Foo: getDerivedStateFromProps() is defined as an instance method ' + - 'and will be ignored. Instead, declare it as a static method.', - {withoutStack: true} + 'and will be ignored. Instead, declare it as a static method.' ); }); @@ -410,8 +409,7 @@ describe('ReactTypeScriptClass', function() { ReactDOM.render(React.createElement(Foo, {foo: 'foo'}), container); }).toWarnDev( 'Foo: getDerivedStateFromError() is defined as an instance method ' + - 'and will be ignored. Instead, declare it as a static method.', - {withoutStack: true} + 'and will be ignored. Instead, declare it as a static method.' ); }); @@ -427,8 +425,7 @@ describe('ReactTypeScriptClass', function() { ReactDOM.render(React.createElement(Foo, {foo: 'foo'}), container); }).toWarnDev( 'Foo: getSnapshotBeforeUpdate() is defined as a static method ' + - 'and will be ignored. Instead, declare it as an instance method.', - {withoutStack: true} + 'and will be ignored. Instead, declare it as an instance method.' ); }); @@ -452,8 +449,7 @@ describe('ReactTypeScriptClass', function() { '`Foo` uses `getDerivedStateFromProps` but its initial state is ' + 'undefined. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `Foo`. ' + - 'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.', - {withoutStack: true} + 'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.' ); }); @@ -510,16 +506,13 @@ describe('ReactTypeScriptClass', function() { it('should warn with non-object in the initial state property', function() { expect(() => test(React.createElement(ArrayState), 'SPAN', '')).toWarnDev( - 'ArrayState.state: must be set to an object or null', - {withoutStack: true} + 'ArrayState.state: must be set to an object or null' ); expect(() => test(React.createElement(StringState), 'SPAN', '')).toWarnDev( - 'StringState.state: must be set to an object or null', - {withoutStack: true} + 'StringState.state: must be set to an object or null' ); expect(() => test(React.createElement(NumberState), 'SPAN', '')).toWarnDev( - 'NumberState.state: must be set to an object or null', - {withoutStack: true} + 'NumberState.state: must be set to an object or null' ); }); @@ -596,7 +589,7 @@ describe('ReactTypeScriptClass', function() { 'propTypes was defined as an instance property on ClassicProperties.', 'contextTypes was defined as an instance property on ClassicProperties.', 'contextType was defined as an instance property on ClassicProperties.', - ], {withoutStack: true}); + ]); expect(getInitialStateWasCalled).toBe(false); expect(getDefaultPropsWasCalled).toBe(false); } @@ -627,8 +620,7 @@ describe('ReactTypeScriptClass', function() { 'Warning: ' + 'MisspelledComponent1 has a method called componentShouldUpdate(). Did ' + 'you mean shouldComponentUpdate()? The name is phrased as a question ' + - 'because the function is expected to return a value.', - {withoutStack: true} + 'because the function is expected to return a value.' ); }); @@ -638,8 +630,7 @@ describe('ReactTypeScriptClass', function() { ).toWarnDev( 'Warning: ' + 'MisspelledComponent2 has a method called componentWillRecieveProps(). ' + - 'Did you mean componentWillReceiveProps()?', - {withoutStack: true} + 'Did you mean componentWillReceiveProps()?' ); }); @@ -649,8 +640,7 @@ describe('ReactTypeScriptClass', function() { ).toWarnDev( 'Warning: ' + 'MisspelledComponent3 has a method called UNSAFE_componentWillRecieveProps(). ' + - 'Did you mean UNSAFE_componentWillReceiveProps()?', - {withoutStack: true} + 'Did you mean UNSAFE_componentWillReceiveProps()?' ); }); diff --git a/packages/react/src/__tests__/createReactClassIntegration-test.js b/packages/react/src/__tests__/createReactClassIntegration-test.js index f0647f479ef5..9613f3e08969 100644 --- a/packages/react/src/__tests__/createReactClassIntegration-test.js +++ b/packages/react/src/__tests__/createReactClassIntegration-test.js @@ -456,7 +456,6 @@ describe('create-react-class-integration', () => { ).toWarnDev( 'Foo: getDerivedStateFromProps() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', - {withoutStack: true}, ); }); @@ -475,7 +474,6 @@ describe('create-react-class-integration', () => { ).toWarnDev( 'Foo: getDerivedStateFromError() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', - {withoutStack: true}, ); }); @@ -496,7 +494,6 @@ describe('create-react-class-integration', () => { ).toWarnDev( 'Foo: getSnapshotBeforeUpdate() is defined as a static method ' + 'and will be ignored. Instead, declare it as an instance method.', - {withoutStack: true}, ); }); @@ -519,9 +516,6 @@ describe('create-react-class-integration', () => { 'null. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `Component`. ' + 'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.', - { - withoutStack: true, - }, ); }); @@ -560,7 +554,6 @@ describe('create-react-class-integration', () => { ' componentWillUpdate\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); }).toLowPriorityWarnDev( [ @@ -604,7 +597,6 @@ describe('create-react-class-integration', () => { ' componentWillUpdate\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-unsafe-component-lifecycles', - {withoutStack: true}, ); }).toLowPriorityWarnDev( [ diff --git a/packages/react/src/forwardRef.js b/packages/react/src/forwardRef.js index bd5ca418f4df..7fefbc06e366 100644 --- a/packages/react/src/forwardRef.js +++ b/packages/react/src/forwardRef.js @@ -7,26 +7,26 @@ import {REACT_FORWARD_REF_TYPE, REACT_MEMO_TYPE} from 'shared/ReactSymbols'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; export default function forwardRef( render: (props: Props, ref: React$Ref) => React$Node, ) { if (__DEV__) { if (render != null && render.$$typeof === REACT_MEMO_TYPE) { - warningWithoutStack( + warning( 'forwardRef requires a render function but received a `memo` ' + 'component. Instead of forwardRef(memo(...)), use ' + 'memo(forwardRef(...)).', ); } else if (typeof render !== 'function') { - warningWithoutStack( + warning( 'forwardRef requires a render function but was given %s.', render === null ? 'null' : typeof render, ); } else { if (render.length !== 0 && render.length !== 2) { - warningWithoutStack( + warning( 'forwardRef render functions accept exactly two parameters: props and ref. %s', render.length === 1 ? 'Did you forget to use the ref parameter?' @@ -37,7 +37,7 @@ export default function forwardRef( if (render != null) { if (render.defaultProps != null || render.propTypes != null) { - warningWithoutStack( + warning( 'forwardRef render functions do not support propTypes or defaultProps. ' + 'Did you accidentally pass a React component?', ); diff --git a/packages/react/src/memo.js b/packages/react/src/memo.js index a11831073a46..b1c203f074db 100644 --- a/packages/react/src/memo.js +++ b/packages/react/src/memo.js @@ -8,7 +8,7 @@ import {REACT_MEMO_TYPE} from 'shared/ReactSymbols'; import isValidElementType from 'shared/isValidElementType'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; export default function memo( type: React$ElementType, @@ -16,7 +16,7 @@ export default function memo( ) { if (__DEV__) { if (!isValidElementType(type)) { - warningWithoutStack( + warning( 'memo: The first argument must be a component. Instead ' + 'received: %s', type === null ? 'null' : typeof type, diff --git a/packages/shared/enqueueTask.js b/packages/shared/enqueueTask.js index be01d62d9641..ec2e53d0ae8c 100644 --- a/packages/shared/enqueueTask.js +++ b/packages/shared/enqueueTask.js @@ -7,7 +7,7 @@ * @flow */ -import warningWithoutStack from './warningWithoutStack'; +import warningWithoutStack from 'shared/warningWithoutStack'; let didWarnAboutMessageChannel = false; let enqueueTask; diff --git a/packages/shared/getComponentName.js b/packages/shared/getComponentName.js index d73f4ce2ce47..c11a356a27a1 100644 --- a/packages/shared/getComponentName.js +++ b/packages/shared/getComponentName.js @@ -9,7 +9,7 @@ import type {LazyComponent} from 'shared/ReactLazyComponent'; -import warningWithoutStack from 'shared/warningWithoutStack'; +import warning from 'shared/warning'; import { REACT_CONTEXT_TYPE, REACT_FORWARD_REF_TYPE, @@ -44,7 +44,7 @@ function getComponentName(type: mixed): string | null { } if (__DEV__) { if (typeof (type: any).tag === 'number') { - warningWithoutStack( + warning( 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.', ); diff --git a/packages/shared/lowPriorityWarning.js b/packages/shared/lowPriorityWarning.js index 97cbf1312f2e..6c81a82a3914 100644 --- a/packages/shared/lowPriorityWarning.js +++ b/packages/shared/lowPriorityWarning.js @@ -19,10 +19,24 @@ let lowPriorityWarning = lowPriorityWarningWithoutStack; if (__DEV__) { lowPriorityWarning = function(format, ...args) { - const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; - const stack = ReactDebugCurrentFrame.getStackAddendum(); + let finalFormat = format; + let finalArgs = args; + + const hasExistingStack = + args.length > 0 && + typeof args[args.length - 1] === 'string' && + args[args.length - 1].indexOf('\n in') === 0; + + if (!hasExistingStack) { + const ReactDebugCurrentFrame = + ReactSharedInternals.ReactDebugCurrentFrame; + const stack = ReactDebugCurrentFrame.getStackAddendum(); + finalFormat += '%s'; + finalArgs.push(stack); + } + // eslint-disable-next-line react-internal/warning-args - lowPriorityWarningWithoutStack(format + '%s', ...args, stack); + lowPriorityWarningWithoutStack(finalFormat, ...finalArgs); }; } diff --git a/packages/shared/warning.js b/packages/shared/warning.js index 4cde29cd3af4..189b651e5e65 100644 --- a/packages/shared/warning.js +++ b/packages/shared/warning.js @@ -19,10 +19,24 @@ let warning = warningWithoutStack; if (__DEV__) { warning = function(format, ...args) { - const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; - const stack = ReactDebugCurrentFrame.getStackAddendum(); + let finalFormat = format; + let finalArgs = args; + + const hasExistingStack = + args.length > 0 && + typeof args[args.length - 1] === 'string' && + args[args.length - 1].indexOf('\n in') === 0; + + if (!hasExistingStack) { + const ReactDebugCurrentFrame = + ReactSharedInternals.ReactDebugCurrentFrame; + const stack = ReactDebugCurrentFrame.getStackAddendum(); + finalFormat += '%s'; + finalArgs.push(stack); + } + // eslint-disable-next-line react-internal/warning-args - warningWithoutStack(format + '%s', ...args, stack); + warningWithoutStack(finalFormat, ...finalArgs); }; }