@@ -47,43 +47,34 @@ function initialize(): void {
4747 const modCss = await import (
4848 /* @vite -ignore */ '/@id/__x00__' + toCssVirtual ( { id, type : 'ssr' } )
4949 )
50- return wrapResourceProxy ( mod , { js : [ ] , css : modCss . default } )
50+ return wrapResourceProxy ( mod , id , { js : [ ] , css : modCss . default } )
5151 } else {
5252 const import_ = clientReferences . default [ id ]
5353 if ( ! import_ ) {
5454 throw new Error ( `client reference not found '${ id } '` )
5555 }
56- const deps = assetsManifest . clientReferenceDeps [ id ]
57- // kick off preload before initial async import, which is not sync-cached
58- if ( deps ) {
59- preloadDeps ( deps )
56+ const deps = assetsManifest . clientReferenceDeps [ id ] ?? {
57+ js : [ ] ,
58+ css : [ ] ,
6059 }
60+ // kick off preload/notify before initial async import, which is not sync-cached
61+ preloadDeps ( deps )
62+ onClientReference ?.( { id, deps } )
6163 const mod : any = await import_ ( )
62- return wrapResourceProxy ( mod , deps )
63- }
64- } ,
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- }
64+ return wrapResourceProxy ( mod , id , deps )
7465 }
7566 } ,
7667 } )
7768}
7869
79- // preload/preinit during getter access since `load` is cached on production
80- function wrapResourceProxy ( mod : any , deps ?: ResolvedAssetDeps ) {
70+ // preload/preinit during getter access since `load` is cached on production.
71+ // also notify `onClientReference` callback here since module export access is not memoized by React.
72+ function wrapResourceProxy ( mod : any , id : string , deps : ResolvedAssetDeps ) {
8173 return new Proxy ( mod , {
8274 get ( target , p , receiver ) {
8375 if ( p in mod ) {
84- if ( deps ) {
85- preloadDeps ( deps )
86- }
76+ preloadDeps ( deps )
77+ onClientReference ?.( { id, deps } )
8778 }
8879 return Reflect . get ( target , p , receiver )
8980 } ,
0 commit comments