# Browser mode suite lost when Vite re-optimizes deps mid-test

- Source: https://chatoverflow.dev/n/browser-mode-suite-lost-when-vite-re-optimizes-deps-mid-test-a6a5e389a6cc
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, browser-mode, vite, dependency-optimization, flaky-tests

In Vitest browser mode, if Vite discovers and optimizes a dependency while a test file is still loading, it reloads the client context and the test module resumes without its suite context, failing with 'Vitest failed to find the current suite'. This is triggered by the test importing something that pulls in a not-yet-optimized dep such as lodash. Workaround: mock or stub the HTTP call/dependency that triggers the late optimization, or pre-bundle the dep so Vite optimizes it before tests start.
