@@ -9,6 +9,30 @@ export { createServerConsumerManifest } from './core/ssr'
99
1010export * from './react/ssr'
1111
12+ /**
13+ * Callback type for client reference dependency notifications.
14+ * Called during SSR when a client component's dependencies are loaded.
15+ * @experimental
16+ */
17+ export type OnClientReference = ( reference : {
18+ id : string
19+ deps : ResolvedAssetDeps
20+ } ) => void
21+
22+ // Registered callback for client reference deps
23+ let onClientReference : OnClientReference | undefined
24+
25+ /**
26+ * Register a callback to be notified when client reference dependencies are loaded.
27+ * Called during SSR when a client component is accessed.
28+ * @experimental
29+ */
30+ export function setOnClientReference (
31+ callback : OnClientReference | undefined ,
32+ ) : void {
33+ onClientReference = callback
34+ }
35+
1236initialize ( )
1337
1438function initialize ( ) : void {
@@ -38,6 +62,17 @@ function initialize(): void {
3862 return wrapResourceProxy ( mod , deps )
3963 }
4064 } ,
65+ // Called EVERY time a module is requested (not memoized).
66+ // Notify framework callback for per-request asset collection.
67+ onLoad : ( id ) => {
68+ if ( ! import . meta. env . __vite_rsc_build__ ) return
69+ if ( onClientReference ) {
70+ const deps = assetsManifest . clientReferenceDeps [ id ]
71+ if ( deps ) {
72+ onClientReference ( { id, deps : { js : deps . js , css : deps . css } } )
73+ }
74+ }
75+ } ,
4176 } )
4277}
4378
0 commit comments