Skip to content

[Bug]: MultiCompiler lazy compilation invalidates unrelated compilers #14779

Description

@Kanary-channelio

System Info

System:
  OS: macOS 26.5.1
  CPU: arm64 Apple M5
Binaries:
  Node: 26.0.0
  Yarn: 4.9.4
  npm: 11.12.1
npmPackages:
  @rspack/cli: 2.1.3
  @rspack/core: 2.1.3
  @rspack/dev-server: 2.1.0

The same implementation is present on the current main branch.

Details

When lazyCompilationMiddleware receives a MultiCompiler, it correctly finds each child compiler that has lazyCompilation enabled, but it creates the request middleware with the parent MultiCompiler:

lazyCompilationMiddlewareInternal(compiler, activeModules, options.prefix)

When a lazy module is activated, the internal middleware calls:

compiler.watching.invalidate()

Because compiler is the parent MultiCompiler, MultiWatching.invalidate() invalidates every child compiler, including compilers that do not use lazy compilation.

In our application, activating a lazy route in the web compiler also caused an unrelated worker compiler to participate in the update cycle. Its HMR client could then request worker hot updates or contribute an unaccepted update that falls back to a full page reload.

Expected behavior: activating a lazy module invalidates only the child compiler that owns that lazy-compilation configuration.

Changing the MultiCompiler branch to pass c fixes the behavior while preserving normal updates when worker source files actually change:

- lazyCompilationMiddlewareInternal(compiler, activeModules, options.prefix)
+ lazyCompilationMiddlewareInternal(c, activeModules, options.prefix)

Reproduce link

A pull request with a focused MultiCompiler regression test will be linked to this issue.

Reproduce Steps

  1. Create a MultiCompiler with two child compilers.
  2. Enable lazyCompilation only on the first child compiler.
  3. Start both compilers in watch mode and install lazyCompilationMiddleware(multiCompiler).
  4. Send a POST request to /_rspack/lazy/trigger__0 with a previously inactive module key.
  5. Observe that the parent MultiWatching.invalidate() is called and both child compilers enter the update cycle.
  6. Change the middleware argument from the parent compiler to the lazy-enabled child c.
  7. Repeat the request and observe that only the lazy-enabled child compiler is invalidated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions