@samitouri / QOS-React-1 / commits / 88b9767404

Hack to recover from reading the wrong Fiber (#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.

Sebastian Markbåge committed Apr 29, 2025 at 13:36 UTC 88b976740467f9dfabae03c79a8eff9033c35050
1 file changed +9 -1
packages/react-reconciler/src/ReactFiberHooks.js
+9 -1
@@ -3355,8 +3355,16 @@ export function requestFormReset(formFiber: Fiber) {
3355 );
3356 }
3357
3358 - const stateHook = ensureFormComponentIsStateful(formFiber);
3358 + let stateHook: Hook = ensureFormComponentIsStateful(formFiber);
3359 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 + }
3368 const resetStateHook: Hook = (stateHook.next: any);
3369 const resetStateQueue = resetStateHook.queue;
3370 dispatchSetStateInternal(