tivac/modular-css

rollup plugin does incorrect CSS chunking

tivac opened this issue · 1 comments

tivac commented

Expected Behavior

When creating files that contain a dep graph like this:

a.js -> a.css -> c.css
b.js -> b.css -> c.css

the rollup plugin should create a.css, b.css, and c.css in the output since c.css is required by both a.css and b.css

Current Behavior

a.css contains both a.css and c.css, and b.css contains just b.css.

Possible Solution

// How does Set not have .filter yet ಠ_ಠ
const included = [ ...css ].filter((file) => !queued.has(file));

This code is intended to prevent CSS from being output multiple times, which is a good idea. Unfortunately it also means that any particular CSS file will only be output once, in the first JS-triggered chunk that depends on it.

Instead the plugin should look at the JS chunk graph & the CSS chunk graph & figure out the minimal set of CSS chunks that satisfies all the dependencies.

Steps to Reproduce (for bugs)

https://gist.github.com/tivac/43b94e87927d8838305f2ae88fb0d789

Context

This issue means that it isn't safe to use import() with code that has CSS dependencies

Your Environment

Executable Version
modular-css v22.0.0
npm --version 6.5.0
node --version 10.15.0
tivac commented

Almost done fixing this in the corrected-chunking branch.