1313// derived serverComponents flag) matches `true` exactly, and stays off
1414// when the option is off,
1515// - under full SSR start mode `'external'` is redundant but harmless:
16- // silent, exactly like `true`.
16+ // silent, exactly like `true`,
17+ // - independent of server components: `serverFunctions` alone (with or
18+ // without `ssr`) pre-bundles the server-function client runtime under
19+ // `serve` (the dependency scan never runs the transform that adds its
20+ // import), listed once when components also ask for it; not without
21+ // `serverFunctions`, not in build, and a custom `runtime.client` only as
22+ // a package specifier, beside the components entries when both are on.
1723//
1824// Pure resolveConfig — no dev server, no browser. Requires the plugin built
1925// (pnpm build at the repo root). Usage: node test/components-warning.mjs
@@ -81,6 +87,14 @@ async function resolveWith(solidOptions) {
8187 config . optimizeDeps . include . includes ( '@solidjs/web/frames' ) &&
8288 config . optimizeDeps . include . includes ( '@solidjs/web/server-functions' ) ,
8389 ) ;
90+ const runtimeEntries = config . optimizeDeps . include . filter (
91+ ( dep ) => dep === '@solidjs/web/server-functions' ,
92+ ) ;
93+ record (
94+ 'enabled: server-function client runtime listed once' ,
95+ runtimeEntries . length === 1 ,
96+ config . optimizeDeps . include . join ( ', ' ) ,
97+ ) ;
8498}
8599
86100// ---- `'external'` in the identical config: silent, still enabled ---------
@@ -123,6 +137,84 @@ async function resolveWith(solidOptions) {
123137 config . optimizeDeps . include . includes ( '@solidjs/web/performance-tracks' ) ,
124138 config . optimizeDeps . include . join ( ', ' ) ,
125139 ) ;
140+ // Compiled server-function references import the client runtime, but the
141+ // dependency scanner never runs the transform that adds that import.
142+ // Without the entry, the first "use server" module the browser loads
143+ // discovers it late: re-optimize and full reload.
144+ record (
145+ 'serverFunctions without components: server-function client runtime pre-bundled' ,
146+ config . optimizeDeps . include . includes ( '@solidjs/web/server-functions' ) ,
147+ config . optimizeDeps . include . join ( ', ' ) ,
148+ ) ;
149+ }
150+
151+ // ---- serverFunctions without ssr: same entry -----------------------------
152+ {
153+ const { config } = await resolveWith ( { serverFunctions : true } ) ;
154+ record (
155+ 'serverFunctions without ssr: server-function client runtime pre-bundled' ,
156+ config . optimizeDeps . include . includes ( '@solidjs/web/server-functions' ) ,
157+ config . optimizeDeps . include . join ( ', ' ) ,
158+ ) ;
159+ }
160+
161+ // ---- serverFunctions off: no server-function runtime pre-bundle -----------
162+ {
163+ const { config } = await resolveWith ( { ssr : true } ) ;
164+ record (
165+ 'serverFunctions off: server-function client runtime not pre-bundled' ,
166+ ! config . optimizeDeps . include . includes ( '@solidjs/web/server-functions' ) ,
167+ config . optimizeDeps . include . join ( ', ' ) ,
168+ ) ;
169+ }
170+
171+ // ---- custom runtime: only a package specifier is pre-bundled --------------
172+ {
173+ const client = '@acme/server-runtime/client' ;
174+ const { config } = await resolveWith ( {
175+ ssr : true ,
176+ serverFunctions : { runtime : { server : '@acme/server-runtime/server' , client } } ,
177+ } ) ;
178+ record (
179+ 'custom runtime (package): runtime.client pre-bundled instead of the default' ,
180+ config . optimizeDeps . include . includes ( client ) &&
181+ ! config . optimizeDeps . include . includes ( '@solidjs/web/server-functions' ) ,
182+ config . optimizeDeps . include . join ( ', ' ) ,
183+ ) ;
184+ }
185+ {
186+ const client = '@acme/server-runtime/client' ;
187+ const { config } = await resolveWith ( {
188+ ssr : true ,
189+ serverFunctions : {
190+ components : true ,
191+ runtime : { server : '@acme/server-runtime/server' , client } ,
192+ } ,
193+ } ) ;
194+ record (
195+ 'components + custom runtime (package): runtime.client beside the components entries' ,
196+ config . optimizeDeps . include . includes ( client ) &&
197+ config . optimizeDeps . include . includes ( '@solidjs/web/server-functions' ) ,
198+ config . optimizeDeps . include . join ( ', ' ) ,
199+ ) ;
200+ }
201+ for ( const client of [
202+ './src/sf-client.ts' ,
203+ '/src/sf-client.ts' ,
204+ 'virtual:sf-client' ,
205+ '@/sf-client' ,
206+ '~/sf-client' ,
207+ ] ) {
208+ const { config } = await resolveWith ( {
209+ ssr : true ,
210+ serverFunctions : { runtime : { server : client , client } } ,
211+ } ) ;
212+ record (
213+ `custom runtime (${ client } ): neither it nor the default pre-bundled` ,
214+ ! config . optimizeDeps . include . includes ( client ) &&
215+ ! config . optimizeDeps . include . includes ( '@solidjs/web/server-functions' ) ,
216+ config . optimizeDeps . include . join ( ', ' ) ,
217+ ) ;
126218}
127219
128220// ---- build: optimizeDeps is serve-only, the entries stay out --------------
@@ -138,6 +230,21 @@ async function resolveWith(solidOptions) {
138230 config . optimizeDeps . include . join ( ', ' ) ,
139231 ) ;
140232}
233+ {
234+ const config = await resolveConfig (
235+ {
236+ root : exampleDir ,
237+ configFile : false ,
238+ plugins : [ solidPlugin ( { ssr : true , serverFunctions : true } ) ] ,
239+ } ,
240+ 'build' ,
241+ ) ;
242+ record (
243+ 'build: server-function client runtime not in optimizeDeps.include' ,
244+ ! config . optimizeDeps . include . includes ( '@solidjs/web/server-functions' ) ,
245+ config . optimizeDeps . include . join ( ', ' ) ,
246+ ) ;
247+ }
141248
142249// ---- full SSR start mode: `'external'` is redundant but harmless ---------
143250{
0 commit comments