Skip to content

[Bug]: codeSplitting rewrites side-effects across entry points #9450

Description

@susnux

Reproduction link or steps

https://repl.rolldown.rs/#eNqVUtuK2zAQ/ZVBL05C6qR9NGyh9PK0S6DtW12Kao0TgT1jJHmzi/G/r2RFTsJeYPUgRnM5OnNmBlGLYhCGm0bxkfKKqdb73NngJVG8FFmLygd027Fx4B47hAF+ntJ2ndNMFkaoDbeQpfKspJI2qxWsNiV5KOsgAhbPSm9gKAlAU9e7ItoAsoBMk8IHTyBbR9//5PvwafaO0829uyyuWOGvrtHOafIfnrwAe8N9Zwv4kxxwjoVDssUCSlFx2zKV4vRvPEjOaLRfjtL4JGd6fDV8h2aPvw8G7YEbVcDH7b/tdnuRPibzbzRiF+H2kZLwYZJaYS37JgknxrVIiqRhze+rEQ1QM88TyTf24DmpIFkAV1z1rWebS6W+33vjVluHhGaRfdvdfWXyD3fLUqHK1rBYws3nqJIHXSyDEcbJDeZoDPuqeUw+OC49FRRFkCfxnaZ1xTh6Iuf30ZH2kapLUnG1WlZ9g36T5FFqB1GHxVXrE/OYl7/ZybRbsRXfwQyQGjg7Iv/TrOqeqrDOUaUztwv0H7vdhFuSGD3yvS9upEPrxPgEZhoqVA==

What is expected?

The side effects (event listener registration) should only be performed in each entry point.
Meaning if loading "a" then only console.error("index.ts"); should be executed and not console.error("index2.ts");

What is actually happening?

Both side effects are combined into the same chunk and thus both entry points will execute both side effects.

System Info

Binaries:
    Node: 24.14.0
    npm: 11.9.0

Any additional comments?

The idea behind the chunking was to reduce the total number of chunks by merging all related code into common chunks. In my actual use case I have 3 entry points but rolldown generates 19 output chunks.

So I hoped to tweak rolldown to generate at most 7 chunks:

  • entry1: all code and dependencies only used by entry 1
  • entry2: all code and dependencies only used by entry 1
  • entry3: all code and dependencies only used by entry 1
  • chunk12: code shared with entry1 and 2
  • chunk13: code shared with entry1 and 3
  • chunk23: code shared with entry2 and 3
  • chunk123: code shared with entry1, 2 and 3

Metadata

Metadata

Assignees

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions