Skip to content

fix: compile server transforms with SSR output when ssr is off - #448

Open
lxsmnsyc wants to merge 2 commits into
mainfrom
fix/64-ssr-codegen-without-ssr-option-main
Open

lxsmnsyc wants to merge 2 commits into
mainfrom
fix/64-ssr-codegen-without-ssr-option-main

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

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

Without ssr: true, modules loaded on the server are now compiled to SSR output. A client-rendered app can now prerender pages with ssrLoadModule. Before, those modules were compiled to DOM output and threw Client-only API called on the server side.

Changes

  • When ssr is off, server transforms use generate: 'ssr' with hydratable: false.
  • Client transforms are unchanged. With ssr: true the behavior is unchanged.
  • No existing option allowed this. solid.generate also applies to the client, and a babel function cannot replace the preset.
  • The ssr option's JSDoc and README entry describe the new behavior.
  • In Vitest, server transforms keep DOM output. On main, Vitest adds the browser condition, so solid-js/web resolves to the browser build, where ssr() is an empty stub. Keeping DOM output avoids breaking DOM tests that run in environment: 'node'.

Note on the first commit

The first commit adds the Vitest unit-test setup. It is the same commit as in the other main fix PRs from this batch, so they do not conflict on it.

Behavior change

Anyone who loads modules on the server without ssr: true now gets SSR output instead of DOM output. DOM output could not run on the server, so this should only affect setups that loaded those modules without rendering them.

Testing

  • Added src/ssr-codegen.test.ts. It fails without the fix: the server transform still contains template.
  • pnpm test:unit and tsc --noEmit pass. The Cypress suite for the vite-3 to vite-8 examples passes.

🤖 Generated with Claude Code

lxsmnsyc and others added 2 commits October 19, 2026 11:34
- Add a root vitest config and a test:unit script, matching the next branch.
- Run the unit tests in the vitest workflow.
- Exclude test files from the declaration build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Without `ssr: true`, modules loaded on the server were compiled to DOM
  output and threw "Client-only API called on the server side".
- Server transforms now use `generate: 'ssr'` with `hydratable: false`, so
  a client-rendered app can prerender pages with `ssrLoadModule`.
- Client transforms and Vitest keep DOM output.

Fixes #64

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

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

commit: cd79ed9

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.

Make ssr settings less strict

1 participant