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

Automatically ignore native-shadow-only CSS files in synthetic shadow #4709

Open
nolanlawson opened this issue Oct 25, 2024 · 0 comments
Open

Comments

@nolanlawson
Copy link
Collaborator

nolanlawson commented Oct 25, 2024

We introduced the experimental disableSyntheticShadowSupport flag as an optimization for compiled CSS to vastly reduce the bundle size: #3229

Some of our downstreams are already using this to conditionally turn on the flag for filenames that match a certain pattern (e.g. foo.my-pattern.native.css). You can do this e.g. in a Rollup plugin.

However, this creates a conundrum. What if your component supports both native and synthetic shadow? Rendering those native-only styles in synthetic mode is not only wasteful from a perf perspective, but it's also incorrect since unscoped CSS selectors are being used in the document <head>.

As a solution, the LWC engine could mark native-only stylesheets as such, e.g.:

function stylesheet(token, useActualHostSelector, useNativeDirPseudoclass) {
  // ...
}
stylesheet.$nativeOnly$ = true

Then the engine could use this $nativeOnly$ flag and, if synthetic shadow is being rendered, treat the stylesheet as a no-op (i.e. returning the empty string).

/cc @gonzalocordero

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