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

[HMR] swapStyle() API does not account for stylesheet collisions #4155

Open
nolanlawson opened this issue Apr 16, 2024 · 0 comments
Open

[HMR] swapStyle() API does not account for stylesheet collisions #4155

nolanlawson opened this issue Apr 16, 2024 · 0 comments
Labels
bug HMR Hot Module Replacement

Comments

@nolanlawson
Copy link
Contributor

nolanlawson commented Apr 16, 2024

In the current implementation of swapStyle, unrendering stylesheets does not work correctly if there is a chance collision of CSS content between two separate .css files.

For example, let's say we have two identical CSS files:

/* a.css */
div { color: red }
/* b.css */
div { color: red }

And a third, different CSS file:

/* c.css */
div { color: blue }

And say we render two components, one with A and the other with B. Now we run:

swapStyle(a, c)

This will correctly replace A with C in the first component. However, it will incorrectly also replace B with C in the second component, since the contents for A and B have happened to collide.

Note this only occurs in cases where it's possible for the exact CSS content to collide in the same target DocumentOrShadowRoot, e.g.:

  • top-level light DOM components with non-scoped style
  • native shadow DOM components with non-scoped style

The reason for this is that style scoping / synthetic shadow scoping defeats the collision by appending generated attributes/classes to the CSS selectors inside the CSS content.

Minimal repro: nolanlawson@43e3d9b (passes for scoped light, fails for native shadow and global light)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug HMR Hot Module Replacement
Projects
None yet
Development

No branches or pull requests

1 participant