Skip to content

Commit

Permalink
[material-nextjs] Fix order of emotion server (#40409)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored Jan 3, 2024
1 parent 48f677e commit b7dd80a
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export async function documentGetInitialProps(
// You can consider sharing the same Emotion cache between all the SSR requests to speed up performance.
// However, be aware that it can have global side effects.
const cache = options?.emotionCache ?? createEmotionCache();
// The createEmotionServer has to be called directly after the cache creation due to the side effect of cache.compat = true,
// otherwise the <style> tag will not come with the HTML string from the server.
const { extractCriticalToChunks } = createEmotionServer(cache);

return createGetInitialProps([
{
Expand All @@ -123,7 +126,6 @@ export async function documentGetInitialProps(
return <App emotionCache={cache} {...props} />;
},
resolveProps: async (initialProps) => {
const { extractCriticalToChunks } = createEmotionServer(cache);
const { styles } = extractCriticalToChunks(initialProps.html);
return {
...initialProps,
Expand Down

0 comments on commit b7dd80a

Please sign in to comment.