Skip to content

fix(vitest): inline solid-js and its consumers in jsdom tests - #434

Open
lxsmnsyc wants to merge 2 commits into
mainfrom
fix/369-client-test-inline-runtime-main
Open

lxsmnsyc wants to merge 2 commits into
mainfrom
fix/369-client-test-inline-runtime-main

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

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

In jsdom tests, packages that import solid-js/web, such as @solidjs/testing-library, now get the browser build under Deno. Before, render threw Client-only API called on the server side.

Cause

  • The client test setup kept solid-js external, along with the packages that use it.
  • External packages are loaded by the host runtime, not by Vite.
  • Deno does not pass Vitest's browser condition to worker threads (pool: 'threads'). Those threads resolved solid-js/web to the server build.

Changes

  • With ssr off, test mode now inlines solid-js and every package that lists it as a dependency or peer. They resolve through Vite's browser condition.
  • solid-js and the packages that use it are inlined together, so they share one copy of solid-js.
  • A user server.deps.inline list is merged with the plugin's. inline: true and a user external entry for solid-js are left alone.
  • With ssr: true, solid-js stays external as before.
  • The second commit sets test.sharedViteServer = false when test.projects is set and the option is unset. This ports fix(vitest): resolve each inline project's own config under Vitest 5 #370 from next.
    • Vitest 5 shares the root Vite server with inline projects by default. Those projects then never get the plugin's test settings, including the inline list above.
    • Without this commit, the reporter's multi-project setup still fails on Deno.
    • It is a separate commit, so it can be dropped if that change should go in on its own.

Known limit

  • The plugin finds a package that uses solid-js only if it depends on it directly. A package that reaches solid-js only through another such package is not inlined, and would still load its own copy.

Testing

  • Added examples/vite-6/tests/jsdom/testing-library.test.tsx, with its own vitest.jsdom.config.ts and a test:jsdom script. It runs with a resolve hook that removes browser and adds deno, the same as Deno.
    • Without the fix, it fails with the issue's error.
    • With the fix, it passes.
  • Added a pnpm run test:jsdom step to the Vitest workflow.
  • Ran the reporter's multi-project setup on Deno 2.9.6 with Vitest 5.0.1 and solid-js 1.9.4.
    • It fails on 2.11.14 with the same error.
    • It passes 3 of 3 with both commits.
  • tsc --noEmit passes.
  • The browser-mode example suite was not run locally, because Playwright's browser is not installed. The browser-mode config now excludes tests/jsdom/**.

🤖 Generated with Claude Code

lxsmnsyc and others added 2 commits October 19, 2026 10:17
DOM tests kept solid-js external, so packages without a `solid` export
condition (such as @solidjs/testing-library) were imported natively and
their own imports were resolved by the host runtime. Node gets the
`browser` condition from vitest's worker --conditions, but Deno does not
apply it in worker threads and resolves `deno`/`node`, so
@solidjs/testing-library loaded the server build of solid-js/web and
`render` threw "Client-only API called on the server side".

- Inline solid-js and the runtime consumers found by the vitefu crawl
  through test.server.deps.inline when the `ssr` option is off.
- Merge with a user inline list; skip for `inline: true` or a user
  external entry for solid-js. `ssr: true` keeps solid-js external.
- Add a jsdom suite to examples/vite-6 (`pnpm test:jsdom`) that emulates
  Deno's resolution with a Node resolve hook, and run it in CI.

Refs #369

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Vitest 5 defaults test.sharedViteServer to true. Inline projects then
reuse the root Vite server and take their test options from the raw root
block captured before any config hook runs, so the jsdom default, the
jest-dom setup file and server.deps never reach them. Set the option to
false when the root declares test.projects and leaves it unset, as
@solidjs/vite-plugin does since #370.

Refs #369

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: 5d6846c

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@434

commit: 5d6846c

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.

@solidjs/testing-library resolves @solidjs/web to the server build (isServer true) in jsdom tests under a multi-project vitest setup

1 participant