Skip to content

[FIX] lbt/bundle/Resolver: Ensure deterministic ordering of raw modules#1208

Merged
matz3 merged 1 commit into
v4from
v4-lbt-fix-raw-module-order
May 8, 2026
Merged

[FIX] lbt/bundle/Resolver: Ensure deterministic ordering of raw modules#1208
matz3 merged 1 commit into
v4from
v4-lbt-fix-raw-module-order

Conversation

@matz3

@matz3 matz3 commented May 8, 2026

Copy link
Copy Markdown
Member

When multiple raw modules share a common dependency, the topological sort tie-breaks by input order. Previously, the input order depended on async resolution timing (pool insertion order), making the output non-deterministic.

Now modules are sorted by their filter definition order before topological sorting, ensuring that modules at the same dependency level appear in the order defined by the section's filter list.

When multiple raw modules share a common dependency, the topological
sort tie-breaks by input order. Previously, the input order depended
on async resolution timing (pool insertion order), making the output
non-deterministic.

Now modules are sorted by their filter definition order before
topological sorting, ensuring that modules at the same dependency
level appear in the order defined by the section's filter list.
@matz3 matz3 requested a review from a team May 8, 2026 10:30
@codeworrior

Copy link
Copy Markdown
Member

As long as you don't assume any semantic behind this order (e.g. to compensate for not-declared dependencies), I'm fine with it. IMO, sorting the modules alphabetically would also result in a stable order.

@matz3

matz3 commented May 8, 2026

Copy link
Copy Markdown
Member Author

Well, I think there can be cases in which you want a specific order, and sorting alphabetically would break it:

Library1 provides 2 raw modules:

  • raw-dep.js
  • raw-module1.js (depends on raw-dep.js)

Library2 (depends on Library1) provides 1 raw module and owns the bundle config:

  • raw-module2.js (depends on raw-dep.js)

Filters in raw section (with resolve: true):

  • raw-module2.js
  • raw-module1.js

Expected raw-module order:

  • raw-dep.js
  • raw-module2.js
  • raw-module1.js

Maybe I'm missing something, but in this case I do not see a way to ensure that raw-module2.js comes before raw-module1.js, and sorting alphabetically would make it deterministic, but would always add module1 before module2.

@codeworrior

codeworrior commented May 8, 2026

Copy link
Copy Markdown
Member

As I didn't immediately got the point of Matthias' (valid) scenario:
There might be cases, where dependencies can't be declared, e.g.

  • they would have to be declared in places, where they can't be declared (e.g. apps don't have a .library file)
  • they would be "forward" declarations, creating a cycle (in Matthias' example, a dependency from a module of lib 1 to a module of lib 2 can'T be declared in lib 1 as it should not "know" lib 2.

There are other solutions for this problem (e.g. two "raw" sections"). But I agree that retaining the order of the filters as long as dependency order is honoured first, is a much simpler mechanism.

@matz3 matz3 merged commit 88953bc into v4 May 8, 2026
19 checks passed
@matz3 matz3 deleted the v4-lbt-fix-raw-module-order branch May 8, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants