-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy path_document.js
45 lines (40 loc) · 1.1 KB
/
_document.js
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
import Document, { Html, Head, Main, NextScript } from 'next/document';
import React from 'react';
import { revalidate, FlushedChunks, flushChunks } from '@module-federation/nextjs-mf/utils';
class MyDocument extends Document {
static async getInitialProps(ctx) {
if (process.env.NODE_ENV === 'development' && !ctx.req.url.includes('_next')) {
await revalidate().then(shouldReload => {
if (shouldReload) {
ctx.res.writeHead(302, { Location: ctx.req.url });
ctx.res.end();
}
});
} else {
ctx?.res?.on('finish', () => {
revalidate();
});
}
const initialProps = await Document.getInitialProps(ctx);
const chunks = await flushChunks();
return {
...initialProps,
chunks,
};
}
render() {
return (
<Html>
<Head>
<meta name="robots" content="noindex" />
<FlushedChunks chunks={this.props.chunks} />
</Head>
<body className="bg-background-grey">
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;