Skip to content

Conversation

@Jagget
Copy link
Contributor

@Jagget Jagget commented Jan 30, 2026

During hydration, shadow DOM components adopt styles via adoptedStyleSheets. The SSR-rendered <style sty-id="..."> elements inside shadow roots become redundant and can be removed.

  • Runs only for shadow DOM components during hydration
  • Removal occurs after adoptedStyleSheets is populated
  • Negligible performance impact (~1 querySelector per shadow root)

@Jagget Jagget requested a review from a team as a code owner January 30, 2026 16:49
@johnjenkins
Copy link
Contributor

Thanks for raising @Jagget
Can you explain the impact of stylesheet not being removed?

@Jagget
Copy link
Contributor Author

Jagget commented Jan 30, 2026

@johnjenkins not removed stylesheets doesn't have negative impact, they just duplicate one another and basically useless. For every element browser should read and parse the same styles twice:

image

@johnjenkins
Copy link
Contributor

johnjenkins commented Jan 30, 2026

But I’m not sure that impacts anything?

The initial style tag is already there and parsed as part of the initial page render, then they’re converted to constructible stylesheets.

Removing the original style tag doesn’t impact any of that?

@Jagget
Copy link
Contributor Author

Jagget commented Jan 30, 2026

@johnjenkins But still, there is twice amount of styles. And we don't need 50% of that, because it's the same. But the browser still have to read it and apply it. I think you can count browser's memory consumption as an impact here. Because browser can unload duplicated styles.

@Jagget
Copy link
Contributor Author

Jagget commented Jan 30, 2026

Removing styles frees memory, especially with many shadow DOM instances. Imagine, if a page with 100 shadow DOM components, that's 100 redundant <style> nodes...

I mean, yes, it's not a parsing optimization. It's more of a runtime cleanup.

@johnjenkins
Copy link
Contributor

Kk - think that makes sense. Can you try and schedule the removal (eg via writeTask)

@johnjenkins johnjenkins added this pull request to the merge queue Jan 31, 2026
Merged via the queue into stenciljs:main with commit bc90887 Jan 31, 2026
69 checks passed
@Jagget Jagget deleted the styles-after-ssr branch January 31, 2026 22:49
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