Repository navigation
fix: define __SOLID_SERVER_COMPONENTS__ for every environment - #402
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 9548326 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
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
force-pushed
the
fix/issue-396-server-components-define
branch
from
October 8, 2026 20:20
3afb014 to
9548326
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #396.
Problem
@solidjs/routerships 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"whenserverFunctions.componentsis set, including'external'; otherwise"false". It is never left undefined, so the dead branch can be eliminated.define, which covers build output and dev source via/@vite/env.optimizeDeps.rolldownOptions.transform.define. The optimizer ignores top-leveldefine, and Vite only seeds theclientenvironment from top-leveloptimizeDeps, soconfigEnvironmentsets the flag on each environment. A value already present on that environment is left alone.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 exampletestscript):components: trueand'external', on both the client and ssr defines and both optimizers. A userdefinewins. A per-environment optimizer value wins only there. The client scanner JSX runtime stays classic.falsedrops theSC_DEFINE_ONbranch,truedropsSC_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 fromconfigEnvironmentfor every environment, which is wider than the issue sketch's top-leveloptimizeDeps(that only reachesclient). Please confirm the name and that all-environment scoping before merging.Made with Cursor