Skip to content

fix: keep renderModule order consistent#19867

Merged
alexander-akait merged 7 commits intowebpack:mainfrom
xiaoxiaojx:render-order-issue
Sep 5, 2025
Merged

fix: keep renderModule order consistent#19867
alexander-akait merged 7 commits intowebpack:mainfrom
xiaoxiaojx:render-order-issue

Conversation

@xiaoxiaojx
Copy link
Copy Markdown
Member

What kind of change does this PR introduce?
Fixes #19861 (comment)

The order of Compilation.modules depends on when module.build finishes, which leads to unstable ordering and different results during render.
We could consider changing Compilation.modules to a SortableSet to make the order deterministic.

Did you add tests for your changes?
Yes

Does this PR introduce a breaking change?
No

What needs to be documented once your changes are merged?
No

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Sep 2, 2025

CodSpeed Performance Report

Merging #19867 will degrade performances by 46.05%

Comparing xiaoxiaojx:render-order-issue (b06ad21) with main (7ddc38a)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 40 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
benchmark "devtool-eval", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 44.7 ms 82.9 ms -46.05%
benchmark "many-chunks-commonjs", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 139.8 ms 111.3 ms +25.61%

@xiaoxiaojx

This comment was marked as outdated.

@xiaoxiaojx
Copy link
Copy Markdown
Member Author

@JSerFeng I think your suggestion of "sort modules first before render" is a good one. However, after internal discussions, the team is more inclined to use the approach of import { v as v_xxxx }. This is because import "as" syntax is analyzable by all bundlers(Though it’s a bit lengthy and clunky 😅).

While this solution cannot completely avoid naming conflicts in the chunk scope, the probability of such conflicts is negligible.

import { v as __WEBPACK_EXTERNAL_MODULE_externals0_v__ } from "externals0";
import { v as __WEBPACK_EXTERNAL_MODULE_externals1_v__ } from "externals1";

@alexander-akait
Copy link
Copy Markdown
Member

@JSerFeng In future we will think about it more deeply (maybe with some design changes), we still want to generate as small and analyzable code as possible, but we want to make a release soon, so current changes fix almost all cases

@JSerFeng
Copy link
Copy Markdown
Contributor

JSerFeng commented Sep 5, 2025

While this solution cannot completely avoid naming conflicts in the chunk scope, the probability of such conflicts is negligible.

Yeah it's okay, previous external namespace symbol has little chance to conflicts as well.

We've thought of this solution as well, the main reason Rspack currently not doing this is because Rspack is heading to a completely new esm output format implementation

As for three shaking, currently the original namespace importing external is also analyzable by popular bundler, I change the render of external module mainly because Rslib wants the more pretty output.

It's totally fine to fix this for now ❤️

@alexander-akait alexander-akait merged commit 57a8ebd into webpack:main Sep 5, 2025
42 of 44 checks passed
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