-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Get emotion cache by key #3266
Comments
I'm rather hesitant to expose this as those keys were never meant to be a public API - just a mechanism to deconflict styles between caches. I think |
Thanks for the reply @Andarist. I tried this solution suggested by a maintainer from Astro: document.addEventListener('astro:before-swap', e => {
const el = document.querySelector('style[data-emotion]').cloneNode(true)
e.newDocument.head.appendChild(el)
}); This clones the existing Do you know of any other trick that can clear the cache without |
The likely problem is that the memory is still preserved between those navigations so Emotion things those elements are still in the DOM as they are still registered in the cache. I think the above solution tries to work around the problem. Astro is removing a resource (style element) from a shared resource (DOM). This is not a resource they control (they have not created it) so its lifecycle (like cleaning up/removing from the DOM) doesn't belong to their responsibilities. I suspect cleaning up the whole DOM is deeply integrated in their philosophy and implementation. So I think, at the very least, they should have some opt-out mechanism from this cleanup, like a data-attribute or smth. This way you could just set that - without being concerned with cache keys etc and they would just leave those elements alone. |
If they do have a data-attribute that keeps it from being removed in the DOM, do you mean apply that data-attribute to the |
Yeah, exactly. I can't add it to Emotion because any data attribute they might have is kinda theirs and I don't want to depend on it directly. But it can easily by applied by you - the person who integrates both tools. I with this wouldn't be required at all but I don't see a different path forward here right now. |
The problem
Get cache by key so userland can manually clear a cache even if the external component doesnt export it.
Say there's an external component library named
awesome-lib
that exports components that uses@emotion/react
with custom cache, and you're using Astro's View transition - the styles will be removed when navigating. A trick would be to clear the emotion cache used, butawesome-lib
doesn't export it.Proposed solution
Is there already an existing function that does this?
The text was updated successfully, but these errors were encountered: