Skip to content

Commit 673bdd3

Browse files
authored
fix: swr hooks support no revalidation (#871)
1 parent 98420fb commit 673bdd3

File tree

3 files changed

+451
-26
lines changed

3 files changed

+451
-26
lines changed

packages/plugins/swr/src/runtime/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export function useModelMutation<Args, Result, CheckReadBack extends boolean = b
255255
checkReadBack?: CheckReadBack
256256
) {
257257
const { endpoint, fetch, logging } = useHooksContext();
258-
const invalidate = useInvalidation(model, modelMeta);
258+
const invalidate = options?.revalidate !== false ? useInvalidation(model, modelMeta) : undefined;
259259
const { cache, mutate } = useSWRConfig();
260260

261261
return useSWRMutation(
@@ -282,7 +282,7 @@ export async function mutationRequest<Result, C extends boolean = boolean>(
282282
method: 'POST' | 'PUT' | 'DELETE',
283283
url: string,
284284
data: unknown,
285-
invalidate: Invalidator,
285+
invalidate?: Invalidator,
286286
fetch?: FetchFn,
287287
checkReadBack?: C
288288
): Promise<C extends true ? Result | undefined : Result> {
@@ -299,7 +299,10 @@ export async function mutationRequest<Result, C extends boolean = boolean>(
299299
fetch,
300300
checkReadBack
301301
);
302-
await invalidate(getOperationFromUrl(url), data);
302+
303+
if (invalidate) {
304+
await invalidate(getOperationFromUrl(url), data);
305+
}
303306
return r;
304307
}
305308

0 commit comments

Comments
 (0)