Skip to content

fix(react): Fix empty conditional slots hydration issues#15378

Open
dmgawel wants to merge 3 commits intowithastro:mainfrom
dmgawel:dmgawel/react-conditional-slots
Open

fix(react): Fix empty conditional slots hydration issues#15378
dmgawel wants to merge 3 commits intowithastro:mainfrom
dmgawel:dmgawel/react-conditional-slots

Conversation

@dmgawel
Copy link
Contributor

@dmgawel dmgawel commented Feb 2, 2026

Changes

  • Fix React slot rendering to skip empty SlotString values and avoid emitting empty <astro-slot> nodes (prevents React hydration mismatches for conditional slots).
  • Add a regression fixture (slots.astro + ConditionalSlot.jsx) and test to validate empty slots don’t render <astro-slot> while filled slots still do.

Minimal example that was causing hydration error:

  <ReactComponent client:load>
    {show ? <span slot="my-slot-name">Visible</span> : null}
  </ReactComponent>

Testing

New test case added.

Docs

  • No docs updates needed (internal integration fix + tests only).

@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

🦋 Changeset detected

Latest commit: fb2dcae

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 Feb 2, 2026
@matthewp
Copy link
Contributor

matthewp commented Feb 3, 2026

@dmgawel this looks great! Can you add a changeset? pnpm changeset

@dmgawel
Copy link
Contributor Author

dmgawel commented Feb 4, 2026

@matthewp Done ✅

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.

2 participants