Skip to content

dynamic import causes parent re-render #77215

@davidgolden

Description

@davidgolden

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/reverent-bird-forked-kmsrqh?file=%2Fapp%2Fpage.tsx%3A18%2C2

To Reproduce

I've created a sandbox (https://codesandbox.io/p/devbox/reverent-bird-forked-kmsrqh?file=%2Fapp%2Fpage.tsx%3A18%2C2 - here is the link to the preview: https://kmsrqh-3000.csb.app/) with a minimal reproduction. When a child component is dynamically imported (), its parent component re-renders. You can see this by inspecting the console.log in dev tools. There are 2 renders of the parent component in the above example, not counting re-renders due to strict mode. When the dynamic import is removed in favor of a standard import, there is only one render as expected.

The issue is fixed by adding , but the Next docs imply this should not be necessary:

next/dynamic is a composite of React.lazy()
and Suspense

Current vs. Expected behavior

The current behavior is that when child components are imported dynamically, there are multiple re-renders of their parent components. When dealing with a tree with many children and many dynamically imported components, this results in a very large number of re-renders. The expectation is that so long as a render is not necessitated by normal conditions (like state change), the parent should only render once.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.3.0-canary.8 // There is a newer canary version (15.3.0-canary.11) available, please upgrade! 
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 4.7.3

Which area(s) are affected? (Select all that apply)

Lazy Loading

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Lazy LoadingRelated to Next.js Lazy Loading (e.g., next/dynamic or React.lazy).

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions