Skip to content

inlineCommonChunks: handle downstream execution order problems #13

Open

Description

@overlookmotel

When a chunk is inlined, it doesn't only produce execution order problems in that chunk itself, it can also have knock-on effects on all later chunks which are loaded statically.

Example

Input:

// entry.js
import { a } from "./a.js";
import { b } from "./b.js";
console.log("loaded entry.js", a(), b());

// a.js
export const a = () => 10;
console.log("loaded a.js");

// b.js
export const b = () => 20;
console.log("loaded b.js");

Possible solution

If a.js is the module we want to duplicate, then we need a strict execution order-style workaround:

// entry.js
import { b, $initB } from "./b.js";

__shared("a", module => {
  const a = () => 10;
  console.log("loaded a.js");
  module.exports = { a };
});

const { helper } = __shared_require("a");

// Only run `b.js`'s side effects now
$initB();

console.log("loaded entry.js", a(), b());

// b.js
export const b = () => 20;
export const $initB = () => {
  console.log("loaded b.js");
};

How to appraoch this

I think we need to clarify:

  1. What's the intended output? (as above, or something else?)
  2. What is the shape of the internal implementation?

Activity

  1. hyfdev commented on Aug 27, 2026

    @hyfdev
    Member

    With #14, I assume the situation described in this issue won't exist?

  2. overlookmotel commented on Aug 28, 2026

    @overlookmotel
    Author

    I would say more that when strict execution order is enabled, we have the means to make it a non-issue. But we do still need to make sure we take this situation into account.

    My point is that we don't just need to make sure that the inlined code executes in the right order, we also need to make sure all chunks which are imported after what was previously import blah from "./common-ABC.js" have their side-effects executed after the inline chunk's side-effects.

    Previously those later chunks may not have required splitting into load-time / call-time sections. Once a chunk before them gets switched to being an inline chunk, now they do.

    This may be quite simple to handle, or quite complex - I don't know enough about Rolldown's internals to say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions