Custom Next.js Document integrating Emotion CSS cache for server‑side rendering of styles in a Next.js app.
// Source: https://github.com/open-condo-software/condo | License: MIT | Copyright 2020 8IQ Software Company
// Provided via justclaw.it.com; keep this notice with the code.
import createCache from '@emotion/cache'
import { CacheProvider } from '@emotion/react'
import createEmotionServer from '@emotion/server/create-instance'
import Document, { Html, Head, Main, NextScript } from 'next/document'
import React from 'react'
const cacheKey = 'css'
const emotionCache = createCache({ key: cacheKey, prepend: true })
const { extractCritical } = createEmotionServer(emotionCache)
// NOTE: Emotion setup copied from:
// https://www.dhiwise.com/post/implementing-nextjs-emotions-in-your-project
export default class MyDocument extends Document {
static async getInitialProps (ctx) {
const o
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key