Skip to content

Regression: next/dynamic conditionally importing client components adds both to client bundle in Next.js 15 (used to work in 14) #80234

@gonmpablo

Description

@gonmpablo

Link to the code that reproduces this issue

https://github.com/gonmpablo/NextDynamicIssue

To Reproduce

Next.js 14:

Go to this URL: https://next-dynamic-issue-git-ec7cb0-pablo-gonzalez-martinezs-projects.vercel.app/
Observe: Only the used component’s chunk is included in the client bundle.
Next.js 15:

Go to this URL: https://next-dynamic-issue-git-09c334-pablo-gonzalez-martinezs-projects.vercel.app/
Observe: Both chunks for ClientA and ClientB are included, despite the conditional rendering

Current vs. Expected behavior

Current (Next.js 15):
When using next/dynamic() to conditionally import two client components (e.g., ClientA, ClientB), both chunks are sent to the client, even though only one is rendered at runtime.

Expected (Next.js 14 behavior):
Only the chunk of the component actually rendered should be sent to the client. This was working correctly in v14 and helped significantly reduce TBT.

Provide environment information

NEXT JS 15:
{
  "dependencies": {
    "next": "15.3.3",
    "react": "^19.0.0",
    "react-dom": "^19.0.0"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3",
    "@next/bundle-analyzer": "^15.3.3",
    "@types/node": "^20",
    "@types/react": "^19",
    "@types/react-dom": "^19",
    "eslint": "^9",
    "eslint-config-next": "15.3.3",
    "typescript": "^5"
  }
}

NEXT JS 14:
{
  "dependencies": {
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "next": "14.2.28"
  },
  "devDependencies": {
    "typescript": "^5",
    "@types/node": "^20",
    "@next/bundle-analyzer": "14.2.28",
    "@types/react": "18.2.0",
    "@types/react-dom": "18.2.0",
    "eslint-config-next": "14.2.28",
    "@eslint/eslintrc": "^3"
  }
}

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

dynamicIO, Performance

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

Other (Deployed), Vercel (Deployed), next start (local), next build (local), next dev (local)

Additional context

Could be something related to this change? #65486

Metadata

Metadata

Assignees

No one assigned

    Labels

    PerformanceAnything with regards to Next.js performance.dynamicIORelated to dynamicIO.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions