-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
FOUC (Flash of Unstyled Content) when using dynamic imports and CSS Modules #62940
Comments
I'm seeing something similar with my Sass set up. I'm importing a global scss file in the root layout.tsx and prepended CSS variable files in sassOptions, I'm using .scss modules in all my components - I've tried everything to eliminate FOUC between pages. It seems the component .scss is not being loaded before the component. If I set |
Same issue. It blocks our migration to the App router. |
I am having the same issue as well. I am trying to use an It's very frustrating because the SSR issue does not affect the user, but causes the next build to fail. On the other hand, the dynamic import or other solutions to bypass SSR fix the problem on the server side, but create a worse experience for the user due to the FOUC. I am also using the App Router. |
Thanks for working on this, @huozhi! ❤️ |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
To Reproduce
font-size: 2rem; color: red
Current vs. Expected behavior
When using
next/dynamic
, I expect that any CSS Modules imported in the lazy-loaded component will be applied to the server-generated HTML. Otherwise, we wind up with this FOUC:Note that this bug only occurs within the App Router. It works as-expected inside the Pages router.
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 Available memory (MB): 65536 Available CPU cores: 10 Binaries: Node: 20.10.0 npm: 10.2.3 Yarn: 1.22.21 pnpm: 8.14.1 Relevant Packages: next: 14.2.0-canary.4 // Latest available version is detected (14.2.0-canary.4). eslint-config-next: 14.1.2 react: 18.2.0 react-dom: 18.2.0 typescript: 5.3.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
App Router, Dynamic imports (next/dynamic)
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)
Additional context
"use client"
directive from the file that does the importing. This does indeed solve the FOUC, but it also breaks lazy-loading, causingHeavyComponent
to be included in the main JS bundle instead of being spun off into its own bundle."use client"
is documented in React lazy or next dynamic don't reduce an app route's "First Load JS" #49454.I'm really hoping that this can get looked at 🙏 it's a pretty big blocker for building real-world apps with CSS Modules, or any of the tools that compile to CSS Modules.
The text was updated successfully, but these errors were encountered: