@@ -938,17 +938,6 @@ function hashString(v: string) {
938938 return createHash ( 'sha256' ) . update ( v ) . digest ( ) . toString ( 'hex' ) . slice ( 0 , 12 )
939939}
940940
941- function normalizeReferenceId ( id : string , name : 'client' | 'rsc' ) {
942- if ( ! server ) {
943- return hashString ( path . relative ( config . root , id ) )
944- }
945-
946- // align with how Vite import analysis would rewrite id
947- // to avoid double modules on browser and ssr.
948- const environment = server . environments [ name ] !
949- return normalizeViteImportAnalysisUrl ( environment , id )
950- }
951-
952941function vitePluginUseClient (
953942 useClientPluginOptions : Pick <
954943 RscPluginOptions ,
@@ -1243,7 +1232,14 @@ function vitePluginUseServer(
12431232 // module identity of `import(id)` like browser, so we simply strip it off.
12441233 id = id . split ( '?v=' ) [ 0 ] !
12451234 }
1246- normalizedId_ = normalizeReferenceId ( id , 'rsc' )
1235+ if ( config . command === 'build' ) {
1236+ normalizedId_ = hashString ( path . relative ( config . root , id ) )
1237+ } else {
1238+ normalizedId_ = normalizeViteImportAnalysisUrl (
1239+ server . environments . rsc ! ,
1240+ id ,
1241+ )
1242+ }
12471243 }
12481244 return normalizedId_
12491245 }
@@ -1262,17 +1258,26 @@ function vitePluginUseServer(
12621258 ) } , ${ JSON . stringify ( name ) } )`,
12631259 rejectNonAsyncFunction : true ,
12641260 encode : enableEncryption
1265- ? ( value ) => `$$ReactServer.encryptActionBoundArgs(${ value } )`
1261+ ? ( value ) =>
1262+ `__vite_rsc_encryption_runtime.encryptActionBoundArgs(${ value } )`
12661263 : undefined ,
12671264 decode : enableEncryption
12681265 ? ( value ) =>
1269- `await $$ReactServer .decryptActionBoundArgs(${ value } )`
1266+ `await __vite_rsc_encryption_runtime .decryptActionBoundArgs(${ value } )`
12701267 : undefined ,
12711268 } )
12721269 if ( ! output . hasChanged ( ) ) return
12731270 serverReferences [ getNormalizedId ( ) ] = id
1274- const importSource = resolvePackage ( `${ PKG_NAME } /rsc` )
1271+ const importSource = resolvePackage ( `${ PKG_NAME } /react/ rsc` )
12751272 output . prepend ( `import * as $$ReactServer from "${ importSource } ";\n` )
1273+ if ( enableEncryption ) {
1274+ const importSource = resolvePackage (
1275+ `${ PKG_NAME } /utils/encryption-runtime` ,
1276+ )
1277+ output . prepend (
1278+ `import * as __vite_rsc_encryption_runtime from ${ JSON . stringify ( importSource ) } ;\n` ,
1279+ )
1280+ }
12761281 return {
12771282 code : output . toString ( ) ,
12781283 map : output . generateMap ( { hires : 'boundary' } ) ,
0 commit comments