Skip to content

fix: define __SOLID_SERVER_COMPONENTS__ for every environment - #402

Merged
ryansolid merged 1 commit into
nextfrom
fix/issue-396-server-components-define
Oct 8, 2026
Merged

ryansolid merged 1 commit into
nextfrom
fix/issue-396-server-components-define

Conversation

@ryansolid

Copy link
Copy Markdown
Member

Fixes #396.

Problem

@solidjs/router ships a client fallback for server-component forms. Only server-component apps need it, but every router app pays for the bytes, because a runtime flag does not fold under Rolldown or esbuild. A build-time literal does.

Fix

The plugin always defines __SOLID_SERVER_COMPONENTS__:

  • "true" when serverFunctions.components is set, including 'external'; otherwise "false". It is never left undefined, so the dead branch can be eliminated.
  • Top-level define, which covers build output and dev source via /@vite/env.
  • Every environment's optimizeDeps.rolldownOptions.transform.define. The optimizer ignores top-level define, and Vite only seeds the client environment from top-level optimizeDeps, so configEnvironment sets the flag on each environment. A value already present on that environment is left alone.
  • A user-provided define.__SOLID_SERVER_COMPONENTS__ wins, and the optimizers follow it unless they set their own.

Tests

examples/ssr/test/server-components-define.mjs (wired into the example test script):

  • Resolved config: off by default, on for components: true and 'external', on both the client and ssr defines and both optimizers. A user define wins. A per-environment optimizer value wins only there. The client scanner JSX runtime stays classic.
  • Production build of a fixture: false drops the SC_DEFINE_ON branch, true drops SC_DEFINE_OFF.

Left open

The name and the scoping are the contract this ships. __SOLID_SERVER_COMPONENTS__ is what #396 proposes; core docs (RFC 11 / the server-components skill) and the router guard are follow-ups in other repos, not this PR. The optimizer flag is applied from configEnvironment for every environment, which is wider than the issue sketch's top-level optimizeDeps (that only reaches client). Please confirm the name and that all-environment scoping before merging.

Made with Cursor

@changeset-bot

changeset-bot Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9548326

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 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/vite-plugin@402

commit: 9548326

Libraries can drop server-component-only client code when the flag is false, and an absent identifier cannot be eliminated.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ryansolid
ryansolid force-pushed the fix/issue-396-server-components-define branch from 3afb014 to 9548326 Compare October 8, 2026 20:20
@ryansolid
ryansolid merged commit b64a22b into next Oct 8, 2026
6 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.

1 participant