Repository navigation
feat(code-splitting): namespace extraction for already-loaded dynamic entry merges - #10560
Closed
IWANABETHATGUY wants to merge 1 commit into
Closed
IWANABETHATGUY wants to merge 1 commit into
IWANABETHATGUY wants to merge 1 commit into
Conversation
This was referenced Jul 31, 2026
… entry merges
The already-loaded pass keeps a shared dependency in its own chunk
whenever the dynamic entry's `import()` namespace is observed opaquely
or read names the entry does not export, because the merge would leak
the atom's generated export names onto the namespace.
Accept those merges too by routing the surviving entry chunk through the
simulated-facade machinery that eliminated facade chunks already use:
`common_chunk_exported_facade_chunk_namespace`, the narrowed simulated
namespace, and the finalizer's `rewrite_dynamic_import_for_merged_entry`
(`import('./chunk.js').then(n => n.<alias>)`). This is Rollup's
`generateFacades` fallback — `Chunk.ts` includes `module.namespace` in
the chunk and exports it, and call sites extract it — expressed at
assignment time. The partial-usage fast path still wins when provable,
emitting neither the namespace object nor the extra promise hop.
Extraction is refused when the simulated namespace cannot reproduce the
entry's interface: dynamic exports (CJS `export *`, star chains that
reach an external) and statically known `then` exports, which would make
the chunk namespace thenable and hand the extraction callback the
assimilated value.
New fixtures `already_loaded_{opaque_namespace,unexported_read}_extraction`
pin the fallback, `already_loaded_{then_export,cjs_star}_keeps_split`
pin the refusals, and `dynamic_dominator_with_exports_no_merge` now
inlines `sharedDynamic` into `dynamic1` with unchanged runtime
assertions.
ref #10263
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
IWANABETHATGUY
force-pushed
the
feat/already-loaded-namespace-extraction
branch
from
July 31, 2026 05:38
ba939a6 to
5a98e35
Compare
Member
Author
|
Closing in favour of #10526, which now implements the same namespace-extraction fallback and the same |
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.
What is this PR solving?
Part of #10263 (stacked on #10532; supersedes #10533, which could not be reopened after its branch was amended).
#10532 merges an already-loaded shared dependency only when partial
import()usage proves the extra exports unobservable. When the namespace is observed opaquely (export const app = import('./app.js'),Object.keys(ns), rest-destructuring) or a read targets an unexported name, Rolldown still split — Rollup emits 3 chunks there via itsgenerateFacadesfallback (Chunk.tsincludesmodule.namespacein the chunk, exports it, and call sites extract it with.then(n => n.a)).How
Rolldown already owns that exact machinery for eliminated facade chunks:
common_chunk_exported_facade_chunk_namespace, the narrowed simulated namespace, the cross-chunk namespace export, and the finalizer'srewrite_dynamic_import_for_merged_entry(import('./chunk.js').then(n => n.<alias>), all formats and wrap kinds). This PR opts the surviving dynamic entry chunk into it from the already-loaded pass: register the entry in the map, narrow its namespace statement to link-retained getters, include the namespace/wrapper symbols (SymbolIncludeReason::SimulatedFacadeChunk), and record the__exportAlldemand before standalone runtime extraction so placement stays normal.The #10532 fast path still wins when provable, so the issue's own graph keeps the leaner no-extraction output.
Extraction is refused when the simulated namespace cannot reproduce the entry's interface:
thenexport — the chunk namespace would become thenable andimport()would assimilate before the extraction callback runs (already_loaded_then_export_keeps_split);export *(already_loaded_cjs_star_keeps_split) — the external-star case is then lifted by feat(code-splitting): forward external star re-exports through extracted namespaces #10559 on top of this PR.Tests
already_loaded_opaque_namespace_extraction—Object.keysobserves exactly the entry's exports; 3 chunksalready_loaded_unexported_read_extraction—ns.missingstaysundefinedthrough the extracted namespace; 3 chunksalready_loaded_then_export_keeps_split,already_loaded_cjs_star_keeps_split— refusals pinned; 4 chunks with source-faithful runtime behaviordynamic_dominator_with_exports_no_merge— now inlinessharedDynamicintodynamic1(snapshot-only change; its runtime assertions are unchanged)All
_test.mjsfiles execute the emitted output. Full Rust suite passes.Stack: #10532 ← #10560 (this) ← #10559