dillon1000/react
Commit
Browse files Fix useId in strict mode (#22681)
* Fix: useId in strict mode In strict mode, `renderWithHooks` is called twice to flush out side effects. Modying the tree context (`pushTreeId` and `pushTreeFork`) is effectful, so before this fix, the tree context was allocating two slots for a materialized id instead of one. To address, I lifted those calls outside of `renderWithHooks`. This is how I had originally structured it, and it's how Fizz is structured, too. The other solution would be to reset the stack in between the calls but that's also a bit weird because we usually only ever reset the stack during unwind or complete. * Add test for render phase updates Noticed this while fixing the previous bug
Changed paths8 files
First-parent comparisonpackages/react-dom/src/__tests__/ReactDOMUseId-test.js ModifiedM packages/react-reconciler/src/ReactFiberBeginWork.new.js ModifiedM packages/react-reconciler/src/ReactFiberBeginWork.old.js ModifiedM packages/react-reconciler/src/ReactFiberHooks.new.js ModifiedM packages/react-reconciler/src/ReactFiberHooks.old.js ModifiedM packages/react-reconciler/src/ReactFiberTreeContext.new.js ModifiedM packages/react-reconciler/src/ReactFiberTreeContext.old.js ModifiedM packages/react-server/src/ReactFizzHooks.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…