Skip to content

fix(vitest): keep the browser condition out of Node in DOM tests - #438

Open
lxsmnsyc wants to merge 1 commit into
fix/369-client-test-inline-runtime-mainfrom
fix/125-msw-node-conditions-main
Open

lxsmnsyc wants to merge 1 commit into
fix/369-client-test-inline-runtime-mainfrom
fix/125-msw-node-conditions-main

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

Fixes #125 on main (1.x). The fix for next is in a separate PR.

This PR is based on #434 (the #369 fix) and needs it. Merge #434 first. GitHub then retargets this PR to main.

In jsdom and happy-dom tests, Node-only packages such as msw/node now load. Before, setupServer from msw/node failed with Package subpath './ClientRequest' is not defined by "exports".

Cause

  • In test mode the plugin added the browser condition to every Vite environment, including ssr.
  • Vitest 4 and later passes the ssr environment's conditions to Node as --conditions for the packages it leaves external.
  • Node then picked browser exports for those packages. @mswjs/interceptors exports null for browser on ./ClientRequest.

Changes

  • In jsdom and happy-dom runs, the ssr environment no longer gets the browser condition. The client environment keeps it.
  • This is safe only because fix(vitest): inline solid-js and its consumers in jsdom tests #434 inlines Solid and the packages that use it. Without that, removing browser makes @solidjs/testing-library load the server build.
  • Browser mode, the node and edge-runtime environments, ssr: true, and a user external entry for solid-js are unchanged.

Testing

  • Reproduced with msw 3.0.3 and a jsdom test that calls setupServer. It fails without the fix on Vitest 5.0.5 and 4.1.12.
  • With the fix, the msw test passes, and testing-library render, click and router tests still pass.
  • Added examples/vite-6/tests/node-conditions.mjs, run by test:jsdom. It fails without the fix. pnpm test:jsdom passes.
  • Vitest 3 is not fixed. There, Vite applies browser to the client environment itself, which DOM tests need. The changeset says "Vitest 4 and later".

🤖 Generated with Claude Code

- Vitest passes the ssr environment's conditions to Node as `--conditions` for external packages.
- The plugin added `browser` to every environment in test mode, so Node resolved `browser` exports too.
- `msw/node` failed because `@mswjs/interceptors/ClientRequest` exports `null` for `browser`.
- DOM tests run in the client environment, and the Solid runtime is now inlined, so the ssr environment no longer gets `browser` in jsdom and happy-dom runs.
- Tests with `environment: 'node'`, browser mode, `ssr: true`, or a user `external` entry for solid-js keep the old conditions.

This builds on the runtime inlining from #434.

Fixes #125

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 765a406

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
vite-plugin-solid Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/vite-plugin-solid@438

commit: 765a406

@ryansolid ryansolid added the 1.x label Oct 21, 2026 — with Claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants