Skip to content

[Bug]: module.buildInfo becomes stale when caching is enabled and buildInfo is mutated by a native loader #15442

Description

@mjames-c

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:

  1. A JavaScript loader runs.
  2. Rspack yields to a subsequent native loader and said loader adds custom fields to the module's Rust BuildInfo.extras.
  3. 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:

if (compiler.options?.cache) {
commitCustomFieldsToRust(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:

fn module_build_info_getter(ctx: CallContext) -> napi::Result<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.

Activity

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

Metadata

Metadata

Assignees

Labels

pending triageThe issue/PR is currently untouched.

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions