Skip to content

fix(ssr): add scoped classes during SSR #6238

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

Merged
merged 5 commits into from
Apr 14, 2025
Merged

Conversation

johnjenkins
Copy link
Contributor

@johnjenkins johnjenkins commented Apr 11, 2025

What is the current behavior?

When using renderToString to hydrate scoped web components, the "scoped" classes are not being applied correctly to the children of the host element.

Image

GitHub Issue Number: #6219

What is the new behavior?

When using renderToString with serializeShadowRoot: 'scoped', the children of the host element should properly have the sc-web-component-name class applied and all the defined styles that come with it.

Documentation

Does this introduce a breaking change?

  • Yes
  • No

Testing

A new wdio test not checks for scoped classes from renderToString content

Other information

n/a

@johnjenkins johnjenkins requested a review from a team as a code owner April 11, 2025 20:49
@Armand-Lluka
Copy link

I did some playing around trying to get to work on my end and noticed that modifying

 if (BUILD.hydrateServerSide && BUILD.shadowDom && cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) {
        style = scopeCss(style, scopeId, true);
   }

to remove the hydrateServerSide, or invert, the check in initializeComponent.ts also seemed to resolve the issue. Not too sure where the correct place to change things here would be here since it seems it can be done in several ways.

@johnjenkins
Copy link
Contributor Author

johnjenkins commented Apr 14, 2025

I did some playing around trying to get to work on my end and noticed that modifying ...
to remove the hydrateServerSide, or invert, the check in initializeComponent.ts also seemed to resolve the issue. Not too sure where the correct place to change things here would be here since it seems it can be done in several ways.

hey @Armand-Lluka - thanks for your investigation(!) but I don't think we would want to bring the scopeCss methods into the client-side build because it would add quite a number of bytes to the users not using SSR at all :)

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@christian-bromann christian-bromann merged commit 3363017 into main Apr 14, 2025
72 checks passed
@christian-bromann christian-bromann deleted the fix-ssr-scoped-classes branch April 14, 2025 15:02
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.

3 participants