Dynamically Imported Components unmount unexpectedly during Hydration if any parent React context updates #65160
Labels
bug
Issue was opened via the bug report template.
Lazy Loading
Related to Next.js Lazy Loading (e.g., `next/dynamic` or `React.lazy`).
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/dynamic-chunk-hydration-9fj3ys
To Reproduce
Current vs. Expected behavior
Current Behaviour
The dynamically imported component(components imported using dynamic function from nextjs and ssr enabled) unmounts and re-renders on the client side during hydration when a parent React context updates, causing a flickering effect. the context update is happening by scheduling a state update in useEffect used in context resulting in change in value passed to a context provider.
Expected Behaviour
The dynamically imported component, once rendered on the server, should not unmount on the client side during hydration, even if a parent React context updates. The context update is happening in useEffect and that is not discouraged practise. it is useful to sync state from local storage or cookies.
Provide environment information
Which area(s) are affected? (Select all that apply)
Lazy Loading
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local)
Additional context
we've been facing this issue since app router was v13 But, we were not able create a minimal demo to reproduce this.
The text was updated successfully, but these errors were encountered: