Skip to content

viewport does not reset between test suite runs in headless browser modeΒ #7649

Closed

Description

@kwojcik

Describe the bug

Something about the viewport persists between test suite runs (using r to re-run), causing tests that depend on scrolling and IntersectionObserver to fail if the suite re-runs. Only fails in headless browser mode, it passes in headed mode.

Reproduction

The test in the repro uses IntersectionObserver to detect when something comes into the viewport. The test checks that the top element is visible and scrolled to, then scrolls to the bottom and checks that the bottom element is visible and scrolled to. When re-running the suite, however, the top element appears to be visible according to getBoundingClientRect but the IntersectionObserver does not fire. Scrolling to the first element at the start of the test "fixes" this.

repro branch: https://github.com/kwojcik/vitest/tree/viewportBug

cd examples/basic
npm install
npm run test test/suite.test.tsx

Test passes the first time, but hit r to run again and it fails.

System Info

System:
    OS: macOS 15.3.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 20.00 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.1 - ~/.asdf/installs/nodejs/20.18.1/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.5.0 - /opt/homebrew/bin/pnpm
    Watchman: 2024.08.12.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 134.0.6998.45
    Firefox Nightly: 127.0
    Safari: 18.3
  npmPackages:
    @vitest/browser: latest => 3.0.8
    @vitest/ui: latest => 3.0.8
    playwright: ^1.50.1 => 1.51.0
    vite: latest => 6.2.1
    vitest: latest => 3.0.8

Used Package Manager

npm

Validations

Activity

  1. added
    feat: browser
    p3-minor-bug
    and removed on Mar 11, 2025
  2. added theissue type on Mar 11, 2025
  3. moved this to Approved in Team Boardon Sep 4, 2025
  4. locked and limited conversation to collaborators on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browserp3-minor-bug

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions