Skip to content

Fix form state reset when component state is updated #34075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

eps1lon
Copy link
Collaborator

@eps1lon eps1lon commented Aug 1, 2025

Alternate to #33351 without the regression highlighted in #33351 (comment)

Host context is now modelled like React context in that we set the value in pushHostContext instead of during updateHostComponent. There was a comment explaining why that shouldn't work but I can't see why it would not work for Host context but normal context.

Closes #30368
Closes #33351

@meta-cla meta-cla bot added the CLA Signed label Aug 1, 2025
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Aug 1, 2025
@react-sizebot
Copy link

react-sizebot commented Aug 1, 2025

Comparing: c260b38...9be8342

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 530.04 kB 530.08 kB = 93.63 kB 93.61 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 654.48 kB 654.52 kB = 115.34 kB 115.34 kB
facebook-www/ReactDOM-prod.classic.js = 674.42 kB 674.45 kB = 118.68 kB 118.65 kB
facebook-www/ReactDOM-prod.modern.js = 664.84 kB 664.87 kB = 117.02 kB 117.02 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 9be8342

Comment on lines -1940 to -1913
// This is intentionally set here instead of pushHostContext because
// pushHostContext gets called before we process the state hook, to avoid
// a state mismatch in the event that something suspends.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I fully understand this comment. If something suspends we pop back up. And the Component we're rendering (here: TransitionAwareHostComponent) should not be able to read the current Context just yet which is what pushing the context before the render would do, right? We can't nest Host Context anyway though. So this seems safe to move the push after the render.

@eps1lon eps1lon force-pushed the sebbie/hostcontextpopper branch 2 times, most recently from b6348c2 to 77dc8cc Compare August 1, 2025 09:14
@eps1lon eps1lon marked this pull request as ready for review August 1, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: useFormStatus pending state is reset when component state is updated
3 participants