@@ -938,17 +938,6 @@ function hashString(v: string) {
938
938
return createHash ( 'sha256' ) . update ( v ) . digest ( ) . toString ( 'hex' ) . slice ( 0 , 12 )
939
939
}
940
940
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
-
952
941
function vitePluginUseClient (
953
942
useClientPluginOptions : Pick <
954
943
RscPluginOptions ,
@@ -1243,7 +1232,14 @@ function vitePluginUseServer(
1243
1232
// module identity of `import(id)` like browser, so we simply strip it off.
1244
1233
id = id . split ( '?v=' ) [ 0 ] !
1245
1234
}
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
+ }
1247
1243
}
1248
1244
return normalizedId_
1249
1245
}
@@ -1262,17 +1258,26 @@ function vitePluginUseServer(
1262
1258
) } , ${ JSON . stringify ( name ) } )`,
1263
1259
rejectNonAsyncFunction : true ,
1264
1260
encode : enableEncryption
1265
- ? ( value ) => `$$ReactServer.encryptActionBoundArgs(${ value } )`
1261
+ ? ( value ) =>
1262
+ `__vite_rsc_encryption_runtime.encryptActionBoundArgs(${ value } )`
1266
1263
: undefined ,
1267
1264
decode : enableEncryption
1268
1265
? ( value ) =>
1269
- `await $$ReactServer .decryptActionBoundArgs(${ value } )`
1266
+ `await __vite_rsc_encryption_runtime .decryptActionBoundArgs(${ value } )`
1270
1267
: undefined ,
1271
1268
} )
1272
1269
if ( ! output . hasChanged ( ) ) return
1273
1270
serverReferences [ getNormalizedId ( ) ] = id
1274
- const importSource = resolvePackage ( `${ PKG_NAME } /rsc` )
1271
+ const importSource = resolvePackage ( `${ PKG_NAME } /react/ rsc` )
1275
1272
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
+ }
1276
1281
return {
1277
1282
code : output . toString ( ) ,
1278
1283
map : output . generateMap ( { hires : 'boundary' } ) ,
0 commit comments