File tree 3 files changed +19
-6
lines changed
3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,8 @@ import { canonicalStringify } from "../../cache/index.js";
8
8
import type { Cache } from "../../cache/index.js" ;
9
9
import { useApolloClient } from "./useApolloClient.js" ;
10
10
import { getSuspenseCache } from "../internal/index.js" ;
11
- import type { CacheKey } from "../internal/index.js" ;
12
- import React from "rehackt" ;
13
- import type { FragmentKey } from "../internal/cache/types.js" ;
11
+ import React , { useMemo } from "rehackt" ;
12
+ import type { FragmentCacheKey , FragmentKey } from "../internal/cache/types.js" ;
14
13
import { __use } from "./internal/__use.js" ;
15
14
import { wrapHook } from "./internal/index.js" ;
16
15
@@ -59,8 +58,16 @@ function _useSuspenseFragment<
59
58
options : UseSuspenseFragmentOptions < TData , TVariables >
60
59
) : UseSuspenseFragmentResult < TData > {
61
60
const client = useApolloClient ( options . client ) ;
61
+ const { from } = options ;
62
+ const { cache } = client ;
62
63
63
- const cacheKey : CacheKey = [
64
+ const id = useMemo (
65
+ ( ) => ( typeof from === "string" ? from : cache . identify ( from ) ) ,
66
+ [ cache , from ]
67
+ ) ! ;
68
+
69
+ const cacheKey : FragmentCacheKey = [
70
+ id ,
64
71
options . fragment ,
65
72
canonicalStringify ( options . variables ) ,
66
73
] ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import type {
6
6
import type { Observable } from "../../../utilities/index.js" ;
7
7
import { canUseWeakMap } from "../../../utilities/index.js" ;
8
8
import { InternalQueryReference } from "./QueryReference.js" ;
9
- import type { CacheKey } from "./types.js" ;
9
+ import type { CacheKey , FragmentCacheKey } from "./types.js" ;
10
10
import { FragmentReference } from "./FragmentReference.js" ;
11
11
12
12
export interface SuspenseCacheOptions {
@@ -58,7 +58,7 @@ export class SuspenseCache {
58
58
}
59
59
60
60
getFragmentRef < TData > (
61
- cacheKey : CacheKey ,
61
+ cacheKey : FragmentCacheKey ,
62
62
createObservable : ( ) => Observable < WatchFragmentResult < TData > >
63
63
) {
64
64
const ref = this . fragmentRefs . lookupArray ( cacheKey ) as {
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ export type CacheKey = [
6
6
...queryKey : any [ ] ,
7
7
] ;
8
8
9
+ export type FragmentCacheKey = [
10
+ cacheId : string ,
11
+ fragment : DocumentNode ,
12
+ stringifiedVariables : string ,
13
+ ] ;
14
+
9
15
export interface QueryKey {
10
16
__queryKey ?: string ;
11
17
}
You can’t perform that action at this time.
0 commit comments