Skip to content

Commit

Permalink
(graphcache) - Fix offlineExchange timing after rehydration (#1019)
Browse files Browse the repository at this point in the history
* Add experimental buffer fix for edge cases in Svelte/Preact

* Add changeset
  • Loading branch information
kitten authored Sep 30, 2020
1 parent 5737b74 commit d8a09c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-plants-peel.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 10 additions & 4 deletions exchanges/graphcache/src/cacheExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import {

import {
filter,
combine,
scan,
map,
merge,
pipe,
share,
fromPromise,
fromArray,
buffer,
take,
mergeMap,
concat,
Expand Down Expand Up @@ -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<Operation>);

Expand Down

0 comments on commit d8a09c6

Please sign in to comment.