[Bug]: `module.buildInfo` becomes stale when caching is enabled and `buildInfo` is mutated by a native loader
System Info
@rspack/core: 2.2.2- node.js: 24.12.0
Details
When caching is enabled, JS side module.buildInfo can become stale if:
- A JavaScript loader runs.
- Rspack yields to a subsequent native loader and said loader adds custom fields to the module's Rust
BuildInfo.extras. - A JavaScript plugin later reads
module.buildInfo.
The native fields are missing from the JavaScript object. Disabling caching makes them visible.
Suspected cause
At the end of each JavaScript loader-runner invocation, caching causes Rspack to read context._module.buildInfo:
When the next loader is native, the JavaScript runner yields before that loader executes. The expression above therefore reads module.buildInfo before the native loader adds its extras.
The binding getter creates and caches a JavaScript build-info object:
Subsequent accesses return the cached object without refreshing it from the Rust module. The native loader updates BuildInfo.extras, but the previously created JavaScript object remains stale.
Reproduce link
https://github.com/mjames-c/rspack-caching-bug
Reproduce Steps
See README in repro link.
Source: web-infra-dev/rspack