Skip to content

Vitest browser tests hang on navigation or form submission #8583

@bteng22

Description

@bteng22

Describe the bug

When running Vitest in browser mode, tests that trigger navigation or execute the default function of an onSubmit handler will hang indefinitely. This appears to happen because the test browser attempts to navigate away potentially causing the test runner to lose connection with the underlying node process. There doesn't seem to be clear documentation or guidance about how to handle or prevent these hangs in browser-enabled tests.

Reproduction

External reproduction: https://github.com/bteng22/vitest-browser-hangs-repro

Steps to reproduce:

  1. Clone the reproduction repository: https://github.com/bteng22/vitest-browser-hangs-repro
  2. Follow the instructions in the README to install dependencies and run the browser tests.
  3. Observe that when a navigation is triggered (via e.g. a form's default onSubmit), the test hangs and never completes.

Actual behaviour:

Vitest browser tests hang forever when navigation or a default onSubmit handler is triggered. The test never completes and requires manual intervention to stop. This includes programmatic navigations as well with window.location.assign or window.history.pushState

Expected behaviour:

Vitest browser tests should not hang or lose connection with the node process when navigation or form submission occurs. There should be clear documentation or built-in handling for these situations, or at least guidance on best practices for preventing such hangs in browser-enabled tests?

System Info

System:
    OS: macOS 15.6.1
    CPU: (16) arm64 Apple M3 Max
    Memory: 322.59 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.7.0 - ~/.nvm/versions/node/v23.7.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v23.7.0/bin/npm
  Browsers:
    Chrome: 140.0.7339.133
    Edge: 140.0.3485.66
    Safari: 18.6
  npmPackages:
    @vitejs/plugin-react: ^4.7.0 => 4.7.0 
    @vitejs/plugin-react-swc: ^3.11.0 => 3.11.0 
    @vitest/browser: 3.2.4 => 3.2.4 
    @vitest/ui: 3.2.4 => 3.2.4 
    playwright: 1.54.2 => 1.54.2 
    vite: 7.0.6 => 7.0.6 
    vitest: 3.2.4 => 3.2.4 
    vitest-browser-react: 1.0.1 => 1.0.1

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browserIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    Status

    Has plan

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions