Skip to content

fix(runtime): reuse SSR styles during hydration - #6965

Open
Elements2720 wants to merge 1 commit into
stenciljs:mainfrom
Elements2720:fix/ssr-style-hydration
Open

Elements2720 wants to merge 1 commit into
stenciljs:mainfrom
Elements2720:fix/ssr-style-hydration

Conversation

@Elements2720

@Elements2720 Elements2720 commented Oct 19, 2026 •

Copy link
Copy Markdown

Summary

Fixes #6947.

SSR style generation now:

SSR styles
-> add sty-id for every component stylesheet
-> client hydration finds existing sheet
-> reuse it once per scope
-> HMR remains allowed to replace stylesheet text

Changes:

  • Mark every SSR/HMR-created component style with sty-id, including light-DOM components.
  • Preserve server stylesheet text during hydration and record the scope as applied.
  • Keep existing HMR stylesheet replacement behavior.
  • Add regression coverage for light-DOM SSR markers, multi-instance hydration reuse, and HMR updates.

Evidence

  • Before: the two new regression tests failed: light-DOM SSR styles had no sty-id, and hydration replaced server-rendered text.
  • After: focused runtime hydration/style checks passed: 3 suites, 20 tests.
  • npm run build -- --ci passed.
  • npm run test.dist passed.
  • npm run test.testing passed.
  • npm run tsc.prod passed.
  • ESLint and Prettier checks passed for the changed files.

The full root Jest run was also attempted. In this environment it hit an unrelated existing failure in src/compiler/output-targets/dist-lazy/test/generate-lazy-module.spec.ts and later ran out of memory; the focused runtime suite passed independently (65 suites, 685 tests) before the final HMR-only test addition.

Merge Danger

Door: two-way

Blast Radius: runtime

The change is limited to runtime stylesheet registration/reuse and its tests. HMR remains explicitly covered, while hydration no longer mutates server stylesheet text.

@Elements2720
Elements2720 requested a review from a team as a code owner October 19, 2026 21:37

This branch has not been deployed

No deployments
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.

bug: SSR <style> of components without encapsulation has no sty-id, so hydration inserts every sheet a second time

1 participant