fix: pre-bundle the server-function client runtime - #395
Open
everton-dgn wants to merge 1 commit into
Open
everton-dgn wants to merge 1 commit into
everton-dgn wants to merge 1 commit into
Conversation
Compiled server-function references import the client runtime (`@solidjs/web/server-functions` by default), but the dependency scanner never runs the server-function transform that adds that import. Only `serverFunctions.components` put the runtime in `optimizeDeps.include`, so with plain `serverFunctions` the first "use server" module discovered it late and forced a re-optimize and full reload (in Vitest browser mode: "Vite unexpectedly reloaded a test"). Under `serve`, include the client runtime whenever `serverFunctions` is on: the default, or `runtime.client` when it is a package specifier. A path or an alias is app source, and a virtual id doesn't resolve for `include`, so those stay out. The server-components branch is unchanged and the default runtime is listed once. Tests (examples/start-ssr/test/components-warning.mjs): included with `serverFunctions: true` with and without `ssr`, with a custom package runtime, and beside the components entries when both are on; not included without `serverFunctions`, in build, or for path, virtual or alias runtimes; listed once with components on.
🦋 Changeset detectedLatest commit: 2a714d4 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 |
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.
With
serverFunctions: trueand nocomponents, a Vitest browser test that imports a'use server'module logs this on a cold cache:The test still passed in all my runs, so the cost is one reload plus that warning on each cold start.
The server-function compiler adds the
createServerReferenceimport fromruntime.clientduring transform (server-functions/index.ts#L381, #L427-L438). The dep scanner doesn't run that transform (the only plugin this package adds to the scan issolid:tsrx-dep-scan, for.tsrxfiles, index.ts#L1503-L1525), and the runtime is only inoptimizeDeps.includewhenserverComponentsis on (index.ts#L1476-L1485).Under
serve, this adds the client runtime wheneverserverFunctionsis on:@solidjs/web/server-functionsby default, orruntime.clientwhen it is a package specifier. It sits in the same place and form as thesolid-js/attributionand@solidjs/web/performance-tracksentries from #374. TheserverComponentsbranch is unchanged, and the default runtime is listed once when both apply. The standaloneserverFunctions()export still doesn't add the entry.Paths, aliases and virtual ids stay out on purpose. I checked what Vite 8.2.1 does with each one in
includeon a small dev server: a relative path or a~/xalias builds a copy the browser never loads, an@/xalias gets served from the deps cache in place of the source (edits stopped showing up, even after a restart), and a virtual id or a root-relative/src/xdoesn't resolve, so it only logs "Failed to resolve dependency" on a cold cache. The check is syntactic, so an alias that looks like a package name would still be added.Testing:
examples/start-ssr/test/components-warning.mjsgets the new assertions. The file passes 19 of its 23 checks on next (e4cdee4), failing the four positive cases, and 23/23 with this change. Dropping the duplicate guard fails only the "listed once" case.release.yml, on pushes to main and next. The PR workflows only test examples/vite-8 (vitest.yml, ande2e.ymlthrough the rootpnpm test), which doesn't exercise this: its Vitest config has noserverFunctions, and the e2e job is build plus preview. Both pass with this change.pnpm build,tsc --noEmit -p tsconfig.jsonand the five suitesrelease.ymlruns (start-ssr, start-client, ssr, css-matrix, start-env) pass.solid({ serverFunctions: true }), nooptimizeDeps.includein the user config, cold cache before each run, variants interleaved: the reload and warning showed up in 3/3 runs with 3.0.0-next.47 and 0/3 with itsdist/swapped for this branch's build. All six runs passed. AddingoptimizeDeps: { include: ['@solidjs/web/server-functions'] }to the user config instead gave the same 0/3 in an earlier set of runs.