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

[EXP] Styles are lost when shadow root is re-mounted #1054

Open
2 tasks done
balthild opened this issue Aug 23, 2024 · 0 comments
Open
2 tasks done

[EXP] Styles are lost when shadow root is re-mounted #1054

balthild opened this issue Aug 23, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@balthild
Copy link

What is the example you wish to see?

https://github.com/PlasmoHQ/examples/tree/main/with-emotion

@emotion/cache uses HTMLStyleElement.sheet (a CSSStyleSheet instance) to insert CSS rules into the style tag. The rules inserted with this API are not persisted. When a style tag is removed from and and re-inserted into the DOM tree, the sheet property will be destroyed and recreated.

However, @emotion/cache assumes that the style tag will never be removed from the DOM, making the components to be unstyled if the root container is re-mounted due to changes of anchors.

A workaround would be to reset styleCache.inserted when the component is unmounted. This workaround only works for the cases of single anchor / single root container.

useLayoutEffect(() => () => {
    styleCache.inserted = {};
}, []);

It would also be better to show how to make the styleCache scoped to each root container in the example. Currently it is a global singleton.

See: whatwg/html#7520

Is there any context that might help us understand?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I checked the current issues for duplicate problems.
@balthild balthild added the documentation Improvements or additions to documentation label Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant