@@ -2,6 +2,7 @@ import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
22import { generateSerializationAdaptersModule } from '../serialization-adapters-module'
33import { generateServerFnResolverModule } from '../start-compiler/server-fn-resolver-module'
44import { buildStartManifest } from '../start-manifest-plugin/manifestBuilder'
5+ import { escapeRegExp } from '../utils'
56import { RSBUILD_ENVIRONMENT_NAMES } from './planning'
67import type {
78 RsbuildPluginAPI ,
@@ -265,6 +266,7 @@ export function registerVirtualModules(
265266 const hasSeparateProviderEnvironment =
266267 ! opts . rscEnabled &&
267268 opts . providerEnvName !== RSBUILD_ENVIRONMENT_NAMES . server
269+ const hasSerializationAdapters = Boolean ( opts . serializationAdapters ?. length )
268270
269271 function isProviderEnvironment ( environmentName : string ) : boolean {
270272 return environmentName === opts . providerEnvName
@@ -384,14 +386,16 @@ export function registerVirtualModules(
384386 content [ paths . serverFnResolver ] = 'export {}'
385387 }
386388
387- // Plugin adapters — both environments get environment-specific content
388- content [ paths . pluginAdapters ] = generateSerializationAdaptersModule ( {
389- adapters : opts . serializationAdapters ,
390- runtime :
391- environmentName === RSBUILD_ENVIRONMENT_NAMES . client
392- ? 'client'
393- : 'server' ,
394- } )
389+ if ( hasSerializationAdapters ) {
390+ // Plugin adapters — both environments get environment-specific content
391+ content [ paths . pluginAdapters ] = generateSerializationAdaptersModule ( {
392+ adapters : opts . serializationAdapters ,
393+ runtime :
394+ environmentName === RSBUILD_ENVIRONMENT_NAMES . client
395+ ? 'client'
396+ : 'server' ,
397+ } )
398+ }
395399
396400 // --- RSC virtual modules ---
397401 if ( rscPaths ) {
@@ -430,7 +434,10 @@ export function createFromReadableStream() { throw new Error('RSC SSR decode is
430434 const aliasMap : Record < string , string > = {
431435 [ VIRTUAL_MODULES . startManifest ] : paths . manifest ,
432436 [ VIRTUAL_MODULES . serverFnResolver ] : paths . serverFnResolver ,
433- [ VIRTUAL_MODULES . pluginAdapters ] : paths . pluginAdapters ,
437+ }
438+
439+ if ( hasSerializationAdapters ) {
440+ aliasMap [ VIRTUAL_MODULES . pluginAdapters ] = paths . pluginAdapters
434441 }
435442
436443 // Add RSC virtual module aliases
@@ -470,15 +477,18 @@ export function createFromReadableStream() { throw new Error('RSC SSR decode is
470477
471478 // Rewrite scheme-like IDs to the VirtualModulesPlugin-backed file paths.
472479 for ( const [ moduleId , virtualFilePath ] of Object . entries ( aliasMap ) ) {
473- const escaped = moduleId . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
474480 const NMR = utils . rspack . NormalModuleReplacementPlugin
475- config . plugins . push ( new NMR ( new RegExp ( `^${ escaped } $` ) , virtualFilePath ) )
481+ config . plugins . push (
482+ new NMR ( new RegExp ( `^${ escapeRegExp ( moduleId ) } $` ) , virtualFilePath ) ,
483+ )
476484 }
477485
478486 const resolve = config . resolve
479487 const resolveAlias = ( resolve . alias ??= { } ) as Record < string , string >
480488 resolveAlias [ VIRTUAL_MODULES . serverFnResolver ] = paths . serverFnResolver
481- resolveAlias [ VIRTUAL_MODULES . pluginAdapters ] = paths . pluginAdapters
489+ if ( hasSerializationAdapters ) {
490+ resolveAlias [ VIRTUAL_MODULES . pluginAdapters ] = paths . pluginAdapters
491+ }
482492
483493 // Add RSC-specific resolve aliases
484494 if ( rscPaths ) {
0 commit comments