Skip to content

Commit 667cc3b

Browse files
committedOct 11, 2017
Deduped warning about updating component which is not mounted(facebook#11140)
1 parent b75be6a commit 667cc3b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed
 

‎src/renderers/shared/fiber/ReactFiberScheduler.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,34 @@ if (__DEV__) {
118118
} = require('ReactDebugFiberPerf');
119119

120120
var didWarnAboutStateTransition = false;
121+
var ownerHasNoopWarning = {};
121122

122123
var warnAboutUpdateOnUnmounted = function(
123124
instance: React$ComponentType<any>,
124125
) {
125126
const ctor = instance.constructor;
127+
const currentComponent =
128+
(ctor && (ctor.displayName || ctor.name)) || 'ReactClass';
129+
const currentComponentErrorInfo =
130+
'Can only update a mounted or mounting ' +
131+
'component. This usually means you called setState, replaceState, ' +
132+
'or forceUpdate on an unmounted component. This is a no-op.\n\nPlease ' +
133+
'check the code for the ' +
134+
currentComponent +
135+
' component.';
136+
137+
if (ownerHasNoopWarning[currentComponentErrorInfo]) {
138+
return;
139+
}
126140
warning(
127141
false,
128-
'Can only update a mounted or mounting component. This usually means ' +
129-
'you called setState, replaceState, or forceUpdate on an unmounted ' +
130-
'component. This is a no-op.\n\nPlease check the code for the ' +
131-
'%s component.',
132-
(ctor && (ctor.displayName || ctor.name)) || 'ReactClass',
142+
'Can only update a mounted or mounting ' +
143+
'component. This usually means you called setState, replaceState, ' +
144+
'or forceUpdate on an unmounted component. This is a no-op.\n\nPlease ' +
145+
'check the code for the %s component.',
146+
currentComponent,
133147
);
148+
ownerHasNoopWarning[currentComponentErrorInfo] = true;
134149
};
135150

136151
var warnAboutInvalidUpdates = function(instance: React$ComponentType<any>) {

0 commit comments

Comments
 (0)
Please sign in to comment.