forked from DustinBrett/daedalOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_document.tsx
More file actions
55 lines (48 loc) · 1.18 KB
/
_document.tsx
File metadata and controls
55 lines (48 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import NextDocument, {
type DocumentContext,
type DocumentInitialProps,
Head,
Html,
Main,
NextScript,
} from "next/document";
import { ServerStyleSheet } from "styled-components";
import { DEFAULT_LOCALE } from "utils/constants";
const withStyledComponents = async (
ctx: DocumentContext
): Promise<DocumentInitialProps> => {
const { renderPage } = ctx;
const sheet = new ServerStyleSheet();
try {
ctx.renderPage = () =>
renderPage({
enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),
});
const { styles, ...initialProps } = await NextDocument.getInitialProps(ctx);
return {
...initialProps,
styles: [styles, sheet.getStyleElement()],
};
} finally {
sheet.seal();
}
};
class Document extends NextDocument {
public static override async getInitialProps(
ctx: DocumentContext
): Promise<DocumentInitialProps> {
return withStyledComponents(ctx);
}
public override render(): React.JSX.Element {
return (
<Html lang={DEFAULT_LOCALE}>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default Document;