Skip to content

Commit 1569cad

Browse files
committed
Add component stacks to (almost) all warnings
1 parent 12c0004 commit 1569cad

File tree

83 files changed

+349
-513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+349
-513
lines changed

packages/create-subscription/src/createSubscription.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import React from 'react';
1111
import invariant from 'shared/invariant';
12-
import warningWithoutStack from 'shared/warningWithoutStack';
12+
import warning from 'shared/warning';
1313

1414
type Unsubscribe = () => void;
1515

@@ -38,12 +38,10 @@ export function createSubscription<Property, Value>(
3838

3939
if (__DEV__) {
4040
if (typeof getCurrentValue !== 'function') {
41-
warningWithoutStack(
42-
'Subscription must specify a getCurrentValue function',
43-
);
41+
warning('Subscription must specify a getCurrentValue function');
4442
}
4543
if (typeof subscribe !== 'function') {
46-
warningWithoutStack('Subscription must specify a subscribe function');
44+
warning('Subscription must specify a subscribe function');
4745
}
4846
}
4947

packages/legacy-events/EventPluginUtils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import {invokeGuardedCallbackAndCatchFirstError} from 'shared/ReactErrorUtils';
99
import invariant from 'shared/invariant';
10-
import warningWithoutStack from 'shared/warningWithoutStack';
10+
import warning from 'shared/warning';
1111

1212
export let getFiberCurrentPropsFromNode = null;
1313
export let getInstanceFromNode = null;
@@ -23,7 +23,7 @@ export function setComponentTree(
2323
getNodeFromInstance = getNodeFromInstanceImpl;
2424
if (__DEV__) {
2525
if (!getNodeFromInstance || !getInstanceFromNode) {
26-
warningWithoutStack(
26+
warning(
2727
'EventPluginUtils.setComponentTree(...): Injected ' +
2828
'module is missing getNodeFromInstance or getInstanceFromNode.',
2929
);
@@ -52,7 +52,7 @@ if (__DEV__) {
5252
: 0;
5353

5454
if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) {
55-
warningWithoutStack('EventPluginUtils: Invalid `event`.');
55+
warning('EventPluginUtils: Invalid `event`.');
5656
}
5757
};
5858
}

packages/legacy-events/EventPropagators.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
traverseTwoPhase,
1111
traverseEnterLeave,
1212
} from 'shared/ReactTreeTraversal';
13-
import warningWithoutStack from 'shared/warningWithoutStack';
13+
import warning from 'shared/warning';
1414

1515
import {getListener} from './EventPluginHub';
1616
import accumulateInto from './accumulateInto';
@@ -47,7 +47,7 @@ function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
4747
function accumulateDirectionalDispatches(inst, phase, event) {
4848
if (__DEV__) {
4949
if (!inst) {
50-
warningWithoutStack('Dispatching inst must not be null');
50+
warning('Dispatching inst must not be null');
5151
}
5252
}
5353
const listener = listenerAtPhase(inst, event, phase);

packages/legacy-events/ResponderTouchHistoryStore.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import invariant from 'shared/invariant';
11-
import warningWithoutStack from 'shared/warningWithoutStack';
11+
import warning from 'shared/warning';
1212

1313
import {isStartish, isMoveish, isEndish} from './ResponderTopLevelEventTypes';
1414

@@ -96,7 +96,7 @@ function getTouchIdentifier({identifier}: Touch): number {
9696
invariant(identifier != null, 'Touch object is missing identifier.');
9797
if (__DEV__) {
9898
if (identifier > MAX_TOUCH_BANK) {
99-
warningWithoutStack(
99+
warning(
100100
'Touch identifier %s is greater than maximum supported %s which causes ' +
101101
'performance issues backfilling array locations for all of the indices.',
102102
identifier,
@@ -202,7 +202,7 @@ const ResponderTouchHistoryStore = {
202202
if (__DEV__) {
203203
const activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
204204
if (activeRecord == null || !activeRecord.touchActive) {
205-
warningWithoutStack('Cannot find single active touch.');
205+
warning('Cannot find single active touch.');
206206
}
207207
}
208208
}

packages/legacy-events/SyntheticEvent.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/* eslint valid-typeof: 0 */
99

1010
import invariant from 'shared/invariant';
11-
import warningWithoutStack from 'shared/warningWithoutStack';
11+
import warning from 'shared/warning';
1212

1313
const EVENT_POOL_SIZE = 10;
1414

@@ -284,7 +284,7 @@ function getPooledWarningPropertyDefinition(propName, getVal) {
284284

285285
function warn(action, result) {
286286
if (__DEV__) {
287-
warningWithoutStack(
287+
warning(
288288
"This synthetic event is reused for performance reasons. If you're seeing this, " +
289289
"you're %s `%s` on a released/nullified synthetic event. %s. " +
290290
'If you must keep the original synthetic event around, use event.persist(). ' +

packages/react-cache/src/ReactCache.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import React from 'react';
11-
import warningWithoutStack from 'shared/warningWithoutStack';
11+
import warning from 'shared/warning';
1212

1313
import {createLRU} from './LRU';
1414

@@ -71,7 +71,7 @@ function identityHashFn(input) {
7171
input !== undefined &&
7272
input !== null
7373
) {
74-
warningWithoutStack(
74+
warning(
7575
'Invalid key type. Expected a string, number, symbol, or boolean, ' +
7676
'but instead received: %s' +
7777
'\n\nTo use non-primitive values as keys, you must pass a hash ' +

packages/react-cache/src/__tests__/ReactCache-test.internal.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,12 @@ describe('ReactCache', () => {
172172
if (__DEV__) {
173173
expect(() => {
174174
expect(Scheduler).toFlushAndYield(['App', 'Loading...']);
175-
}).toWarnDev(
176-
[
177-
'Invalid key type. Expected a string, number, symbol, or ' +
178-
'boolean, but instead received: Hi,100\n\n' +
179-
'To use non-primitive values as keys, you must pass a hash ' +
180-
'function as the second argument to createResource().',
181-
],
182-
{withoutStack: true},
183-
);
175+
}).toWarnDev([
176+
'Invalid key type. Expected a string, number, symbol, or ' +
177+
'boolean, but instead received: Hi,100\n\n' +
178+
'To use non-primitive values as keys, you must pass a hash ' +
179+
'function as the second argument to createResource().',
180+
]);
184181
} else {
185182
expect(Scheduler).toFlushAndYield(['App', 'Loading...']);
186183
}

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

+3-28
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ describe('ReactComponentLifeCycle', () => {
215215
'StatefulComponent: It is not recommended to assign props directly to state ' +
216216
"because updates to props won't be reflected in state. " +
217217
'In most cases, it is better to use props directly.',
218-
{withoutStack: true},
219218
);
220219
});
221220

@@ -240,7 +239,6 @@ describe('ReactComponentLifeCycle', () => {
240239
'This is a no-op, but it might indicate a bug in your application. ' +
241240
'Instead, assign to `this.state` directly or define a `state = {};` ' +
242241
'class property with the desired state in the StatefulComponent component.',
243-
{withoutStack: true},
244242
);
245243

246244
// Check deduplication; (no extra warnings should be logged).
@@ -271,9 +269,7 @@ describe('ReactComponentLifeCycle', () => {
271269
expect(() => {
272270
const instance = ReactTestUtils.renderIntoDocument(element);
273271
expect(instance._isMounted()).toBeTruthy();
274-
}).toWarnDev('Component is accessing isMounted inside its render()', {
275-
withoutStack: true,
276-
});
272+
}).toWarnDev('Component is accessing isMounted inside its render()');
277273
});
278274

279275
it('should correctly determine if a null component is mounted', () => {
@@ -300,9 +296,7 @@ describe('ReactComponentLifeCycle', () => {
300296
expect(() => {
301297
const instance = ReactTestUtils.renderIntoDocument(element);
302298
expect(instance._isMounted()).toBeTruthy();
303-
}).toWarnDev('Component is accessing isMounted inside its render()', {
304-
withoutStack: true,
305-
});
299+
}).toWarnDev('Component is accessing isMounted inside its render()');
306300
});
307301

308302
it('isMounted should return false when unmounted', () => {
@@ -340,9 +334,7 @@ describe('ReactComponentLifeCycle', () => {
340334

341335
expect(() => {
342336
ReactTestUtils.renderIntoDocument(<Component />);
343-
}).toWarnDev('Component is accessing findDOMNode inside its render()', {
344-
withoutStack: true,
345-
});
337+
}).toWarnDev('Component is accessing findDOMNode inside its render()');
346338
});
347339

348340
it('should carry through each of the phases of setup', () => {
@@ -408,7 +400,6 @@ describe('ReactComponentLifeCycle', () => {
408400
instance = ReactDOM.render(<LifeCycleComponent />, container);
409401
}).toWarnDev(
410402
'LifeCycleComponent is accessing isMounted inside its render() function',
411-
{withoutStack: true},
412403
);
413404

414405
// getInitialState
@@ -705,7 +696,6 @@ describe('ReactComponentLifeCycle', () => {
705696
expect(() => {
706697
expect(() => ReactDOM.render(<Component />, container)).toWarnDev(
707698
'Unsafe legacy lifecycles will not be called for components using new component APIs.',
708-
{withoutStack: true},
709699
);
710700
}).toLowPriorityWarnDev(
711701
[
@@ -744,7 +734,6 @@ describe('ReactComponentLifeCycle', () => {
744734
ReactDOM.render(<Component value={1} />, container),
745735
).toWarnDev(
746736
'Unsafe legacy lifecycles will not be called for components using new component APIs.',
747-
{withoutStack: true},
748737
);
749738
}).toLowPriorityWarnDev(
750739
[
@@ -780,7 +769,6 @@ describe('ReactComponentLifeCycle', () => {
780769
const container = document.createElement('div');
781770
expect(() => ReactDOM.render(<Component value={1} />, container)).toWarnDev(
782771
'Unsafe legacy lifecycles will not be called for components using new component APIs.',
783-
{withoutStack: true},
784772
);
785773
ReactDOM.render(<Component value={2} />, container);
786774
});
@@ -812,7 +800,6 @@ describe('ReactComponentLifeCycle', () => {
812800
' componentWillUpdate\n\n' +
813801
'The above lifecycles should be removed. Learn more about this warning here:\n' +
814802
'https://fb.me/react-unsafe-component-lifecycles',
815-
{withoutStack: true},
816803
);
817804
}).toLowPriorityWarnDev(
818805
[
@@ -839,7 +826,6 @@ describe('ReactComponentLifeCycle', () => {
839826
' UNSAFE_componentWillMount\n\n' +
840827
'The above lifecycles should be removed. Learn more about this warning here:\n' +
841828
'https://fb.me/react-unsafe-component-lifecycles',
842-
{withoutStack: true},
843829
);
844830

845831
class WillMountAndUpdate extends React.Component {
@@ -864,7 +850,6 @@ describe('ReactComponentLifeCycle', () => {
864850
' UNSAFE_componentWillUpdate\n\n' +
865851
'The above lifecycles should be removed. Learn more about this warning here:\n' +
866852
'https://fb.me/react-unsafe-component-lifecycles',
867-
{withoutStack: true},
868853
);
869854
}).toLowPriorityWarnDev(['componentWillMount has been renamed'], {
870855
withoutStack: true,
@@ -888,7 +873,6 @@ describe('ReactComponentLifeCycle', () => {
888873
' componentWillReceiveProps\n\n' +
889874
'The above lifecycles should be removed. Learn more about this warning here:\n' +
890875
'https://fb.me/react-unsafe-component-lifecycles',
891-
{withoutStack: true},
892876
);
893877
}).toLowPriorityWarnDev(['componentWillReceiveProps has been renamed'], {
894878
withoutStack: true,
@@ -921,7 +905,6 @@ describe('ReactComponentLifeCycle', () => {
921905
' componentWillUpdate\n\n' +
922906
'The above lifecycles should be removed. Learn more about this warning here:\n' +
923907
'https://fb.me/react-unsafe-component-lifecycles',
924-
{withoutStack: true},
925908
);
926909
}).toLowPriorityWarnDev(
927910
[
@@ -947,7 +930,6 @@ describe('ReactComponentLifeCycle', () => {
947930
' UNSAFE_componentWillMount\n\n' +
948931
'The above lifecycles should be removed. Learn more about this warning here:\n' +
949932
'https://fb.me/react-unsafe-component-lifecycles',
950-
{withoutStack: true},
951933
);
952934

953935
class WillMountAndUpdate extends React.Component {
@@ -971,7 +953,6 @@ describe('ReactComponentLifeCycle', () => {
971953
' UNSAFE_componentWillUpdate\n\n' +
972954
'The above lifecycles should be removed. Learn more about this warning here:\n' +
973955
'https://fb.me/react-unsafe-component-lifecycles',
974-
{withoutStack: true},
975956
);
976957
}).toLowPriorityWarnDev(['componentWillMount has been renamed'], {
977958
withoutStack: true,
@@ -994,7 +975,6 @@ describe('ReactComponentLifeCycle', () => {
994975
' componentWillReceiveProps\n\n' +
995976
'The above lifecycles should be removed. Learn more about this warning here:\n' +
996977
'https://fb.me/react-unsafe-component-lifecycles',
997-
{withoutStack: true},
998978
);
999979
}).toLowPriorityWarnDev(['componentWillReceiveProps has been renamed'], {
1000980
withoutStack: true,
@@ -1045,7 +1025,6 @@ describe('ReactComponentLifeCycle', () => {
10451025
"If you can't use a class try assigning the prototype on the function as a workaround. " +
10461026
'`Parent.prototype = React.Component.prototype`. ' +
10471027
"Don't use an arrow function since it cannot be called with `new` by React.",
1048-
{withoutStack: true},
10491028
);
10501029
ReactDOM.render(<Parent ref={c => c && log.push('ref')} />, div);
10511030

@@ -1074,7 +1053,6 @@ describe('ReactComponentLifeCycle', () => {
10741053
expect(() => ReactDOM.render(<MyComponent />, div)).toWarnDev(
10751054
'MyComponent.getDerivedStateFromProps(): A valid state object (or null) must ' +
10761055
'be returned. You have returned undefined.',
1077-
{withoutStack: true},
10781056
);
10791057

10801058
// De-duped
@@ -1097,7 +1075,6 @@ describe('ReactComponentLifeCycle', () => {
10971075
'undefined. This is not recommended. Instead, define the initial state by ' +
10981076
'assigning an object to `this.state` in the constructor of `MyComponent`. ' +
10991077
'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.',
1100-
{withoutStack: true},
11011078
);
11021079

11031080
// De-duped
@@ -1366,7 +1343,6 @@ describe('ReactComponentLifeCycle', () => {
13661343
expect(() => ReactDOM.render(<MyComponent value="bar" />, div)).toWarnDev(
13671344
'MyComponent.getSnapshotBeforeUpdate(): A snapshot value (or null) must ' +
13681345
'be returned. You have returned undefined.',
1369-
{withoutStack: true},
13701346
);
13711347

13721348
// De-duped
@@ -1387,7 +1363,6 @@ describe('ReactComponentLifeCycle', () => {
13871363
expect(() => ReactDOM.render(<MyComponent />, div)).toWarnDev(
13881364
'MyComponent: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' +
13891365
'This component defines getSnapshotBeforeUpdate() only.',
1390-
{withoutStack: true},
13911366
);
13921367

13931368
// De-duped

0 commit comments

Comments
 (0)