Skip to content

Commit 88b9767

Browse files
authored
Hack to recover from reading the wrong Fiber (facebook#33055)
`requestFormReset` incorrectly tries to get the current dispatch queue from the Fiber. However, the Fiber might be the workInProgress which is an inconsistent state. This hack just tries the other Fiber if it detects one of the known inconsistent states but there can be more. Really we should stash the dispatch queue somewhere stateful which is effectively what `setState` does by binding it to the closure.
1 parent 0038c50 commit 88b9767

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/react-reconciler/src/ReactFiberHooks.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -3355,8 +3355,16 @@ export function requestFormReset(formFiber: Fiber) {
33553355
);
33563356
}
33573357

3358-
const stateHook = ensureFormComponentIsStateful(formFiber);
3358+
let stateHook: Hook = ensureFormComponentIsStateful(formFiber);
33593359
const newResetState = {};
3360+
if (stateHook.next === null) {
3361+
// Hack alert. If formFiber is the workInProgress Fiber then
3362+
// we might get a broken intermediate state. Try the alternate
3363+
// instead.
3364+
// TODO: We should really stash the Queue somewhere stateful
3365+
// just like how setState binds the Queue.
3366+
stateHook = (formFiber.alternate: any).memoizedState;
3367+
}
33603368
const resetStateHook: Hook = (stateHook.next: any);
33613369
const resetStateQueue = resetStateHook.queue;
33623370
dispatchSetStateInternal(

0 commit comments

Comments
 (0)