@@ -333,6 +333,7 @@ export type ResourceOptions<T> = undefined extends T
333
333
} ;
334
334
335
335
const SuspenseContext = createContext < SuspenseContextType > ( ) ;
336
+ let resourceContext : any [ ] | null = null ;
336
337
export function createResource < T , S = true > (
337
338
fetcher : ResourceFetcher < S , T > ,
338
339
options ?: ResourceOptions < undefined >
@@ -386,6 +387,7 @@ export function createResource<T, S>(
386
387
options . ssrLoadFrom !== "initial" &&
387
388
sharedConfig . context ! . async &&
388
389
"data" in sharedConfig . context ! . resources [ id ] ;
390
+ if ( ! resolved && resourceContext ) resourceContext . push ( id ) ;
389
391
if ( ! resolved && read . loading ) {
390
392
const ctx = useContext ( SuspenseContext ) ;
391
393
if ( ctx ) {
@@ -411,7 +413,14 @@ export function createResource<T, S>(
411
413
value = ctx . resources [ id ] . data ;
412
414
return ;
413
415
}
414
- const lookup = typeof source === "function" ? ( source as ( ) => S ) ( ) : source ;
416
+ let lookup ;
417
+ try {
418
+ resourceContext = [ ] ;
419
+ lookup = typeof source === "function" ? ( source as ( ) => S ) ( ) : source ;
420
+ if ( resourceContext . length ) return ;
421
+ } finally {
422
+ resourceContext = null ;
423
+ }
415
424
if ( ! p ) {
416
425
if ( lookup == null || lookup === false ) return ;
417
426
p = ( fetcher as ResourceFetcher < S , T > ) ( lookup , { value } ) ;
0 commit comments