-
Current behavior: Preact CLI is compatible with Emotion, and has a feature where it will pre-render routes (SSR) to improve first-paint times. However, when an The end result is that shared Emotion components (e.g. header, footer) are unstyled during first paint, and FOUT ensues. To reproduce: Reduced test case in this post (only takes a minute to setup with Expected behavior: Ideally, it would be possible to use Environment information: Every package in the reduced test case is up-to-date (reproduced an hour ago w/ a fresh install)
Really appreciate your help with this issue. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I think a single cache instance is being reused across multiple HTML pages. Your I tested a similar case with Next.js prerendering ( By the way, we don't test against Preact so I can't fully recommend using Emotion + Preact together. |
Beta Was this translation helpful? Give feedback.
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…