Skip to content

Commit 0c9f8cf

Browse files
committed
fix
1 parent 3b82d78 commit 0c9f8cf

File tree

3 files changed

+11
-65
lines changed

3 files changed

+11
-65
lines changed

packages/shared/src/react/hooks/createCacheKeys.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export function createCacheKeys<
1111
authenticated: boolean;
1212
tracked: T;
1313
untracked: U extends { args: Params } ? U : never;
14-
15-
//U extends undefined ? never : U extends { args: Params } ? U['args'] : never;
1614
}) {
1715
return {
1816
queryKey: [params.stablePrefix, params.authenticated, params.tracked, params.untracked] as const,

packages/shared/src/react/hooks/usePageOrInfinite.types.ts

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,6 @@ export type ArrayType<DataArray> = DataArray extends Array<infer ElementType> ?
44

55
export type ExtractData<Type> = Type extends { data: infer Data } ? ArrayType<Data> : Type;
66

7-
// export type UsePagesOrInfiniteSignature = <
8-
// Params extends PagesOrInfiniteOptions,
9-
// FetcherReturnData extends Record<string, any>,
10-
// TCacheKeys extends {
11-
// stableKey: string;
12-
// trackedKeys: {
13-
// [key: string]: unknown;
14-
// args?: Record<string, unknown>;
15-
// };
16-
// untrackedKeys: {
17-
// [key: string]: unknown;
18-
// args?: Record<string, unknown>;
19-
// };
20-
// },
21-
// CacheKeys extends Record<string, unknown> = Record<string, unknown>,
22-
// TConfig extends PagesOrInfiniteConfig = PagesOrInfiniteConfig,
23-
// >(
24-
// /**
25-
// * The parameters will be passed to the fetcher.
26-
// */
27-
// params: Params,
28-
// /**
29-
// * A Promise returning function to fetch your data.
30-
// */
31-
// fetcher: ((p: Params) => FetcherReturnData | Promise<FetcherReturnData>) | undefined,
32-
// acacheKeys: TCacheKeys,
33-
// /**
34-
// * Internal configuration of the hook.
35-
// */
36-
// config: TConfig,
37-
// cacheKeys: CacheKeys,
38-
// ) => PaginatedResources<ExtractData<FetcherReturnData>, TConfig['infinite']>;
39-
407
type Config = PagesOrInfiniteConfig & PagesOrInfiniteOptions;
418

429
interface Register {
@@ -76,26 +43,9 @@ export type UsePagesOrInfiniteSignature = <
7643
invalidationKey: AnyQueryKey;
7744
stableKey: string;
7845
},
79-
// CacheKeys extends Record<string, unknown> = Record<string, unknown>,
8046
TConfig extends Config = Config,
81-
>(
82-
// /**
83-
// * The parameters will be passed to the fetcher.
84-
// */
85-
// params: Params,
86-
// /**
87-
// * A Promise returning function to fetch your data.
88-
// */
89-
// fetcher: ((p: Params) => FetcherReturnData | Promise<FetcherReturnData>) | undefined,
90-
// acacheKeys: TCacheKeys,
91-
// /**
92-
// * Internal configuration of the hook.
93-
// */
94-
// config: TConfig,
95-
// cacheKeys: CacheKeys,
96-
params: {
97-
fetcher: ((p: Params) => FetcherReturnData | Promise<FetcherReturnData>) | undefined;
98-
config: TConfig;
99-
keys: TCacheKeys;
100-
},
101-
) => PaginatedResources<ExtractData<FetcherReturnData>, TConfig['infinite']>;
47+
>(params: {
48+
fetcher: ((p: Params) => FetcherReturnData | Promise<FetcherReturnData>) | undefined;
49+
config: TConfig;
50+
keys: TCacheKeys;
51+
}) => PaginatedResources<ExtractData<FetcherReturnData>, TConfig['infinite']>;

packages/shared/src/react/hooks/usePagesOrInfinite.rq.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ export const usePagesOrInfinite: UsePagesOrInfiniteSignature = params => {
7272
return undefined as any;
7373
}
7474

75-
// Why do we need this ? can we just specify which `args` to use in the key ?
76-
// const requestParams = getDifferentKeys(key, cacheKeys);
7775
return fetcher(args);
7876
},
7977
staleTime: 60_000,
@@ -116,14 +114,14 @@ export const usePagesOrInfinite: UsePagesOrInfiniteSignature = params => {
116114
const isNowSignedOut = isSignedIn === false;
117115

118116
if (previousIsSignedIn && isNowSignedOut) {
119-
// Clear ALL queries matching the base query keys (including old userId)
120-
// Use predicate to match queries that start with 'clerk-pages' or 'clerk-pages-infinite'
121-
122117
queryClient.removeQueries({
123118
predicate: query => {
124-
const key = query.queryKey;
125-
// Clear all queries that are marked as authenticated
126-
return Array.isArray(key) && key[1] === true;
119+
const [stablePrefix, authenticated] = query.queryKey;
120+
return (
121+
authenticated === true &&
122+
typeof stablePrefix === 'string' &&
123+
(stablePrefix === keys.queryKey[0] || stablePrefix === keys.queryKey[0] + '-inf')
124+
);
127125
},
128126
});
129127

0 commit comments

Comments
 (0)