Skip to content

fix(bundled-dev): avoid stack overflow on import.meta.hot.invalidate()#22797

Open
shulaoda wants to merge 1 commit into
mainfrom
06-28-fix_bundled-dev_avoid_stack_overflow_on_import.meta.hot.invalidate_
Open

fix(bundled-dev): avoid stack overflow on import.meta.hot.invalidate()#22797
shulaoda wants to merge 1 commit into
mainfrom
06-28-fix_bundled-dev_avoid_stack_overflow_on_import.meta.hot.invalidate_

Conversation

@shulaoda

Copy link
Copy Markdown
Member

Problem

In bundled dev mode (experimental.bundledDev), calling import.meta.hot.invalidate() from a client crashes the dev server with RangeError: Maximum call stack size exceeded.

Root cause

DevEnvironment.invalidateModule should hand off to the BundledDev instance when in bundled mode, but it calls itself instead:

// packages/vite/src/node/server/environment.ts
if (this.bundledDev) {
  this.invalidateModule(m, _client) // ← calls itself
  return
}

this.bundledDev stays truthy on re-entry, so it recurses forever and overflows the stack. It is reachable from the vite:invalidate handler registered in the constructor, which fires on every client import.meta.hot.invalidate().

Fix

  if (this.bundledDev) {
-   this.invalidateModule(m, _client)
+   this.bundledDev.invalidateModule(m, _client)
    return
  }

BundledDev.invalidateModule is async; the surrounding method is void, so this is fire-and-forget, matching the previous behavior.

Test

Added an e2e regression test in playground/hmr-full-bundle-mode:

  • invalidation-child.js self-accepts and calls import.meta.hot.invalidate().
  • invalidation-parent.js imports it and accepts, so the edit produces an in-place Patch, which is what makes the server log hmr invalidate.
  • The test edits the child and asserts the server logs hmr invalidate.

Before the fix the server crashes (no hmr invalidate log); after, it is handled.

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.

1 participant