Skip to content

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

Merged
ryansolid merged 1 commit into
nextfrom
fix/125-msw-node-conditions
Oct 21, 2026
Merged

ryansolid merged 1 commit into
nextfrom
fix/125-msw-node-conditions

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

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

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

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 the Solid runtime and its consumers in client tests #433 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 a vitest/ssr-conditions check to examples/start-ssr/test/run.mjs. It fails without the fix. node test/run.mjs vitest passes 8/8 and pnpm test:unit 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.
- In the client test posture the plugin added `browser` to every environment, so Node resolved `browser` exports too.
- `msw/node` failed because `@mswjs/interceptors/ClientRequest` exports `null` for `browser`.
- jsdom and happy-dom tests run in the client environment, and the Solid runtime is now inlined, so the ssr environment no longer gets `browser` in those runs.
- The server posture, browser mode, and a user `external` entry for solid-js keep the old conditions.

This builds on the runtime inlining from #433.

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: a6cae59

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

This PR includes changesets to release 1 package
Name Type
@solidjs/vite-plugin 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/@solidjs/vite-plugin@437

commit: a6cae59

@ryansolid
ryansolid changed the base branch from fix/369-client-test-inline-runtime to next October 21, 2026 15:58
@ryansolid
ryansolid merged commit 67a3812 into next Oct 21, 2026
4 checks passed
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