From c8424e245f15dcad46445c6e29026594ed394bbe Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 30 Sep 2020 16:24:05 +0100 Subject: [PATCH 1/2] Add experimental buffer fix for edge cases in Svelte/Preact --- exchanges/graphcache/src/cacheExchange.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/exchanges/graphcache/src/cacheExchange.ts b/exchanges/graphcache/src/cacheExchange.ts index 9c3bc99518..598ea059dc 100644 --- a/exchanges/graphcache/src/cacheExchange.ts +++ b/exchanges/graphcache/src/cacheExchange.ts @@ -11,13 +11,14 @@ import { import { filter, + combine, + scan, map, merge, pipe, share, fromPromise, fromArray, - buffer, take, mergeMap, concat, @@ -249,10 +250,15 @@ export const cacheExchange = (opts?: CacheExchangeOpts): Exchange => ({ // If no hydration takes place we replace this stream with an empty one const bufferedOps$ = hydration ? pipe( - sharedOps$, - buffer(fromPromise(hydration)), + combine( + pipe( + sharedOps$, + scan((acc: Operation[], x) => (acc.push(x), acc), []) + ), + fromPromise(hydration) + ), take(1), - mergeMap(fromArray) + mergeMap(zip => fromArray(zip[0])) ) : (empty as Source); From 4fcc2102435c15939fa33bb0fde04b160a43745b Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 30 Sep 2020 16:43:29 +0100 Subject: [PATCH 2/2] Add changeset --- .changeset/ninety-plants-peel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/ninety-plants-peel.md diff --git a/.changeset/ninety-plants-peel.md b/.changeset/ninety-plants-peel.md new file mode 100644 index 0000000000..37b434b044 --- /dev/null +++ b/.changeset/ninety-plants-peel.md @@ -0,0 +1,5 @@ +--- +'@urql/exchange-graphcache': patch +--- + +Fix a case where the `offlineExchange` would not start processing operations after hydrating persisted data when no operations arrived in time by the time the persisted data was restored. This would be more evident in Preact and Svelte due to their internal short timings.