Skip to content

[Bug]: lazy compilation: import() of a module that accepts its own updates keeps resolving to its first namespace #16594

Closed

Description

@Sheraff

Written by an AI coding agent (Claude) on behalf of a TanStack Router maintainer; reproduced locally.

System Info

System: Linux 6.12 x64 (Debian 13)
Binaries: Node 26.12.1, npm 12.2.0
npmPackages: @rsbuild/core 2.3.2, @rspack/core 2.3.2

Details

With lazy compilation on (Rsbuild's dev default), a module loaded with import() that accepts its own updates evaluates again on each edit, but a later import() of it keeps resolving to the namespace of its first evaluation. With dev.lazyCompilation: false, it resolves to the new one.

// src/index.js
const show = async () => {
  const m = await import('./value.js')
  document.getElementById('app').textContent = 'import() answers ' + m.value
}
window.__show = show
show()
// src/value.js (edited to v2, then v3)
export const value = 'v1'
;(window.__evals ??= []).push('v1')
if (import.meta.webpackHot) {
  import.meta.webpackHot.accept()
}
setTimeout(() => window.__show?.(), 0) // import it again after each evaluation

Actual (lazy compilation on):

start:  import() answers v1
edit 2: import() answers v1   (value.js evaluated: v1,v2; page reloaded: no)
edit 3: import() answers v1   (value.js evaluated: v1,v2,v3; page reloaded: no)

Expected, as with dev.lazyCompilation: false:

start:  import() answers v1
edit 2: import() answers v2   (value.js evaluated: v1,v2; page reloaded: no)
edit 3: import() answers v3   (value.js evaluated: v1,v2,v3; page reloaded: no)

The lazy proxy makes a new namespace promise only in its hot.accept(<id>, () => hot.invalidate()) handler (module.rs), which a module that accepts itself never reaches.

We hit this with solid-refresh, which adds import.meta.webpackHot.accept() to modules that hold components.

Reproduce link

https://github.com/Sheraff/rspack-lazy-self-accept-import

Reproduce Steps

  1. npm install
  2. npm run repro: starts the Rsbuild dev server, opens the page in headless Chromium (playwright-core), edits src/value.js twice, prints what import() answers; exits 1
  3. npm run control: same with dev.lazyCompilation: false; exits 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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