Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash of Unstyled content using Ant Design with Nextjs #48483

Open
1 task done
useCallback opened this issue Apr 17, 2023 · 6 comments
Open
1 task done

Flash of Unstyled content using Ant Design with Nextjs #48483

useCallback opened this issue Apr 17, 2023 · 6 comments
Labels
examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers

Comments

@useCallback
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64
    Binaries:
      Node: 16.15.0
      npm: 8.5.5
      Yarn: 1.22.18
      pnpm: N/A
    Relevant packages:
      next: 13.3.1-canary.8
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0

Which example does this report relate to?

with-ant-design

What browser are you using? (if relevant)

Chrome 112.0.5615.49

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

Flash of Unstyled content using Ant Design with Nextjs :

When using Ant Design with Next JS
the HTML gets rendered unstyled ( barebone HTML elements) for a fraction of a second , and then the styles get loaded and the components are rendered correctly

Expected Behavior

the first contentful-paint should be properly styled

To Reproduce

clone the with-ant-design example and host it

@useCallback useCallback added the examples Issue/PR related to examples label Apr 17, 2023
@imaksp
Copy link
Contributor

imaksp commented Apr 18, 2023

it may be because this example does not use any provider from antd, you can use this official example from antd for SSR:
https://github.com/ant-design/create-next-app-antd

@shuding shuding added the good first issue Easy to fix issues, good for newcomers label Apr 30, 2023
SamarthBagga added a commit to SamarthBagga/next.js that referenced this issue May 12, 2023
Fixed issue vercel#48483 by adding a Head tag with the a link to the ant design css. I did this because the issue was related to server-side rendering, where the HTML generated on the server did not include the necessary CSS styles for the Ant Design components, leading to a flash of unstyled components on page load. By adding the <Head> tag and including the necessary CSS styles, we were able to ensure that the CSS is included in the HTML generated on the server, thereby avoiding the flash of unstyled components.
SamarthBagga added a commit to SamarthBagga/next.js that referenced this issue May 12, 2023
fixed issue vercel#48483. Added a head tag with a link to the ant design css. I did this because the issue was related to server-side rendering, where the HTML generated on the server did not include the necessary CSS styles for the Ant Design components, leading to a flash of unstyled components on page load. By adding the <Head> tag and including the necessary CSS styles, we were able to ensure that the CSS is included in the HTML generated on the server, thereby avoiding the flash of unstyled components.
This was referenced May 12, 2023
@Shubhdeep12
Copy link

Hi, just want to confirm - is this issue fixed?

@jeremypeters
Copy link

jeremypeters commented Jun 19, 2023

Just came across this issue - https://github.com/ant-design/create-next-app-antd is not suitable when using the app folder structure though.

@sujalcodes3
Copy link

sujalcodes3 commented Aug 28, 2023

I am new to this repository. I would love to work on this issue. Can you guide me how to further approach this issue.?

@alexrohleder
Copy link

I solved this by setting the @ant-design/cssinjs version resolution on my package.json:

{
  "resolutions": {
    "@ant-design/cssinjs": "1.17.2"
  }
}

I'm using the Next.js 13.5.1 app dir and AntD 5.10.2.

@sambatlim
Copy link

@alexrohleder solved my problem. I recommed you to read Antd documentation to find which "@ant-design/cssinjs" version that you should choose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

8 participants