Skip to content

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 updated in pushHostContext (similar to normal React Context) in addition to during updateHostComponent.

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: eb89912...aa288b5

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.84 kB 6.84 kB +0.05% 1.88 kB 1.88 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.02% 608.26 kB 608.36 kB +0.01% 107.67 kB 107.68 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.84 kB 6.84 kB = 1.88 kB 1.88 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.02% 667.37 kB 667.47 kB +0.01% 117.55 kB 117.57 kB
facebook-www/ReactDOM-prod.classic.js +0.02% 693.56 kB 693.67 kB +0.01% 122.05 kB 122.06 kB
facebook-www/ReactDOM-prod.modern.js +0.02% 683.99 kB 684.10 kB +0.01% 120.43 kB 120.45 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against aa288b5

Comment on lines 1940 to 1979
// 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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A common issue is that CompleteWork and UnwindWork unconditionally calls popHostContext. That's called even when something in the component suspends because it doesn't know if we suspended before or after the push. There's no state to indicate that.

That's why we always pushHostContext and other push things immediately when we enter the update before anything could error or suspend.

Since renderTransitionAwareHostComponentWithHooks might suspend, I don't think it's safe to move the pushHostContext after it. In fact I'm surprised we don't have a test that fails for that case. Maybe we're lacking coverage or there's some other thing that covers it but it shouldn't be safe in general.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. Moved the pushContext back to its original place. When the state changes, we update the context value which works because only a single transition provider is allowed.

Basically, we set the value on pushHostContext and when we update state.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you revert this comment back to the original now too please?

@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
@eps1lon eps1lon force-pushed the sebbie/hostcontextpopper branch from 77dc8cc to 9be8342 Compare August 1, 2025 09:15
@eps1lon eps1lon force-pushed the sebbie/hostcontextpopper branch 2 times, most recently from a8e8216 to 692d5d9 Compare August 12, 2025 09:54
@eps1lon eps1lon requested a review from sebmarkbage August 12, 2025 09:55
@redbmk
Copy link

redbmk commented Aug 27, 2025

Would love to see this merged in soon. We're blocked from upgrading to Next 15 and React 19 until this issue is fixed - will also have to wait for Next to pull in a new canary release after this is merged.

@sebmarkbage any chance you could review the most recent changes?

@eps1lon eps1lon changed the title Fix form state reset when component state is updated Fix form status reset when component state is updated Nov 18, 2025
@eps1lon eps1lon requested a review from acdlite November 18, 2025 14:54
@eps1lon eps1lon force-pushed the sebbie/hostcontextpopper branch from 692d5d9 to aa288b5 Compare November 19, 2025 17:13
@eps1lon eps1lon merged commit 8ac5f4e into facebook:main Nov 19, 2025
237 of 238 checks passed
@eps1lon eps1lon deleted the sebbie/hostcontextpopper branch November 19, 2025 17:22
github-actions bot pushed a commit that referenced this pull request Nov 19, 2025
Co-authored-by: Vordgi <sasha2822222@gmail.com>

DiffTrain build for [8ac5f4e](8ac5f4e)
github-actions bot pushed a commit that referenced this pull request Nov 19, 2025
Co-authored-by: Vordgi <sasha2822222@gmail.com>

DiffTrain build for [8ac5f4e](8ac5f4e)
github-actions bot pushed a commit to code/lib-react that referenced this pull request Nov 23, 2025
Co-authored-by: Vordgi <sasha2822222@gmail.com>

DiffTrain build for [8ac5f4e](facebook@8ac5f4e)
github-actions bot pushed a commit to code/lib-react that referenced this pull request Nov 23, 2025
Co-authored-by: Vordgi <sasha2822222@gmail.com>

DiffTrain build for [8ac5f4e](facebook@8ac5f4e)
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

6 participants