Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type ClientReferenceMeta = {
// build only for tree-shaking unused export
exportNames: string[]
renderedExports: string[]
groupChunkId?: string
}

type ServerRerferenceMeta = {
Expand Down Expand Up @@ -800,10 +801,11 @@ export default function vitePluginRsc(
assert(entry)
const entryUrl = assetsURL(entry.chunk.fileName, manager)
const clientReferenceDeps: Record<string, AssetDeps> = {}
for (const [id, meta] of Object.entries(
manager.clientReferenceMetaMap,
)) {
const deps: AssetDeps = assetDeps[id]?.deps ?? { js: [], css: [] }
for (const meta of Object.values(manager.clientReferenceMetaMap)) {
const deps: AssetDeps = assetDeps[meta.groupChunkId!]?.deps ?? {
js: [],
css: [],
}
clientReferenceDeps[meta.referenceKey] = assetsURLOfDeps(
mergeAssetDeps(deps, entry.deps),
manager,
Expand Down Expand Up @@ -1145,13 +1147,16 @@ function vitePluginUseClient(
// group client reference modules by `clientChunks` option
manager.clientReferenceGroups = {}
for (const meta of Object.values(manager.clientReferenceMetaMap)) {
const name =
let name =
useClientPluginOptions.clientChunks?.(meta.importId) ||
// use original module id as name by default
normalizePath(path.relative(manager.config.root, meta.importId))
name = name.replaceAll('..', '__')
const group = (manager.clientReferenceGroups[name] ??= [])
group.push(meta)
meta.groupChunkId = `\0virtual:vite-rsc/client-references/group/${name}`
}
debug('client-reference-groups', manager.clientReferenceGroups)
for (const [name, metas] of Object.entries(
manager.clientReferenceGroups,
)) {
Expand Down
Loading