Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(graphcache): avoid removing subscription layers (#2771)

authored by

Jovi De Croock and committed by
GitHub
3814959c 33054672

+27 -1
+5
.changeset/lucky-terms-greet.md
··· 1 + --- 2 + '@urql/exchange-graphcache': patch 3 + --- 4 + 5 + Ensure we aren't eagerly removing layers that are caused by subscriptions
+21
exchanges/graphcache/src/store/data.test.ts
··· 499 499 expect(data.optimisticOrder).toEqual([]); 500 500 }); 501 501 502 + it('does not erase data from a prior deferred layer when updating it', () => { 503 + // initially it's unknown whether a layer is deferred 504 + InMemoryData.reserveLayer(data, 1, true); 505 + InMemoryData.reserveLayer(data, 2, true); 506 + 507 + InMemoryData.initDataState('write', data, 2); 508 + InMemoryData.writeRecord('Query', 'index', 2); 509 + InMemoryData.clearDataState(); 510 + 511 + InMemoryData.initDataState('read', data, null); 512 + expect(InMemoryData.readRecord('Query', 'index')).toBe(2); 513 + 514 + // A subsequent reserve layer call should not erase the layer 515 + InMemoryData.reserveLayer(data, 2, true); 516 + InMemoryData.initDataState('read', data, null); 517 + expect(InMemoryData.readRecord('Query', 'index')).toBe(2); 518 + 519 + // The layers must not be squashed 520 + expect(data.optimisticOrder).toEqual([2, 1]); 521 + }); 522 + 502 523 it('keeps a deferred layer around even if it is the lowest', () => { 503 524 // initially it's unknown whether a layer is deferred 504 525 InMemoryData.reserveLayer(data, 1);
+1 -1
exchanges/graphcache/src/store/data.ts
··· 535 535 536 536 let index = data.optimisticOrder.indexOf(layerKey); 537 537 if (index > -1) { 538 - if (hasNext || !data.commutativeKeys.has(layerKey)) { 538 + if (!data.commutativeKeys.has(layerKey) && !hasNext) { 539 539 data.optimisticOrder.splice(index, 1); 540 540 // Protect optimistic layers from being turned into non-optimistic layers 541 541 // while preserving optimistic data