Closed snehakhobragade90 closed 1 month ago
Close as duplicate of #64060, let's track there
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
https://codesandbox.io/p/devbox/jolly-fog-h86q9z
To Reproduce
Code Working details:
ClientWrapper
component imports a next/dynamic code-splitDynamicHeader
componentClientWrapper
uses client hooks likeuseEffect
which leads react to render client sidepage.tsx
dynamicHeader.tsx
ClientWrapper
Current vs. Expected behavior
I would expect that the loading state of the dynamically imported component is not rendered. It renders the server response, then flashes the loading state before rendering the client side rendered content. There should be no flashing of the loading state which harms the application's CLS. Hypothesis why this is happening there is a race condition where the react is rendering and mounting before the code split chunks are loaded. Adding a
setTimeout
with an arbitrary delay to the react rendering effectively resolves the bug.Provide environment information
Which area(s) are affected? (Select all that apply)
Performance
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Other (Deployed)
Additional context
This bug significantly impacts our application's Cumulative Layout Shift metric, thereby detrimentally affecting our SEO performance. It posing a roadblock for us in migrating more URLs to route through the Next app.
Adding of videos from the sandbox and our stripped down app for reference:
https://github.com/vercel/next.js/assets/31524521/0f857076-23fc-4c63-97d0-910f31597c04