Skip to content

fix(runtime): keep SSR slot content visible across hydration order - #7013

Merged
johnjenkins merged 4 commits into
stenciljs:mainfrom
deleonio:fix/6934-slot-content-hidden-after-hydration
Nov 24, 2026
Merged

johnjenkins merged 4 commits into
stenciljs:mainfrom
deleonio:fix/6934-slot-content-hidden-after-hydration

Conversation

@deleonio

Copy link
Copy Markdown
Contributor

What is the current behavior?

Content that a light-DOM component renders into another light-DOM component's default slot disappears after client hydration: since 4.41.0 the runtime sets hidden="" on it. In a real app every layout section that renders into a wrapper's slot goes blank once the client hydrates, which takes the LCP element with it. 4.40.1 was fine, and client-only rendering never hits this.

The reporter's analysis in #6934 traced the whole chain, and I could reproduce every step with their inline repro:

SSR serializes a node's slot assignment as an s-sn attribute on the element. The owning host only converts it into the s-sn property while it hydrates itself. When the wrapper hydrates first, addSlottedNodes runs before that conversion happened: the projected node matches neither the slot attribute nor the s-sn property, so it is not collected and never gets s-sh. The post-render hiding pass from #6514 then hides it, because at that point it looks exactly like content without a slot to go to. Nothing relocates it later, since SSR had already placed it. Hydration order decides whether you see the bug - which is why it is easy to miss.

GitHub Issue Number: #6934

What is the new behavior?

addSlottedNodes also honors the s-sn attribute, so nodes SSR already assigned to a slot are collected no matter which host hydrates first. That is the fix direction the reporter suggested and verified, and I implemented it in the same shape.

My first instinct was the smaller-looking one: gate the hiding pass back to what it was before #6514. The reporter explicitly ruled that out, and rightly so - the pass correctly hides stale server markup in nodes cloned on the client, and restoring the old flag-gated behavior would bring that problem back. Collecting the node at the source is the fix that keeps #6514 working.

I verified the whole thing against the reporter's inline reproduction (two light-DOM components, renderToString, headless Chrome): without the change, .inner comes back hidden with exit code 1; with it, .inner stays visible, matching 4.40.1. I ran that both ways myself - stash the fix, rebuild, watch it fail, restore it, watch it pass.

Documentation

No docs change needed; this restores behavior the SSR docs already describe.

Does this introduce a breaking change?

  • Yes
  • No

Testing

  • New wdio regression test in test/wdio/ssr-hydration/ that reproduces the hydration order from the issue (wrapper hydrates before the owning host, set up via the existing defineCustomElement pattern) and asserts the projected content stays visible. Without the fix this test fails; I ran it both ways.
  • A spec-page test pins the fix(runtime): update non-shadow slotted content visibility via dynamic <slot> #6514 behavior this fix must not touch (scoped component, dynamic slot toggle: hidden without slot, visible with slot, hidden again) - the addSlottedNodes change only affects the SSR-attribute path, which does not exist in client-only rendering, but I wanted that pinned rather than assumed.
  • Full jest unit suite green (4195 tests), all ssr-hydration wdio specs green (25 tests). The broader e2e/wdio suites beyond ssr-hydration I did not run locally.

Thank you to the reporter of #6934 - the bisect, the traced hydration order and the verified fix direction in the issue made this a small change instead of a long hunt.

Content a light-DOM component renders into another light-DOM
component's default slot disappeared after client hydration since
4.41.0 (see stenciljs#6934): the runtime set `hidden` on it once the client
took over.

SSR serializes a node's slot assignment as an `s-sn` attribute on the
element. The owning host converts it into the `s-sn` property only
when it hydrates itself. When the wrapper component hydrates first,
`addSlottedNodes` ran before that conversion happened, skipped the
node (it matched neither `slot` attribute nor `s-sn` property), so
the node never got `s-sh` - and the post-render hiding pass from
stenciljs#6514 then hid it, since it looks exactly like content without a slot
to go to. Nothing relocated it afterwards, because SSR had already
placed it.

`addSlottedNodes` now also honors the `s-sn` attribute, so nodes SSR
already assigned to the slot are collected regardless of which host
hydrates first. Verified against the reproduction from stenciljs#6934: SSR
markup hydrates with the content visible, as in 4.40.1.
@deleonio
deleonio requested a review from a team as a code owner November 13, 2026 06:36
@johnjenkins
johnjenkins enabled auto-merge (squash) November 24, 2026 15:11
@johnjenkins
johnjenkins merged commit d49c70c into stenciljs:main Nov 24, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants