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

[React 19] inline style tag not removing when new content is loaded without that element #32367

Open
tounsoo opened this issue Feb 12, 2025 · 2 comments
Labels

Comments

@tounsoo
Copy link

tounsoo commented Feb 12, 2025

Summary

Trying out the inline style referred in the doc and it works as expected on initial load.

After the initial load, if I change to page (or navigate to a different content) where some of the element in the initial page isn't used, I expect the style tag for those to be removed but looks like they are just there and it compounds new ones.

Is this by design? If so, what is the benefit of doing this?

If it isn't, am I doing something wrong?

What can I do in short term?

Screenshots

Image "Shadow Dom" page has `data-href="_8rfbtm-lg"` and `data-href="_8rfbtm-md"` only.

Moving to another page that doesn't have _8rfbtm-lg, I expect that style tag to be removed but its still there:

Image
@Andarist
Copy link
Contributor

FWIW, this is currently expected. It matches the behavior of all (most?) existing CSS-in-JS libraries. Styles are not cleaned up, there is no "garbage collection" implemented for them. It's likely that the user navigates back to the page using those styles so they might still be used in the future by the application. In a sense, a style element can be left in the DOM because it doesn't matter for the application all that much if it's there is there are elements matching the selectors contained in it. It will just "do nothing" but there is no big harm in that.

@tounsoo
Copy link
Author

tounsoo commented Feb 23, 2025

Gotcha. I expected so too but wanted to confirm since the doc didn't mention it. Thank you!

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

No branches or pull requests

2 participants