Skip to content

EmotionCacheProvider prevents style from being injected during Preact-CLI SSR #2829

Answered by srmagura
micahjon asked this question in Q&A
Discussion options

You must be logged in to vote

I think a single cache instance is being reused across multiple HTML pages. cache.sheet keeps track of the style tags it has inserted, so if you reuse the same cache, it won't insert the same style tag twice.

Your components/header/index.js file is executed once when it is imported for the first time, and this is when the cache gets created. After that, importing the file again won't cause a new cache to be created.

I tested a similar case with Next.js prerendering (next export) and found that Next is generating each page in a separate JavaScript "context", meaning a new cache will be created for each page. I'm not sure exactly how they are doing this.

By the way, we don't test against Pr…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@micahjon
Comment options

@srmagura
Comment options

@srmagura
Comment options

Answer selected by micahjon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #2828 on July 19, 2022 11:45.