Reproduction link or steps
Consider these two examples:
They both contain these modules:
// app.js
import "./shared.js";
console.log("app");
import("./sidebar.js");
// shared.js
console.log("shared");
// sidebar.js
import "./shared.js"
console.log("sidebar");
In addition, REPL B contains this module:
// entry.js
console.log("entry");
import("./app.js");
The entry point of REPL A is app.js, while the entry point of REPL B is entry.js.
What is expected?
Rolldown bundles REPL A with two chunks:
app, which contains app.js and shared.js
sidebar, which contains sidebar.js
app has a dynamic import for sidebar (for the app.js->sidebar.js dynamic import), and sidebar has a static import for app (for the sidebar.js->shared.js static import). Rolldown correctly detects that it does not need to split shared.js into its own chunk, because the only way sidebar.js is ever loaded is through app.js, so it's always app.js causing first shared.js to be loaded.
I would expect REPL B to be similar, given that the only difference is that app.js is not directly the entrypoint but it's dynamically imported by entry.js:
entry, which contains entry.js, and dynamically imports app
app, which contains app.js and shared.js, and dynamically imports sidebar
sidebar, which contains sidebar.js, and statically imports app
Rolldown should not extract shared.js into its own chunk for the same reason as above.
What is actually happening?
In REPL B, Rolldown is extracting shared.js into its own chunk:
entry, which contains entry.js, and dynamically imports app
app, which contains app.js, statically imports shared, and dynamically imports sidebar
shared, which contains shared.js
sidebar, which contains sidebar.js, and statically imports app
System Info
This `envinfo` command doesn't print the rolldown version, but it would be 1.0.0-rc.16.
Any additional comments?
I noticed this because Vite 8 (Rolldown) is producing many more chunks than Vite 7 (Rollup), going from about 50 to about 80.
Reproduction link or steps
Consider these two examples:
They both contain these modules:
In addition, REPL B contains this module:
The entry point of REPL A is
app.js, while the entry point of REPL B isentry.js.What is expected?
Rolldown bundles REPL A with two chunks:
app, which containsapp.jsandshared.jssidebar, which containssidebar.jsapphas a dynamic import forsidebar(for theapp.js->sidebar.jsdynamic import), andsidebarhas a static import forapp(for thesidebar.js->shared.jsstatic import). Rolldown correctly detects that it does not need to splitshared.jsinto its own chunk, because the only waysidebar.jsis ever loaded is throughapp.js, so it's alwaysapp.jscausing firstshared.jsto be loaded.I would expect REPL B to be similar, given that the only difference is that
app.jsis not directly the entrypoint but it's dynamically imported byentry.js:entry, which containsentry.js, and dynamically importsappapp, which containsapp.jsandshared.js, and dynamically importssidebarsidebar, which containssidebar.js, and statically importsappRolldown should not extract
shared.jsinto its own chunk for the same reason as above.What is actually happening?
In REPL B, Rolldown is extracting
shared.jsinto its own chunk:entry, which containsentry.js, and dynamically importsappapp, which containsapp.js, statically importsshared, and dynamically importssidebarshared, which containsshared.jssidebar, which containssidebar.js, and statically importsappSystem Info
Any additional comments?
I noticed this because Vite 8 (Rolldown) is producing many more chunks than Vite 7 (Rollup), going from about 50 to about 80.