Skip to content

fix(react): Fix hydration mismatch for experimentalReactChildren#15146

Merged
Princesseuh merged 7 commits into
withastro:mainfrom
kedarvartak:fix/react-children-client-props
Mar 24, 2026
Merged

fix(react): Fix hydration mismatch for experimentalReactChildren#15146
Princesseuh merged 7 commits into
withastro:mainfrom
kedarvartak:fix/react-children-client-props

Conversation

@kedarvartak
Copy link
Copy Markdown
Contributor

Fixes hydration mismatch when using experimentalReactChildren option.

Problem

When experimentalReactChildren=true, children passed to React components had inconsistent prop handling between server and client:

  • Server correctly mapped class to className and generated unique key props
  • Client read DOM attributes directly without applying the same transformations

This caused React warnings and hydration errors:

  • "Invalid DOM property 'class'. Did you mean 'className'?"
  • "Each child in a list should have a unique 'key' prop."

Solution

Updated the client-side createReactElementFromDOMElement function in client.ts to:

  • Map DOM attribute names to React prop names (class to className, for to htmlFor)
  • Generate unique key props for each child element

Testing

Added unit tests for class-to-className mapping and key generation. All existing tests pass.

Closes #15102

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 8, 2026

🦋 Changeset detected

Latest commit: a58f37c

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added pkg: react Related to React (scope) pkg: integration Related to any renderer integration (scope) labels Jan 8, 2026
@matthewp
Copy link
Copy Markdown
Contributor

Can you change this to go against next instead?

Comment thread packages/integrations/react/src/client.ts Outdated
Comment thread packages/integrations/react/src/client.ts Outdated
kedarvartak and others added 3 commits March 14, 2026 16:50
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
@kedarvartak
Copy link
Copy Markdown
Contributor Author

@ematipico hi so sorry for the massive delay, i have updated the pr as per your change requests. thanks

Copy link
Copy Markdown
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

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

Thanks, this looks fine to me!

@Princesseuh Princesseuh dismissed ematipico’s stale review March 24, 2026 23:32

Changes have been applied

@Princesseuh Princesseuh merged commit f771f75 into withastro:main Mar 24, 2026
21 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope) pkg: react Related to React (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

experimentalReactChildren flag doesn't map node.class and children keys on client

4 participants