Skip to content

Commit

Permalink
fix(clerk-js,shared): Increase time-to-stale for less frequent revali…
Browse files Browse the repository at this point in the history
…dations (#2093)
  • Loading branch information
panteliselef committed Nov 10, 2023
1 parent 7f833da commit 492b8a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/gentle-pants-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
---

Increase the duration until data become stale for organization hooks.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ export const ActiveMembersList = () => {
return null;
}

const handleRoleChange = (membership: OrganizationMembershipResource) => (newRole: string) => {
return card
.runAsync(async () => {
return await membership.update({ role: newRole });
})
.catch(err => handleError(err, [], card.setError));
};
const handleRoleChange = (membership: OrganizationMembershipResource) => (newRole: string) =>
card.runAsync(() => membership.update({ role: newRole })).catch(err => handleError(err, [], card.setError));

const handleRemove = (membership: OrganizationMembershipResource) => async () => {
return card
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/src/react/hooks/usePagesOrInfinite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export const useWithSafeValues = <T extends PagesOrInfiniteOptions>(params: T |
} as T;
};

const cachingSWROptions = {
dedupingInterval: 1000 * 60,
focusThrottleInterval: 1000 * 60 * 2,
} satisfies Parameters<typeof useSWR>[2];

type ArrayType<DataArray> = DataArray extends Array<infer ElementType> ? ElementType : never;
type ExtractData<Type> = Type extends { data: infer Data } ? ArrayType<Data> : Type;

Expand Down Expand Up @@ -122,7 +127,7 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, options,
// @ts-ignore
return fetcher?.(requestParams);
},
{ keepPreviousData },
{ keepPreviousData, ...cachingSWROptions },
);

const {
Expand Down Expand Up @@ -152,6 +157,7 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, options,
// @ts-ignore
return fetcher?.(requestParams);
},
cachingSWROptions,
);

const page = useMemo(() => {
Expand Down

0 comments on commit 492b8a7

Please sign in to comment.