@@ -63,6 +63,7 @@ type ClientReferenceMeta = {
6363 // build only for tree-shaking unused export
6464 exportNames : string [ ]
6565 renderedExports : string [ ]
66+ serverChunk ?: string
6667 groupChunkId ?: string
6768}
6869
@@ -185,11 +186,13 @@ export type RscPluginOptions = {
185186 *
186187 * This function allows you to group multiple client components into
187188 * custom chunks instead of having each module in its own chunk.
188- *
189- * @param id - The absolute path of the client module
190- * @returns The chunk name to group this module with, or undefined to use default behavior
191189 */
192- clientChunks ?: ( id : string ) => string | undefined
190+ clientChunks ?: ( meta : {
191+ /** client reference module id */
192+ id : string
193+ /** server chunk which includes a corresponding client reference proxy module */
194+ serverChunk : string
195+ } ) => string | undefined
193196}
194197
195198/** @experimental */
@@ -1148,7 +1151,10 @@ function vitePluginUseClient(
11481151 manager . clientReferenceGroups = { }
11491152 for ( const meta of Object . values ( manager . clientReferenceMetaMap ) ) {
11501153 let name =
1151- useClientPluginOptions . clientChunks ?.( meta . importId ) ||
1154+ useClientPluginOptions . clientChunks ?.( {
1155+ id : meta . importId ,
1156+ serverChunk : meta . serverChunk ! ,
1157+ } ) ??
11521158 // use original module id as name by default
11531159 normalizePath ( path . relative ( manager . config . root , meta . importId ) )
11541160 name = name . replaceAll ( '..' , '__' )
@@ -1261,6 +1267,14 @@ function vitePluginUseClient(
12611267 const meta = manager . clientReferenceMetaMap [ id ]
12621268 if ( meta ) {
12631269 meta . renderedExports = mod . renderedExports
1270+ meta . serverChunk =
1271+ ( chunk . facadeModuleId ? 'facade:' : 'non-facade:' ) +
1272+ normalizePath (
1273+ path . relative (
1274+ manager . config . root ,
1275+ chunk . facadeModuleId ?? [ ...chunk . moduleIds ] . sort ( ) [ 0 ] ! ,
1276+ ) ,
1277+ )
12641278 }
12651279 }
12661280 }
0 commit comments