Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR+hydration should not result in duplicated stylesheets across HTML and JS #3944

Open
nolanlawson opened this issue Jan 11, 2024 · 0 comments

Comments

@nolanlawson
Copy link
Collaborator

nolanlawson commented Jan 11, 2024

Right now, the way SSR works is that renderComponent renders the component stylesheets as <style>s:

<x-foo>
  <template shadowrootmode=open>
    <style> div { color: red } </style>
    <div>Hello world</div>
  </template>
</x-foo>

And then this stylesheet is duplicated inside of the JS bundle as well:

function stylesheet(token, useActualHostSelector, useNativeDirPseudoclass) {
  var shadowSelector = token ? ("[" + token + "]") : "";
  return "div" + shadowSelector + " {color: red;}";
}

This is fairly wasteful to include the same content twice. Especially if disableSyntheticShadowSupport is set in the compiler, then the strings are always the same (at least for shadow DOM – light DOM is trickier because of :host and useActualHostSelector).

Ideally there should be some way to avoid this duplication entirely, i.e. to only put the stylesheet into the HTML, not the JS.

Related: #2851

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant