Repository navigation
fix(runtime): don't break declarative shadow DOM when SSR HTML is streamed - #7005
Merged
Merged
Conversation
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the current behavior?
When SSR HTML is streamed (e.g. Next.js App Router / Suspense), components are often already defined when the browser parses their markup. The browser then runs the element's constructor at the host's start tag, before it has parsed the children. Stencil attaches a shadow root in that constructor, so when the parser reaches the host's
<template shadowrootmode>it can't attach the declarative root:A second declarative shadow root cannot be created on a host.<template>in the host's light DOMHydration has the same problem in general: it runs from
connectedCallback, before the host's children have been parsed.GitHub Issue Number: #6690
What is the new behavior?
SSR hosts (
s-id) wait until the parser has finished their subtree before attaching a shadow root or hydrating.runtime/parse-gate.ts. While the document is loading, an SSR host whose subtree isn't parsed yet is held back. "Parsed" means the element or an ancestor has a next sibling. AMutationObserver(only active while something is held) andDOMContentLoadedrelease held hosts:loader-bundle) andstandaloneruntimes. The constructor only skips attaching the shadow root when the parser may still be streaming into the element. Any other element (created after load, or upgraded once its definition arrives) attaches in the constructor as before.client-hydrate. The original-location comment scan re-runs when a host isn't in the map yet. Previously it ran once, so hosts streamed in later were missed.Closes #6690
Documentation
BREAKING_CHANGES.md: "Shadow Roots of Parser-Created Elements Attach on Connect".Does this introduce a breaking change?
A
shadowcomponent that the HTML parser creates while the document is still loading no longer has a shadow root in its constructor. It gets one when it connects, or, for an SSR host, once its subtree is parsed. Elements created any other way are unaffected.Migration: don't read
this.el.shadowRootin a component constructor; useconnectedCallbackor a later lifecycle method.Testing
test/ssr/test/streaming.e2e.ts, run against both the lazy and standalone builds. It serves pages from a real chunked HTTP server, loads the components with anasyncscript, and splits the stream inside every host. It covers:<template>, hydrated and interactive)declarative-shadow-domandscopedmodes, compared with the same page served in one gov5without this change and pass with ittest/ssre2e, all fourtest/runtimeprojects, plus typecheck / lint / knip / spellcheck / format.<Suspense>: