101
} = require('./ReactDebugFiberPerf');
102
103
var didWarnAboutStateTransition = false;
104
+ var didWarnSetStateChildContext = false;
105
+ var didWarnStateUpdateForUnmountedComponent = {};
106
105
- var warnAboutUpdateOnUnmounted = function(
106
- instance: React$ComponentType<any>,
107
- ) {
108
- const ctor = instance.constructor;
107
+ var warnAboutUpdateOnUnmounted = function(fiber: Fiber) {
108
+ const componentName = getComponentName(fiber) || 'ReactClass';
109
+ if (didWarnStateUpdateForUnmountedComponent[componentName]) {
110
+ return;
111
+ }
112
warning(
113
false,
111
- 'Can only update a mounted or mounting component. This usually means ' +
112
- 'you called setState, replaceState, or forceUpdate on an unmounted ' +
113
- 'component. This is a no-op.\n\nPlease check the code for the ' +
114
- '%s component.',
115
- (ctor && (ctor.displayName || ctor.name)) || 'ReactClass',
114
+ 'Can only update a mounted or mounting ' +
115
+ 'component. This usually means you called setState, replaceState, ' +
116
+ 'or forceUpdate on an unmounted component. This is a no-op.\n\nPlease ' +
117
+ 'check the code for the %s component.',
118
+ componentName,
119
);
120
+ didWarnStateUpdateForUnmountedComponent[componentName] = true;
121
};
122
119
- var warnAboutInvalidUpdates = function(instance: React$ComponentType<any>) {
123
+ var warnAboutInvalidUpdates = function(instance: React$Component<any>) {
124
switch (ReactDebugCurrentFiber.phase) {
125
case 'getChildContext':
126
+ if (didWarnSetStateChildContext) {
127
+ return;
128
+ }
129
warning(
130
false,
131
'setState(...): Cannot call setState() inside getChildContext()',
132
);
133
+ didWarnSetStateChildContext = true;
134
break;
135
case 'render':
136
if (didWarnAboutStateTransition) {
137
return;
138
}
131
- didWarnAboutStateTransition = true;
139
warning(
140
false,
141
'Cannot update during an existing state transition (such as within ' +
143
'be a pure function of props and state; constructor side-effects are ' +
144
'an anti-pattern, but can be moved to `componentWillMount`.',
145
);
146
+ didWarnAboutStateTransition = true;
147
break;
148
}
149
};
1237
} else {
1238
if (__DEV__) {
1239
if (!isErrorRecovery && fiber.tag === ClassComponent) {
1232
- warnAboutUpdateOnUnmounted(fiber.stateNode);
1240
+ warnAboutUpdateOnUnmounted(fiber);
1241
}
1242
}
1243
return;