Skip to content

First page load fails when HMR WebSocket misses deps reload message #21349

@williamhogman

Description

@williamhogman

Describe the bug

In remote development environments with cold starts, the first page load sometimes fails because the HMR deps reload message is sent before the WebSocket connection is established. The client never receives it.

This issue is more frequent in v7 than v5.

**Suggested fix (per discussion with @yyx990803):**Buffer HMR messages until WebSocket connection is confirmed established.

Context:
Discussed with Evan in Slack who confirmed the diagnosis and requested an issue to track.

Reproduction

This is a timing-dependent issue in remote/containerized environments with cold starts - difficult to reproduce in standard setups. Discussed with @yyx990803 in Slack who confirmed the diagnosis and requested this issue be filed to track. Happy to provide demo access to our environment.

Steps to reproduce

  1. Run Vite dev server in a remote/containerized environment
    1. Let it go cold (idle timeout)
    1. Load the page on cold start
    1. First request to deps sometimes fails - the reload message is sent before WebSocket is established

System Info

System:
    OS: Linux 4.4 undefined
    CPU: (16) x64 unknown
    Memory: 31.79 GB / 32.00 GB
    Container: Yes
    Shell: Unknown
  Binaries:
    Node: 22.21.1 - /nix/var/nix/profiles/sandbox/bin/node
    npm: 10.9.4 - /nix/var/nix/profiles/sandbox/bin/npm
    pnpm: 10.25.0 - /nix/var/nix/profiles/sandbox/bin/pnpm
    bun: 1.3.2 - /nix/var/nix/profiles/sandbox/bin/bun
    Deno: 2.5.6 - /nix/var/nix/profiles/sandbox/bin/deno

Used Package Manager

bun

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions