Skip to content

fix(vitest): load client solid-js in node-env files of DOM test runs - #535

Merged
ryansolid merged 1 commit into
mainfrom
fix/534-node-env-browser-condition
Nov 10, 2026
Merged

ryansolid merged 1 commit into
mainfrom
fix/534-node-env-browser-condition

Conversation

@brenelz

@brenelz brenelz commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #534.

Since 2.11.15, a test file with // @vitest-environment node loads the server build of solid-js when test.environment is jsdom or happy-dom. In that file isServer is true and effects never run.

Root cause

The fix for #125 (765a406) removed the browser condition from the whole ssr environment in DOM test runs, so that Node would not get browser in its --conditions. But Vitest runs per-file node environment files in the ssr environment, and solid-js is inlined there, so Vite resolved it without browser and picked the server build.

Vitest builds Node's --conditions from the resolved config.ssr.resolve.conditions (Vitest 3 and 5 both read it). Vite 6, 7 and 8 fill that field from a separate copy of the ssr environment's conditions, and Vite does not read it again after resolving.

Change

  • configEnvironment adds browser to the ssr environment in test mode again, as 2.11.14 did. It is no longer added a second time when the list already has it.
  • In DOM test runs, configResolved removes browser from config.ssr.resolve.conditions only, which is the list Vitest passes to Node. The ssr environment keeps it. A browser condition the user set on ssr is left in place, and nothing changes if that field turns out to be the same object as the environment's.

Node-env files then load the client build of solid-js, and msw/node still loads in both node and DOM files.

Verification

The reporter's setup (vite 8.3.6, vitest 5.1.0, happy-dom 21.0.4, solid-js 1.9.18), with node-env and DOM files plus msw/node imports in each, run against the packed plugin:

Plugin node-env files msw/node files
2.11.14 pass fail to load
2.11.15 fail pass
this PR pass pass

A mixed suite of 25 DOM files and 25 node-env files passes three runs out of three, with and without --no-isolate. On 2.11.15 only the node-env files failed. I could not reproduce the intermittent DOM-file failures described in the issue.

New tests, which fail without the fix:

  • examples/vite-6/tests/jsdom/node-environment.test.tsx, a // @vitest-environment node file in the jsdom suite (pnpm test:jsdom).
  • Three cases in src/test-config.test.ts (pnpm test:unit, 17/17 pass).
  • examples/vite-6/tests/node-conditions.mjs, updated: the ssr environment keeps browser and Node's conditions do not.

The browser-mode example suite did not run locally because the Playwright browser was missing. It runs in the client environment, which this change does not touch.

Open

The plugin keeps its test-mode flags on the plugin instance across config, configEnvironment and configResolved. If two config resolutions run at once on one instance they can read each other's flags. The domTestRuntimeInlined flag from 2.11.15 already had this, and this PR does not change it.

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d373e4f

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 Nov 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: d373e4f

@brenelz brenelz added the 1.x label Nov 9, 2026
@ryansolid
ryansolid merged commit 1ea0fba into main Nov 10, 2026
6 checks passed
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.11.15: files with // @vitest-environment node load the solid-js server build when test.environment is a DOM one

2 participants