Repository navigation
Turbopack: preserve chunk load promise identity - #100421
Merged
lukesandberg merged 3 commits intoOct 21, 2026
Merged
Conversation
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Contributor
Tests PassedCommit: f8e30eb |
lukesandberg
commented
Oct 19, 2026
lukesandberg
marked this pull request as ready for review
October 19, 2026 21:56
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
lukesandberg
enabled auto-merge (squash)
October 20, 2026 15:55
jimmyhmiller
approved these changes
Oct 21, 2026
lukesandberg
deleted the
fleet/turbopack-ensure-chunk-promise-identity
branch
October 21, 2026 19:28
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.
Summary
#98836 added an on-demand
__turbopack_ensure_chunk__hook to the Turbopack Node dev runtime by overriding__turbopack_context__.l. The override returnedensured.then(() => loadChunkAsync(...)), so every call that hit a not-yet-cached chunk produced a new promise, and the first caller's promise never matched the one later callers got fromchunkCache. That broke referential identity for__next_chunk_load__(which wraps.l), which React relies on. It also created extra promises for React's dev async tracking to process.This change makes
loadChunkAsyncitself aware of__turbopack_ensure_chunk__:undefined(nothing to compile), the chunk is required synchronously and the shared pre-resolved promise is cached, exactly as without the hook.ensure â require/installpromise is cached inchunkCacheimmediately. Concurrent and later callers all get the same promise untilclearChunkCache().requirefailures stay cached asChunkLoadError, as before..loverride andchunksBeingEnsuredmap indev-base.tsare removed. The Node runtime snapshots are regenerated.On the Next.js side, the dev hook is now a plain function. It returns synchronously for chunks that aren't lazy-compilation chunks, or that have no matching entries, and returns a promise only when it actually activates a lazy chunk.
Verification
pnpm test-dev-turbo test/development/app-dir/lazy-dynamic-imports/lazy-dynamic-imports.test.ts(12/12 pass)A scratch Node script against the generated dev and build runtimes, with a mocked ensure hook. It checks:
ChunkLoadError, non-JS chunks, andclearChunkCacheresetThe identity and sync-path checks fail on the previous runtime and pass with this change.