···11+---
22+'urql': patch
33+---
44+55+Avoid unnecessary re-render when two components use the same query but receive unchanging results, due to differing operations
+1-1
CONTRIBUTING.md
···75757676```sh
7777# TypeScript checks:
7878-pnpnm run check
7878+pnpm run check
79798080# Linting (prettier & eslint):
8181pnpm run lint
+24-5
packages/react-urql/src/hooks/state.ts
···99 operation: undefined,
1010};
11111212-const isShallowDifferent = (a: any, b: any) => {
1313- if (typeof a != 'object' || typeof b != 'object') return a !== b;
1414- for (const x in a) if (!(x in b)) return true;
1515- for (const x in b) if (a[x] !== b[x]) return true;
1212+// Two operations are considered equal if they have the same key
1313+const areOperationsEqual = (
1414+ a: { key: number } | undefined,
1515+ b: { key: number } | undefined
1616+) => {
1717+ return a === b || !!(a && b && a.key === b.key);
1818+};
1919+2020+/**
2121+ * Checks if two objects are shallowly different with a special case for
2222+ * 'operation' where it compares the key if they are not the otherwise equal
2323+ */
2424+const isShallowDifferent = <T extends Record<string, any>>(a: T, b: T) => {
2525+ for (const key in a) if (!(key in b)) return true;
2626+ for (const key in b) {
2727+ if (
2828+ key === 'operation'
2929+ ? !areOperationsEqual(a[key], b[key])
3030+ : a[key] !== b[key]
3131+ ) {
3232+ return true;
3333+ }
3434+ }
1635 return false;
1736};
1837···2746 prevState: T,
2847 result: Partial<T>
2948): T => {
3030- const newState = {
4949+ const newState: T = {
3150 ...prevState,
3251 ...result,
3352 data: