next/dynamic from external package causes hydration errors for combination of pages and app routers
Nobody has claimed this yet.
- 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/adanperez/nextjs-dynamic-hydration-error
To Reproduce
pnpm run buildpnpm run start- Go to http://localhost:3000/ and refresh the page a couple times
You will see the following Hydration errors in the console.
framework-5e252d5045bb7a0e.js:9 Uncaught Error: Minified React error #418; visit https://reactjs.org/docs/error-decoder.html?invariant=418 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
at ly (framework-5e252d5045bb7a0e.js:9:46791)
at framework-5e252d5045bb7a0e.js:9:99911
at oD (framework-5e252d5045bb7a0e.js:9:106131)
at oO (framework-5e252d5045bb7a0e.js:9:99079)
at framework-5e252d5045bb7a0e.js:9:98886
at oF (framework-5e252d5045bb7a0e.js:9:98893)
at oS (framework-5e252d5045bb7a0e.js:9:93932)
at x (framework-5e252d5045bb7a0e.js:33:1364)
at MessagePort.T (framework-5e252d5045bb7a0e.js:33:1894)
framework-5e252d5045bb7a0e.js:9 Uncaught Error: Minified React error #423; visit https://reactjs.org/docs/error-decoder.html?invariant=423 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
at i (framework-5e252d5045bb7a0e.js:9:120721)
at oO (framework-5e252d5045bb7a0e.js:9:99019)
at framework-5e252d5045bb7a0e.js:9:98886
at oF (framework-5e252d5045bb7a0e.js:9:98893)
at ox (framework-5e252d5045bb7a0e.js:9:95645)
at oS (framework-5e252d5045bb7a0e.js:9:94200)
at x (framework-5e252d5045bb7a0e.js:33:1364)
at MessagePort.T (framework-5e252d5045bb7a0e.js:33:1894)
Current vs. Expected behavior
Current
Currently we get hydration errors when using a next/dynamic component from an external package.
Expected
We do not expect to get hydration errors.
If you remove the app directory and rebuild and start the app, you will no longer see hydration errors. The combination of pages and app directories causes the hydration error.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
Available memory (MB): 32768
Available CPU cores: 10
Binaries:
Node: 20.10.0
npm: 10.2.3
Yarn: N/A
pnpm: 9.4.0
Relevant Packages:
next: 14.2.5 // Latest available version is detected (14.2.5).
eslint-config-next: 14.2.5
react: 18.3.1
react-dom: 18.3.1
typescript: 5.5.4
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Lazy Loading, Pages Router, Runtime
Which stage(s) are affected? (Select all that apply)
next build (local), next start (local)
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Clone the linked reproduction, run pnpm run build and pnpm run start, then refresh http://localhost:3000/ to confirm the hydration errors. Compare the result with the app directory removed; done means the pages-and-app-router combination with an external next/dynamic component no longer produces hydration errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, next.js, react
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100