I cloned the the official next js example with ant design link : https://github.com/vercel/next.js/tree/canary/examples/with-ant-design
Then I did npm install to install all dependencies . Then I did npm run dev to see everything is working fine . Then I did npm run build to build the next js app and then I run npm run start to run the built app in localhost .
The problem is when I go to network tab and select localhost page and then preview it from the preview tab , the ant design is not actually applying with server side rendering and I see no styles at all . It takes half second for ant design css to apply which is not what I want .
How can I use ant design with next js server side rendering properly ?
What you might be looking for is inlining the CSS, in order for the browser to apply them more quickly without needing to fetch the CSS resources as separate requests first.
There's a question about official support for this, but no answer yet: https://github.com/vercel/next-plugins/issues/364
However, there's a workaround, that can be found in https://github.com/vercel/next-plugins/issues/238 and I tried this and it works.
To achieve inlining the CSS, add a file called
_document.js
in thepages
folder, with the following contents: