From ca06adefde1159cf8673e0190816c8e451f8a31b Mon Sep 17 00:00:00 2001 From: jdecroock Date: Tue, 24 May 2022 19:16:48 +0200 Subject: [PATCH 1/2] fix default storage not clearing idb batch result --- .changeset/two-masks-draw.md | 5 +++++ exchanges/graphcache/src/default-storage/index.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/two-masks-draw.md diff --git a/.changeset/two-masks-draw.md b/.changeset/two-masks-draw.md new file mode 100644 index 0000000000..d4ca6ed4d7 --- /dev/null +++ b/.changeset/two-masks-draw.md @@ -0,0 +1,5 @@ +--- +'@urql/exchange-graphcache': patch +--- + +Fix issue where our default-storage would persist data after it has been cleared diff --git a/exchanges/graphcache/src/default-storage/index.ts b/exchanges/graphcache/src/default-storage/index.ts index 49efd42f18..3e62b180c3 100644 --- a/exchanges/graphcache/src/default-storage/index.ts +++ b/exchanges/graphcache/src/default-storage/index.ts @@ -40,7 +40,7 @@ export const makeDefaultStorage = (opts?: StorageOptions): DefaultStorage => { const ENTRIES_STORE_NAME = 'entries'; const METADATA_STORE_NAME = 'metadata'; - const batch: Record = Object.create(null); + let batch: Record = Object.create(null); const timestamp = Math.floor(new Date().valueOf() / (1000 * 60 * 60 * 24)); const maxAge = timestamp - (opts.maxAge || 7); @@ -105,6 +105,7 @@ export const makeDefaultStorage = (opts?: StorageOptions): DefaultStorage => { ); transaction.objectStore(METADATA_STORE_NAME).clear(); transaction.objectStore(ENTRIES_STORE_NAME).clear(); + batch = Object.create(null); return getTransactionPromise(transaction); }); }, From eace89751e6dde2816b3663bd803cf6536d62bac Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Tue, 24 May 2022 19:03:12 +0100 Subject: [PATCH 2/2] Update two-masks-draw.md --- .changeset/two-masks-draw.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/two-masks-draw.md b/.changeset/two-masks-draw.md index d4ca6ed4d7..9ecd9050ad 100644 --- a/.changeset/two-masks-draw.md +++ b/.changeset/two-masks-draw.md @@ -2,4 +2,4 @@ '@urql/exchange-graphcache': patch --- -Fix issue where our default-storage would persist data after it has been cleared +Fix default storage persisting data after `clear()` was called on it