vercel / vercel/next.js

[Turbopack] [Pages] Hydration error (or double render) when using dynamic imports in _app.tsx

Open
#85,370 7 comments 14 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

linear: turbopack Module Resolution Pages Router Turbopack
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/rtrembecky/next-turbopack-hydration-repro

To Reproduce
  1. Install the deps - pnpm i
  2. Start the app - pnpm dev
  3. Navigate to http://localhost:3000
Current vs. Expected behavior

Current behavior:

Image

Expected: No errors.

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 24.2.0
  npm: 11.4.0
  Yarn: 1.22.19
  pnpm: 9.15.9
Relevant Packages:
  next: 16.0.1-canary.2 // Latest available version is detected (16.0.1-canary.2).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Pages Router, Module Resolution, Turbopack

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

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

Additional context

Pinpointed broken versions:

  • canary: >= 15.1.1-canary.14, up to 16.0.1-canary.2 (latest at the time of writing)
  • stable: >= 15.2.0

Working versions:

  • 15.1.1-canary.13
  • 15.1.6

Background:

  • _app.tsx imports a component via next/dynamic - this causes a hydration issue
  • when the same component is imported from the page level as well, it works - http://localhost:3000/works page (in repro repo) works
  • when the <main> wrapper in _app.tsx is removed or replaced by a <> fragment, the dynamic element is rendered TWICE instead

Real world scenario:

  • On www.groupon.com, we use const Layout = Component.getLayout || DefaultLayout; in _app.tsx, where DefaultLayout is imported dynamically - it's not needed for a user that accesses only pages with custom layouts (defined on the page level via Page.getLayout).
    • -> We are getting hydration errors in dev when using Turbopack, and also production React minified errors (even though we haven't migrated build to Turbopack yet, so it might be a different issue).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction: run pnpm i, pnpm dev, and compare the root page with /works. Inspect the dynamic import in _app.tsx and the related Pages Router behavior; done means the root page has no hydration errors or duplicate rendering while /works continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, react, typescript
Domain
build-system, frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.