Repository navigation
Description
From the behaviors described in rolldown/rolldown#10693, there are some effects we could reason out:
Behaviors
inlineCommonChunks removes the original common chunk and allows its modules to appear in multiple final chunks, while the runtime still ensures that each module is executed only once.
Vite CSS plugin
Some reasoning:
inlineCommonChunkswill only affect vite css behavior if it's enabled. From this aspect, implementinginlineCommonChunkwon't introduce any breaking behavior to the current vite css. So the key here is the new behaviors after enablinginlineCommonChunksare positive or negative.- Following above reasoning, the css related issues can be handled separate from the implementation.
Investigations
Plain CSS
For main.js -> lib.css -> @import util.css, Vite resolves the CSS @import before chunking. Rolldown sees one empty JavaScript module for lib.css, while Vite stores the compiled lib.css + util.css under that module ID.
When A and B each have their own CSS and also import shared.css:
- Without
inlineCommonChunks, the module forshared.cssstays in a common chunk. Vite emits the shared rules once in a CSS asset used by both A and B. - When
inlineCommonChunksselects that common chunk, the module forshared.cssappears in both the A and B chunks. - Vite collects CSS by walking each chunk's
chunk.modules, so it writes the shared rules into both A's and B's CSS assets.
The separate shared CSS request disappears, but the shared rules are duplicated. If both A and B are loaded, loading the later CSS asset can change which rule wins in the cascade. For this common chunk, no JavaScript output is removed: Vite already deletes its empty JavaScript output.
Size issue
inlineCommonChunks.maxSize measures the transformed module source, not the stylesheet stored by Vite. A plain CSS module therefore contributes zero bytes even when its stylesheet is large. A pure CSS common chunk falls below any positive maxSize; in a mixed chunk, the CSS still contributes zero bytes.
A workaround would be the css plugin just generate enough placeholders to make the generated proxy js module have the same size of the css content.
A real solution would be allow plugins delcare a module's logic size so rolldown will use it for calculation instead of using original source's size.
CSS Modules
A shared.module.css import also becomes one Rolldown module. Its generated JavaScript exports the class-name map, while Vite stores its stylesheet separately under the same module ID.
When A and B each have their own CSS and also import shared.module.css, selecting its common chunk puts the class-name-map code in both JavaScript chunks, and Vite writes the shared rules into both CSS assets. maxSize counts the class-name-map source but not the stylesheet, so a large stylesheet with a small class-name map can still be treated as small.
With cssCodeSplit: false, the copied rules are repeated in the single output stylesheet, so no CSS request disappears.
Effects
- css chunks are affected by
inlineCommonChunksbecuase the js proxy modules are affected byinlineCommonChunks. - For pure css chunk(chunk that only contains js proxy modules), it would be duplicate into their consumer entries. Vite css will extract them into corresponding entry css chunk. If there are not entry css chunks, themselves will become entry css chunks.
- For non-pure css chunks(chunk that contains normal js modules and proxy modules), if they got inlined, js modules are processed normally, js proxy modules are processed the same as pure css chunks.
- What
inlineCommonChunksbrings to Vite css is positve (declaring the proxy module size correctly)inlineCommonChunkscan reduce common css chunks(css modules shared by multiple entries)
Open questions
How to make inlineCommonChunks not to touch pure css chunks or chunks that will render css assets? Or do we want to?
rolldown-plugin-dts
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
hyfdev commentedon Aug 23, 2026
For reference, here is how
inlineCommonChunkscan affect CSS loading and cascade order withcssCodeSplit: true.Consider two dynamically loaded consumers that each have their own CSS and also import a shared stylesheet:
Without
inlineCommonChunks, Vite emits three CSS assets:shared.cssis loaded once. When the second consumer is loaded, Vite sees that the same CSS URL is already present and does not load it again.When
inlineCommonChunksselects the pure CSS common chunk, the module forshared.cssappears in both final JavaScript chunks. Vite collects CSS from each chunk'schunk.modules, so the output becomes:The separate
shared.cssrequest disappears, but its rules are transferred and parsed again when the second consumer is loaded. Because the second consumer's CSS asset is appended later, its copy of the shared rules also gets a later position in document order and can affect the cascade when declarations otherwise have equal precedence. Vite cannot deduplicate this at load time becauseA.cssandB.cssare different URLs.Webpack has the same behavior with
mini-css-extract-plugin. When shared CSS stays in the consumer chunks, its rules are emitted into both consumer CSS assets. When SplitChunks extracts it into a common CSS chunk, the shared stylesheet is loaded once instead.The CSS cascade is standardized, but the mapping from JavaScript imports and JavaScript chunks to emitted CSS assets is not. This behavior follows naturally from extracting CSS per final chunk and is not specific to Rolldown.
hyfdev commentedon Aug 24, 2026
For reference, selecting a "
dts" chunk withinlineCommonChunksis a correctness failure for the currentrolldown-plugin-dts, not only a change in output layout.The plugin stores each original declaration AST in an internal map and gives Rolldown fake, top-level JavaScript that preserves only its bindings and references. After chunking, its
renderChunkhook recognizes that top-level shape and turns it back into.d.tssyntax. The mechanism is described in the plugin's fake-JS implementation.When
inlineCommonChunksselects a shareddtschunk, its fake JavaScript is moved into a runtime factory. The resulting JavaScript has this shape:The current
renderChunkremoves expression statements, including the complete__share(...)factory. It also removes variable declarations that are not declaration encodings, includingshare_types_d. It still reconstructsApiResponse:The shared declaration is gone and
share_types_ddoes not exist, so the generated declaration bundle is invalid.This is simpler to avoid than the Vite CSS interaction. Declaration entries form a separate dependency graph, so an automatic
dtschunk containing a declaration module can be excluded as a whole. For example:excludeshould match module IDs and keep the whole candidate common chunk when any module matches.rolldown-plugin-dtscan add this pattern in itsoutputOptionshook, keeping declaration encodings out of runtime factories without requiring users to configure it manually.overlookmotel commentedon Aug 26, 2026
CSS
Broad thought
I don't know the historical reasons why CSS is dealt with this way. My guess is maybe Vite had to get what it needed from JS bundlers (Rollup, ESBuild) which it didn't control. Those bundlers dealt only with JS files, so Vite had to pretend CSS was JS.
My suspicion is that this approach doesn't entirely make sense any more. Vite and the bundler it uses (Rolldown) are now part of the same "family", so it'd now be feasible for the bundler to make CSS a first class citizen, and treat it with the correct semantics for CSS - which aren't the same as for JS.
It sounds to me like what we're missing is a kind of "strict execution order for CSS" or "strict cascade order".
I'm guessing the ultimate solution for these CSS problems will lie along these lines. However, obviously that's wildly out of scope for what we're talking about now (
inlineCommonChunks), so for now we need to figure out how to make the current situation work.The danger of surprise
We know that inlining chunks produces execution order hazards. But we have a tool to deal with that - strict execution order.
We have no such tool to deal with CSS.
If CSS participates in inline chunks, it can lead to CSS cascade order problems.
But that ISN'T the problem! The real problem is that the user can't control it, can't work around it, can't know when this problem will strike.
Here's an example:
maxSize, so the CSS is in a normal shared chunk.maxSize.This would be incredibly confusing to the user. They'll assume the cause is related to some CSS change, and go hunting for the bug. The last thing they'd expect is that a totally unconnected change to some JS screwed up the styles, so they'll be looking in all the wrong places. And even if they do manage to track it down, how do they fix it?
What to do?
In my opinion, we need to find a way to exclude CSS from chunk inlining.
I don't know what this looks like in practice, but maybe something like:
In the end, CSS can benefit from duplication/inlining, same as JS can. But IMO until we have some way to produce "strict cascade order", it feels like a recipe for really horrible DX.
More broadly: The problem space of the
inlineCommonChunksfeature is already broad, and I imagine we're going to hit a multitude of weird bugs and edge cases. Bringing CSS into the mix too early IMO widens what's already hard into really hard. I propose: Let's go for the big win of eradicating small JS chunks first, and defer dealing with CSS.(All the above is just my opinion, based on little knowledge of how Vite/Rolldown handle CSS, so I may have completely missed the point. Apologies if so.)
overlookmotel commentedon Aug 26, 2026
rolldown-plugin-dtsAgain, this is a situation where the starting point is not ideal, and we have to work around it.
rolldown-plugin-dtsis a completely insane hack! (no disrespect to the author, the insanity is inherited from the Rollup plugin)Can I just check one thing:
Are you saying that because it's a separate dependency graph, the
excludehere will have no effect whatsoever on the JS bundles?Is there any other circumstance in which
excludeoption would be useful? Or are we adding this option purely to supportrolldown-plugin-dts? If the latter, can we make it unstable or something, so we can remove it later when a different approach to DTS bundling becomes available?sapphi-red commentedon Aug 27, 2026
It is probably possible to workaround using CSS layers, although it can require many
@layers.hyfdev commentedon Aug 27, 2026
@overlookmotel Yes. The issue is only show we have a solution for it, but it's not something settled.
And just to tease you, we hard-code minify pass' logic to skip minifying the chunk ends with
.d.ts. (Seems we could do the same lolhyfdev commentedon Aug 27, 2026
For the CSS, I would say any complaint to the current bundle model(rolldown + webpack) is right and we should improve it. However, it's a separate step. In the scope of
inlineCommonChunks + css, I would consider there is no fundamental blocker for this area. Things that need to be done are pretty clear.inlineCommonChunksis not trying to invent a new css bundle model that's wrong, it just inherits what current has. It does not introduce any new negative situation as the situation already existed.@overlookmotel I think what you said is resonable, just to add more context
This situation already happened in the current css bundling model no matter in vite/webpack/turbopack. It's not something new that
inlineCommonChunksintroduced.I'm ok with this. We could provide a option or method to allow users to disable
inlineCommonChunksfrom touching css chunks if they think the behavior is negative.hyfdev commentedon Aug 27, 2026
Thought:
It seems we could always split the mix-up chunk into a pure css chunk and js chunk. In this case, enabling
inlineCommonChunksor not won't have difference in the css output.overlookmotel commentedon Aug 28, 2026
Personally I think hard-coded logic for
.d.ts(ugly though that is) might be preferable to adding a public option that's really only there to supportrolldown-plugin-dts. If we add that option, we have to support it (for whatever weird use cases people find for it).