Skip to content

Commit 1b9328c

Browse files
author
Brian Vaughn
authored
Null stateNode after unmount (#17666)
1 parent 8979766 commit 1b9328c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/legacy-events/ReactControlledComponent.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ function restoreStateOfTarget(target) {
3333
'setRestoreImplementation() needs to be called to handle a target for controlled ' +
3434
'events. This error is likely caused by a bug in React. Please file an issue.',
3535
);
36-
const props = getFiberCurrentPropsFromNode(internalInstance.stateNode);
37-
restoreImpl(internalInstance.stateNode, internalInstance.type, props);
36+
const stateNode = internalInstance.stateNode;
37+
// Guard against Fiber being unmounted.
38+
if (stateNode) {
39+
const props = getFiberCurrentPropsFromNode(stateNode);
40+
restoreImpl(internalInstance.stateNode, internalInstance.type, props);
41+
}
3842
}
3943

4044
export function setRestoreImplementation(

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ function detachFiber(current: Fiber) {
905905
current.lastEffect = null;
906906
current.pendingProps = null;
907907
current.memoizedProps = null;
908+
current.stateNode = null;
908909
if (alternate !== null) {
909910
detachFiber(alternate);
910911
}

0 commit comments

Comments
 (0)