@@ -47,6 +47,7 @@ async function compile(opts: {
4747 kind : 'Root' ,
4848 } ,
4949 ] ,
50+ getKnownServerFns : ( ) => ( { } ) ,
5051 resolveId : async ( id ) => {
5152 return id
5253 } ,
@@ -250,6 +251,7 @@ describe('createServerFn compiles correctly', async () => {
250251 kind : 'Root' ,
251252 } ,
252253 ] ,
254+ getKnownServerFns : ( ) => ( { } ) ,
253255 resolveId : resolveIdMock ,
254256 mode : 'build' ,
255257 } )
@@ -297,6 +299,7 @@ describe('createServerFn compiles correctly', async () => {
297299 kind : 'Root' ,
298300 } ,
299301 ] ,
302+ getKnownServerFns : ( ) => ( { } ) ,
300303 resolveId : resolveIdMock ,
301304 mode : 'build' ,
302305 } )
@@ -349,6 +352,7 @@ describe('createServerFn compiles correctly', async () => {
349352 kind : 'Root' ,
350353 } ,
351354 ] ,
355+ getKnownServerFns : ( ) => ( { } ) ,
352356 resolveId : resolveIdMock ,
353357 mode : 'build' ,
354358 } )
@@ -407,6 +411,7 @@ describe('createServerFn compiles correctly', async () => {
407411 kind : 'Root' ,
408412 } ,
409413 ] ,
414+ getKnownServerFns : ( ) => ( { } ) ,
410415 resolveId : resolveIdMock ,
411416 mode : 'build' ,
412417 } )
@@ -430,4 +435,86 @@ describe('createServerFn compiles correctly', async () => {
430435 './factory' ,
431436 )
432437 } )
438+
439+ test ( 'reuses deduped custom IDs across compiler instances' , async ( ) => {
440+ const serverFnsById : Record <
441+ string ,
442+ {
443+ functionName : string
444+ functionId : string
445+ extractedFilename : string
446+ filename : string
447+ isClientReferenced ?: boolean
448+ }
449+ > = { }
450+
451+ function createCompiler ( ) {
452+ return new StartCompiler ( {
453+ env : 'server' ,
454+ ...getDefaultTestOptions ( 'server' ) ,
455+ mode : 'build' ,
456+ loadModule : async ( ) => { } ,
457+ lookupKinds : new Set ( [ 'ServerFn' ] ) ,
458+ lookupConfigurations : [
459+ {
460+ libName : '@tanstack/react-start' ,
461+ rootExport : 'createServerFn' ,
462+ kind : 'Root' ,
463+ } ,
464+ ] ,
465+ resolveId : async ( id ) => id ,
466+ generateFunctionId : ( { functionName } ) =>
467+ functionName === 'greetUser_createServerFn_handler'
468+ ? 'constant_id'
469+ : undefined ,
470+ getKnownServerFns : ( ) => serverFnsById ,
471+ onServerFnsById : ( discovered ) => {
472+ Object . assign ( serverFnsById , discovered )
473+ } ,
474+ } )
475+ }
476+
477+ const firstCompiler = createCompiler ( )
478+ await firstCompiler . compile ( {
479+ code : `
480+ import { createServerFn } from '@tanstack/react-start'
481+ export const greetUser = createServerFn().handler(async () => 'first')
482+ ` ,
483+ id : '/test/src/submit-post-formdata.tsx' ,
484+ } )
485+
486+ await firstCompiler . compile ( {
487+ code : `
488+ import { createServerFn } from '@tanstack/react-start'
489+ export const greetUser = createServerFn().handler(async () => 'second')
490+ ` ,
491+ id : '/test/src/formdata-redirect/index.tsx' ,
492+ } )
493+
494+ expect (
495+ Object . values ( serverFnsById )
496+ . map ( ( serverFn ) => serverFn . functionId )
497+ . sort ( ) ,
498+ ) . toEqual ( [ 'constant_id' , 'constant_id_1' ] )
499+
500+ const secondCompiler = createCompiler ( )
501+ const firstResult = await secondCompiler . compile ( {
502+ code : `
503+ import { createServerFn } from '@tanstack/react-start'
504+ export const greetUser = createServerFn().handler(async () => 'first')
505+ ` ,
506+ id : '/test/src/submit-post-formdata.tsx' ,
507+ } )
508+
509+ const secondResult = await secondCompiler . compile ( {
510+ code : `
511+ import { createServerFn } from '@tanstack/react-start'
512+ export const greetUser = createServerFn().handler(async () => 'second')
513+ ` ,
514+ id : '/test/src/formdata-redirect/index.tsx' ,
515+ } )
516+
517+ expect ( firstResult ! . code ) . toContain ( 'createSsrRpc("constant_id"' )
518+ expect ( secondResult ! . code ) . toContain ( 'createSsrRpc("constant_id_1"' )
519+ } )
433520} )
0 commit comments