Skip to content

Commit

Permalink
Merge pull request #468 from psteinroe/fix/swr-revalidate
Browse files Browse the repository at this point in the history
fix: use only `mutate(key)` for revalidation
  • Loading branch information
psteinroe authored Jul 12, 2024
2 parents 50c35fb + 2874096 commit 1d2d9eb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-pants-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@supabase-cache-helpers/postgrest-swr": patch
---

fix: revalidation flicker due to undefined data passed to mutate
2 changes: 1 addition & 1 deletion packages/postgrest-swr/src/cache/use-delete-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function useDeleteItem<Type extends Record<string, unknown>>(
cacheKeys: getMutableKeys(Array.from(cache.keys())),
getPostgrestFilter,
revalidate: (key) => {
mutate(key, null, { ...opts, revalidate: true });
mutate(key);
},
mutate: (key, data) => {
mutate(key, data, { ...opts, revalidate: opts?.revalidate ?? false });
Expand Down
2 changes: 1 addition & 1 deletion packages/postgrest-swr/src/cache/use-mutate-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function useMutateItem<Type extends Record<string, unknown>>(
cacheKeys: getMutableKeys(Array.from(cache.keys())),
getPostgrestFilter,
revalidate: (key) => {
mutate(key, null, { ...opts, revalidate: true });
mutate(key);
},
mutate: (key, data) => {
mutate(key, data, {
Expand Down
2 changes: 1 addition & 1 deletion packages/postgrest-swr/src/cache/use-upsert-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function useUpsertItem<Type extends Record<string, unknown>>(
cacheKeys: getMutableKeys(Array.from(cache.keys())),
getPostgrestFilter,
revalidate: (key) => {
mutate(key, null, { ...opts, revalidate: true });
mutate(key);
},
mutate: (key, data) => {
mutate(key, data, {
Expand Down

0 comments on commit 1d2d9eb

Please sign in to comment.