Skip to content

fix(test): pre-warm vite dep optimization for browser suites so mid-run re-optimize never reloads the tester (#389) - #422

Merged
omridevk merged 1 commit into
mainfrom
fix/389-vite-optimizer-prewarm
Aug 11, 2026
Merged

fix(test): pre-warm vite dep optimization for browser suites so mid-run re-optimize never reloads the tester (#389)#422
omridevk merged 1 commit into
mainfrom
fix/389-vite-optimizer-prewarm

Conversation

@omridevk

@omridevk omridevk commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • On cold CI runners, vite discovers a dependency mid-run, re-optimizes, and full-reloads the __vitest_test__ tester frame; vitest browser mode has no birpc reconnect (Browser mode: run hangs forever when a tester page dies without closing its websocket (no run-level deadline on createTesters) vitest-dev/vitest#10791), so the reload kills the whole package run. Root-caused with pw:protocol logging in comment on #389: prepareDuration: 61547ms on cold runners → Failed to fetch dynamically imported module on the in-flight test → Page.frameStartedNavigating navigationType:"reload"Inspector.detached "Render process gone."[vitest] Browser connection was closed / [birpc] rpc is closed.
  • Added browserOptimizeDeps() to @conciv/vitest-config (packages/vitest-config/src/reporters.ts), a single shared definition of optimizeDeps.include for deps known to be discovered late — currently lucide-solid, which resolves through vite-plugin-solid's 'solid' export condition and only gets pre-bundled once that plugin's own package crawl completes. This matches vitest's own suggested remediation (its custom logger literally recommends optimizeDeps.include when it detects a mid-run reload).
  • Wired optimizeDeps: browserOptimizeDeps() as a vite-level sibling of each browser project's test config in all six vitest browser projects: apps/conciv, packages/ui-kit-chat, packages/ui-kit-chat-tools, packages/ui-kit-system, packages/ui-kit-terminal, packages/extensions/terminal.

Investigation notes

  • Verified in @vitest/browser's dist that vitest's own vitest:browser:tests plugin already sets optimizeDeps.entries to the full set of browser test files + setup files via a config() hook, and that Vite's mergeConfig concatenates array-valued optimizeDeps.* fields across plugin config() hooks and the project config — so browserOptimizeDeps()'s include list additively extends vitest's own entries rather than fighting them.
  • Two riskier approaches were tried locally and reverted after they reproduced browser-death signatures on a clean, cold run:
    • Broadening optimizeDeps.entries to src/**/*.{ts,tsx} + test/**/*.{ts,tsx} globs pulled node-only unit-test helpers into the client dependency scan and broke the build entirely (UNLOADABLE_DEPENDENCY on fsevents).
    • Adding optimizeDeps.extensions: ['.jsx'] to force-optimize lucide-solid's raw JSX source caused vite to pre-bundle it without the solid-plugin's own JSX handling, producing invalid JS in the deps cache (Failed to parse source for import analysis... make sure to name the file with the .jsx or .tsx extension) and killing every subsequent browser test file with Failed to fetch dynamically imported module.
    • The final include-only change produces one benign Cannot optimize dependency: lucide-solid, present in client 'optimizeDeps.include' warning (vite-plugin-solid's own crawl already optimizes it through the 'solid' condition, so the explicit include is a documented no-op/safety net today) but does not affect test outcomes.

Test plan

  • env TURBO_CONCURRENCY=1 VITEST_MAX_FORKS=1 pnpm turbo run test --concurrency=1 --filter=@conciv/app --force on a cold .vite cache: 28/28 files, 105/105 tests, no "optimized dependencies changed" / reload messages in the log.
  • Same for @conciv/ui-kit-chat: 28/28 files, 145/145 tests, no reload messages.
  • env TURBO_CONCURRENCY=70% pnpm turbo run typecheck --filter=@conciv/vitest-config --filter=@conciv/app --filter=@conciv/ui-kit-chat --filter=@conciv/ui-kit-chat-tools --filter=@conciv/ui-kit-system --filter=@conciv/ui-kit-terminal --filter=@conciv/extension-terminal: all green.
  • pnpm exec oxfmt --check / pnpm exec oxlint on touched files: clean.
  • pnpm exec fallow audit --changed-since origin/main --format json: verdict pass, 0 introduced findings.
  • CI validation in progress on diag/389-app-browser (temporary lone-suite diagnostic branch, 7 runs triggered): watch for absence of the reload/birpc-closed signature across repeated cold runs.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved browser test setup across multiple application and UI packages.
    • Added consistent dependency optimization for browser-based test projects.
    • Maintained existing browser and Node test configurations.

…un re-optimize never reloads the tester (#389)

On cold CI runners, vite can discover a dependency mid-run (esbuild's
static scan can't resolve solid-conditioned packages like lucide-solid
until vite-plugin-solid's own optimizeDeps.include crawl catches up),
re-optimize, and full-reload the __vitest_test__ tester frame. Vitest
browser mode has no birpc reconnect, so that reload kills the whole
package run (vitest-dev/vitest#10791).

Add a shared browserOptimizeDeps() helper in @conciv/vitest-config that
declares the known late-discovered dep (lucide-solid) in
optimizeDeps.include as a sibling of each browser project's `test`
config, matching vitest's own suggested fix
("please add mentioned dependencies to your config's
`optimizeDeps.include` field manually"). Wired into every vitest
browser project: app, ui-kit-chat, ui-kit-chat-tools, ui-kit-system,
ui-kit-terminal, extensions/terminal.

Two riskier approaches were tried and reverted after they reproduced
the exact failure locally: a broad optimizeDeps.entries glob crawled
into node-only test helpers and broke the client scan (fsevents), and
forcing optimizeDeps.extensions: ['.jsx'] caused vite to pre-bundle
lucide-solid's raw JSX source without a transform, corrupting the
optimized output and killing the browser connection outright.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6bc74c9c-9cb2-4f61-9eec-a14df9ebc5dc

📥 Commits

Reviewing files that changed from the base of the PR and between c24f1e5 and 53c7cc1.

📒 Files selected for processing (7)
  • apps/conciv/vitest.config.ts
  • packages/extensions/terminal/vitest.config.ts
  • packages/ui-kit-chat-tools/vitest.config.ts
  • packages/ui-kit-chat/vitest.config.ts
  • packages/ui-kit-system/vitest.config.ts
  • packages/ui-kit-terminal/vitest.config.ts
  • packages/vitest-config/src/reporters.ts

📝 Walkthrough

Walkthrough

This PR adds a shared browserOptimizeDeps() helper in @conciv/vitest-config and applies it to multiple Vitest browser test projects in app and package configs.

Changes

Vitest browser optimizeDeps configuration

Layer / File(s) Summary
Shared browser optimizeDeps helper
packages/vitest-config/src/reporters.ts
Adds LATE_DISCOVERED_BROWSER_DEPS and exports browserOptimizeDeps(), which returns the browser dependency optimization include list.
Browser project config wiring
apps/conciv/vitest.config.ts, packages/extensions/terminal/vitest.config.ts, packages/ui-kit-chat-tools/vitest.config.ts, packages/ui-kit-chat/vitest.config.ts, packages/ui-kit-system/vitest.config.ts, packages/ui-kit-terminal/vitest.config.ts
Imports browserOptimizeDeps and sets optimizeDeps: browserOptimizeDeps() on the browser Vitest project in each configuration file.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • conciv-dev/conciv#417: Both PRs change the same Vitest config files and the shared packages/vitest-config/src/reporters.ts helper module for browser test setup.
  • conciv-dev/conciv#379: Both PRs update the same Vitest browser project configuration files, but they add different project settings.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the browser test dependency optimization fix and its purpose of preventing mid-run tester reloads.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/389-vite-optimizer-prewarm

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Pre-warms Vite browser-test dependencies to prevent mid-run optimizer reloads from disconnecting Vitest.

Changes:

  • Adds shared browserOptimizeDeps() configuration for lucide-solid.
  • Applies it to six browser-test projects.
  • Three applicable browser projects remain unconfigured.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/vitest-config/src/reporters.ts Adds the shared optimization helper.
apps/conciv/vitest.config.ts Enables dependency pre-warming.
packages/ui-kit-chat/vitest.config.ts Enables dependency pre-warming.
packages/ui-kit-chat-tools/vitest.config.ts Enables dependency pre-warming.
packages/ui-kit-system/vitest.config.ts Enables dependency pre-warming.
packages/ui-kit-terminal/vitest.config.ts Enables dependency pre-warming.
packages/extensions/terminal/vitest.config.ts Enables dependency pre-warming.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


const LATE_DISCOVERED_BROWSER_DEPS = ['lucide-solid']

export function browserOptimizeDeps(): {
@omridevk
omridevk merged commit 7b59af1 into main Aug 11, 2026
47 checks passed
@omridevk
omridevk deleted the fix/389-vite-optimizer-prewarm branch August 11, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants