Make Stack error message more generic, too
We want to avoid passing around caller names because stripping them out in production complicates the code for little benefit.
Andrew Clark committed
Feb 8, 2017 at 11:43 UTC
5b181a696e8625f35d6c39502118d7d644a6aa8c
2 files changed
+25
-49
src/renderers/__tests__/ReactCompositeComponent-test.js
+13
-22
@@ -278,14 +278,10 @@ describe('ReactCompositeComponent', () => {
278
instance.forceUpdate();
279
expectDev(console.error.calls.count()).toBe(1);
280
expectDev(console.error.calls.argsFor(0)[0]).toContain(
281
- ReactDOMFeatureFlags.useFiber ?
282
- 'Can only update a mounted or mounting component. This usually means ' +
283
- 'you called setState, replaceState, or forceUpdate on an unmounted ' +
284
- 'component. This is a no-op.\n\nPlease check the code for the ' +
285
- 'Component component.' :
286
- 'Can only update a mounted or mounting component. This usually means ' +
287
- 'you called forceUpdate() on an unmounted component. This is a no-op.' +
288
- '\n\nPlease check the code for the Component component.'
281
+ 'Can only update a mounted or mounting component. This usually means ' +
282
+ 'you called setState, replaceState, or forceUpdate on an unmounted ' +
283
+ 'component. This is a no-op.\n\nPlease check the code for the ' +
284
+ 'Component component.'
285
);
286
});
287
@@ -326,14 +322,10 @@ describe('ReactCompositeComponent', () => {
322
323
expectDev(console.error.calls.count()).toBe(1);
324
expectDev(console.error.calls.argsFor(0)[0]).toContain(
329
- ReactDOMFeatureFlags.useFiber ?
330
- 'Can only update a mounted or mounting component. This usually means ' +
331
- 'you called setState, replaceState, or forceUpdate on an unmounted ' +
332
- 'component. This is a no-op.\n\nPlease check the code for the ' +
333
- 'Component component.' :
334
- 'Can only update a mounted or mounting component. This usually means ' +
335
- 'you called setState() on an unmounted component. This is a no-op.' +
336
- '\n\nPlease check the code for the Component component.'
325
+ 'Can only update a mounted or mounting component. This usually means ' +
326
+ 'you called setState, replaceState, or forceUpdate on an unmounted ' +
327
+ 'component. This is a no-op.\n\nPlease check the code for the ' +
328
+ 'Component component.'
329
);
330
});
331
@@ -392,12 +384,11 @@ describe('ReactCompositeComponent', () => {
384
var instance = ReactDOM.render(<Component />, container);
385
386
expectDev(console.error.calls.count()).toBe(1);
395
- expectDev(console.error.calls.argsFor(0)[0]).toBe(
396
- 'Warning: setState(...): Cannot update during an existing state ' +
397
- 'transition (such as within `render` or another component\'s ' +
398
- 'constructor). Render methods should be a pure function of props and ' +
399
- 'state; constructor side-effects are an anti-pattern, but can be moved ' +
400
- 'to `componentWillMount`.'
387
+ expectDev(console.error.calls.argsFor(0)[0]).toContain(
388
+ 'Cannot update during an existing state transition (such as within ' +
389
+ '`render` or another component\'s constructor). Render methods should ' +
390
+ 'be a pure function of props and state; constructor side-effects are ' +
391
+ 'an anti-pattern, but can be moved to `componentWillMount`.'
392
);
393
394
// The setState call is queued and then executed as a second pass. This
src/renderers/shared/stack/reconciler/ReactUpdateQueue.js
+12
-27
@@ -28,16 +28,12 @@ function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
28
if (!internalInstance) {
29
if (__DEV__) {
30
var ctor = publicInstance.constructor;
31
- // Only warn when we have a callerName. Otherwise we should be silent.
32
- // We're probably calling from enqueueCallback. We don't want to warn
33
- // there because we already warned for the corresponding lifecycle method.
31
warning(
35
- !callerName,
36
- '%s(...): Can only update a mounted or mounting component. ' +
37
- 'This usually means you called %s() on an unmounted component. ' +
38
- 'This is a no-op.\n\nPlease check the code for the %s component.',
39
- callerName,
40
- callerName,
32
+ false,
33
+ 'Can only update a mounted or mounting component. This usually means ' +
34
+ 'you called setState, replaceState, or forceUpdate on an unmounted ' +
35
+ 'component. This is a no-op.\n\nPlease check the code for the ' +
36
+ '%s component.',
37
ctor && (ctor.displayName || ctor.name) || 'ReactClass'
38
);
39
}
@@ -47,12 +43,10 @@ function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
43
if (__DEV__) {
44
warning(
45
ReactCurrentOwner.current == null,
50
- '%s(...): Cannot update during an existing state transition (such as ' +
51
- 'within `render` or another component\'s constructor). Render methods ' +
52
- 'should be a pure function of props and state; constructor ' +
53
- 'side-effects are an anti-pattern, but can be moved to ' +
54
- '`componentWillMount`.',
55
- callerName
46
+ 'Cannot update during an existing state transition (such as within ' +
47
+ '`render` or another component\'s constructor). Render methods should ' +
48
+ 'be a pure function of props and state; constructor side-effects are ' +
49
+ 'an anti-pattern, but can be moved to `componentWillMount`.',
50
);
51
}
52
@@ -124,10 +118,7 @@ var ReactUpdateQueue = {
118
* @internal
119
*/
120
enqueueForceUpdate: function(publicInstance, callback, callerName) {
127
- var internalInstance = getInternalInstanceReadyForUpdate(
128
- publicInstance,
129
- 'forceUpdate'
130
- );
121
+ var internalInstance = getInternalInstanceReadyForUpdate(publicInstance);
122
123
if (!internalInstance) {
124
return;
@@ -161,10 +152,7 @@ var ReactUpdateQueue = {
152
* @internal
153
*/
154
enqueueReplaceState: function(publicInstance, completeState, callback, callerName) {
164
- var internalInstance = getInternalInstanceReadyForUpdate(
165
- publicInstance,
166
- 'replaceState'
167
- );
155
+ var internalInstance = getInternalInstanceReadyForUpdate(publicInstance);
156
157
if (!internalInstance) {
158
return;
@@ -207,10 +195,7 @@ var ReactUpdateQueue = {
195
);
196
}
197
210
- var internalInstance = getInternalInstanceReadyForUpdate(
211
- publicInstance,
212
- 'setState'
213
- );
198
+ var internalInstance = getInternalInstanceReadyForUpdate(publicInstance);
199
200
if (!internalInstance) {
201
return;