Turbopack: Fix experimental server hmr for pages router#90398
Merged
wbinnssmith merged 2 commits intocanaryfrom Feb 24, 2026
Merged
Turbopack: Fix experimental server hmr for pages router#90398wbinnssmith merged 2 commits intocanaryfrom
wbinnssmith merged 2 commits intocanaryfrom
Conversation
This is cherry-picked from #90389, which also serves as a test case for server hmr being enabled by default. This fixes a number of issues with server hmr, most notably that pages router updates weren’t reflected: 1. **Pages Router pages weren't clearing the chunk cache** — the old condition (which just checked the cli flag) meant the chunk cache was only cleared when server HMR was entirely absent. Once server HMR was enabled, Pages Router pages (which don't use the Turbopack module registry) got stale. 2. **`deleteCache` was skipped for files with server HMR subscriptions** — this left stale entries in `evalManifest`'s `sharedCache`, causing "Could not find module in React Client Manifest" errors when new `'use client'` components were added. 3. **`clearModuleContext` was skipped for middleware and edge routes** — server HMR subscriptions include edge runtime chunks, but `__turbopack_server_hmr_apply__` can't reach those sandboxes. They need `clearModuleContext` called explicitly. 4. **Chunk cache wasn't cleared for `.env`/config changes** — when `force: true` (no code change), module-level env captures stayed stale. Now `__next__clear_chunk_cache__()` is called unconditionally when `force` is set.
06a89a6 to
42cfad0
Compare
Collaborator
Failing test suitesCommit: 8bb3f7f | About building and testing Next.js
Expand output● typed-routes-validator › should have passing tsc after the server generated types |
Collaborator
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles: **399 kB** → **399 kB** ✅ -1 B80 files with content-based hashes (individual files not comparable between builds) Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URL |
d2bd2a2 to
1e69bbc
Compare
… HMR chunks - Add comment explaining the usesServerHmr condition (App Router Node.js only) - Move deleteCache to after the serverHmrSubscriptions check so it is skipped for server HMR module chunks. Calling it unconditionally risks resetting the Turbopack runtime's devModuleCache if onUpdateFailed later clears loadedChunks and the runtime chunk gets re-executed from disk.
1e69bbc to
8bb3f7f
Compare
lukesandberg
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is cherry-picked from #90389, which also serves as a test case for server hmr being enabled by default.
This fixes a number of issues with server hmr, most notably that pages router updates weren’t reflected:
Pages Router pages weren't clearing the chunk cache — the old condition (which just checked the cli flag) meant the chunk cache was only cleared when server HMR was entirely absent. Once server HMR was enabled, Pages Router pages (which don't use the Turbopack module registry) got stale.
deleteCachewas skipped for files with server HMR subscriptions — this left stale entries inevalManifest'ssharedCache, causing "Could not find module in React Client Manifest" errors when new'use client'components were added.clearModuleContextwas skipped for middleware and edge routes — server HMR subscriptions include edge runtime chunks, but__turbopack_server_hmr_apply__can't reach those sandboxes. They needclearModuleContextcalled explicitly.Chunk cache wasn't cleared for
.env/config changes — whenforce: true(no code change), module-level env captures stayed stale. Now__next__clear_chunk_cache__()is called unconditionally whenforceis set.