Skip to content

HMR errors inconsistently sent to multiple tabs #19710

@infiton

Description

@infiton

Describe the bug

This error is possible to reproduce on a brand new vite app.

Steps.

  1. create a vanilla vite app with npm create vite@latest
  2. run npm run dev
  3. Open the app in a tab
  4. introduce the following syntax error in counter.ts
export function setupCounter(element: HTMLButtonElement) {
  let counter = 0;
  const setCounter = (count: number) => {
    counter = count;
    element.innerHTML = `count is ${counter}`;
  };
  element.addEventListener("click", () => setCounter(counter + 1));
  setCounter(0);
  1. notice that you get an hmr overlay in first tab showing the error
  2. open the app in a second tab; you just get a white screen, until you hit refresh in the first tab, now you will see the hmr overlay in the second tab but not the first

Note that sometimes this doesn't happen, but 2 or 3 attempts of the above tab opening steps above should reproduce it. It's also possible to trigger it with two open tabs in the error state and refreshing one repeatedly; sometimes on refresh you get a white screen and the hmr error is not sent on the websocket until the other tab is refreshed.

Reproduction

https://vite.new/

Steps to reproduce

detailed in the above description

System Info

can reproduce on stackblitz and locally with 


  System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 116.09 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.9.0 - /opt/homebrew/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.3 - /opt/homebrew/bin/npm
    pnpm: 8.15.7 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 134.0.6998.118
    Safari: 17.5

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions