Skip to content

[Bug]: incorrect chunking with strictExecutionOrder: true when sideeffectful chunk exists #4684

@sapphi-red

Description

@sapphi-red

Reproduction link or steps

  1. Open https://stackblitz.com/edit/github-nci4o6nk-yfztxytw?file=rolldown.config.mjs,package.json,src%2Fread.js
  2. pnpm i runs automatically
  3. pnpm run build runs automatically
  4. Run node src/index.js
  5. Run node dist/index.js

What is expected?

node dist/index.js behaves the same with node src/index.js.
In other words, node dist/index.js outputs:

read foo
read foo

What is actually happening?

node dist/index.js behaves differently from node src/index.js.
In other words, node dist/index.js outputs:

read undefined

System Info

StackBlitz

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @rolldown/browser:  1.0.0-beta.9-commit.273d50e

Any additional comments?

The plugin marks files other than index.js / setup.js as sideeffect free. If I do not mark read.js as sideeffect free, the output is correct. Even in that case, if I wrap globalThis.foo with a pure annotated IIFE, the output is wrong.

I think the missing limitation that should apply here is: "a side-effect-free module that may depend on a side-effectful module should not be reordered."

refs #4617

Probably related to #4670 cc @hyf0

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions