AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Next/Dynamic Manifest ID Collision Between Pages And App Routers Breaks Pages Hydration

When a module using next/dynamic is imported by both Pages Router and App Router, ReactLoadablePlugin writes the App Router webpack module id into react-loadable-manifest.json, causing Pages Router client bundle to request the wrong dynamic chunk id and fail hydration with React error #418.

highConfidence 95%Next.jsAffected V16.3.2Affected V16.4.0-Canary.21

Origin Analysis

ReactLoadablePlugin keys manifest entries by `${importer} -> ${request}` without considering webpack layer. A module imported by both routers exists twice in the client compilation (pages-dir-browser and app-pages-browser) with different module ids. Both copies are walked under the same key, and whichever is processed last overwrites the entry. In typical builds the App Router copy is processed last, so the manifest contains the App Router module id, which the Pages Router client cannot use.
1. Clone https://github.com/korhan/next-loadable-layer-repro 2. Run `bun install` or `npm install` 3. Run `bun run build` (uses `next build --webpack`) 4. Run `bun run check` to compare manifest ids 5. Run `bun run start` and open http://localhost:3400/ with browser console open; observe React #418 error on pages router route

Fixing Code Block

Edge Case Audit

This fix assumes the App Router will never need entries from react-loadable-manifest.json. If future Next.js versions change that behavior, this filter would cause missing manifest entries for App Router dynamic imports. Additionally, the layer name 'app-pages-browser' may change in future webpack layer schemas. Rollback recommendation: revert this patch and instead make the manifest key layer-aware (e.g., include layer in the key) or maintain separate manifests per router, then merge only the Pages Router entries.

Ecosystem Topology