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(preact): Check operations for key difference only (#3266)

authored by

Phil Pluckthun and committed by
GitHub
3526e2a4 3d6b0c83

+22 -1
+5
.changeset/yellow-shrimps-admire.md
··· 1 + --- 2 + '@urql/preact': patch 3 + --- 4 + 5 + Apply shallow difference patch from React bindings to `@urql/preact` (See: #3195)
+17 -1
packages/preact-urql/src/hooks/useSource.ts
··· 8 8 9 9 let currentInit = false; 10 10 11 + // Two operations are considered equal if they have the same key 12 + const areOperationsEqual = ( 13 + a: { key: number } | undefined, 14 + b: { key: number } | undefined 15 + ) => { 16 + return a === b || !!(a && b && a.key === b.key); 17 + }; 18 + 11 19 const isShallowDifferent = (a: any, b: any) => { 12 20 if (typeof a != 'object' || typeof b != 'object') return a !== b; 13 21 for (const x in a) if (!(x in b)) return true; 14 - for (const x in b) if (a[x] !== b[x]) return true; 22 + for (const key in b) { 23 + if ( 24 + key === 'operation' 25 + ? !areOperationsEqual(a[key], b[key]) 26 + : a[key] !== b[key] 27 + ) { 28 + return true; 29 + } 30 + } 15 31 return false; 16 32 }; 17 33