Skip to content

Vite crash when switching between two significantly different branches - RangeError: Set maximum size exceeded #12062

@fc

Description

@fc

Describe the bug

In our case, by running vite in local dev and switching between our release branches with git checkout then we see the shell/vite crash and the browser die. It seems like HMR is not able to keep up with so many files changing so quickly.

Examination of the stack trace

It seems like since so many files change at the same time, it triggers this event handler many times:

watcher.on('add', (file) => {
handleFileAddUnlink(normalizePath(file), server)
})
watcher.on('unlink', (file) => {
handleFileAddUnlink(normalizePath(file), server)
})

The event handler is calling handleFileAddUnlink:

export async function handleFileAddUnlink(

Which subsequently calls updateModules:

Calls propagateUpdate at this line over-and-over again (10+ times according to stack trace):

if (propagateUpdate(importer, boundaries, subChain)) {

Then calls propagateUpdate one more time before hitting the RangeError:

const hasDeadEnd = propagateUpdate(mod, boundaries)

Finally, the exception/crash is triggered at this point:

boundaries.add({

Reproduction

not yet...

Steps to reproduce

  1. Checkout branch "A"
  2. Run yarn vite
  3. Checkout branch "B" that is significantly different than "A"
  4. Watch in the terminal and browser for the crash

System Info

Vite 4.1.1

Used Package Manager

yarn

Logs

boundaries.add({                                                                                                                                                                      
^

RangeError: Set maximum size exceeded
at Set.add (<anonymous>)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38291:20)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
at updateModules (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38231:28)
at handleFileAddUnlink (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38271:9)
at FSWatcher.<anonymous> (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:61281:9)
 at FSWatcher.emit (node:events:525:35)
at FSWatcher.emitWithAll (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:50325:8)
at FSWatcher._emit (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:50417:8)
at FSWatcher._remove (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:50680:50)
at FsEventsHandler.handleEvent (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:49529:16)
at FsEventsHandler.checkExists (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:49517:12)

I think the browser crash is possibly due to how HMR tries to do a full reload of the page but because the vite server crashed it shows Chrome as unavailable:
image

Possibly related stack trace that doesn't cause total crash

The stack trace below can happen but in an overlay and appears to be more recoverable.

When a lot of files change but not as many as when switching between our release branches, then it doesn't lead to a complete vite crash but it has this stack trace that displays in the vite overlay. I suspect that the stack trace below and the one above have a related cause (i.e., lots of files change):

Set maximum size exceeded
    at Set.add (<anonymous>)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38291:20)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at propagateUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38347:13)
    at updateModules (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38231:28)
    at handleHMRUpdate (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:38219:5)
    at FSWatcher.<anonymous> (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:61267:23)
    at FSWatcher.emit (node:events:525:35)
    at FSWatcher.emitWithAll (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:50325:8)
    at FSWatcher._emit (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:50417:8)
    at FsEventsHandler.handleEvent (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:49551:14)
    at FsEventsHandler.addOrChange (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js:49501:8)
    at FsEventsHandler.checkExists (file:///xxx/node_modules/vite/dist/node/chunks/dep-3007b26d.js

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions