@rpcbase/client 0.110.0 → 0.111.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.110.0",
3
+ "version": "0.111.0",
4
4
  "scripts": {
5
5
  "build-firebase": "webpack -c firebase/webpack.config.js",
6
6
  "build": "yarn build-firebase",
@@ -6,6 +6,9 @@ import debug from "debug"
6
6
  import _omit from "lodash/omit"
7
7
  import LZString from "lz-string"
8
8
 
9
+ // TODO: remove this when stable
10
+ import isEqual from "fast-deep-equal/react"
11
+
9
12
  import isEqualValues from "../../isEqualValues"
10
13
  import get_uid from "../../auth/get_uid"
11
14
 
@@ -50,6 +53,7 @@ const getUseQuery = (register_query) => (
50
53
 
51
54
  const [source, setSource] = useState()
52
55
 
56
+ const dataRef = useRef(null)
53
57
  const [data, setData] = useData({useStorage, storageKey, hasInitiallySetFromStorage})
54
58
 
55
59
  const [error, setError] = useState()
@@ -69,6 +73,8 @@ const getUseQuery = (register_query) => (
69
73
 
70
74
  const applyNewData = (newData, context) => {
71
75
  setData(newData)
76
+ // set data in a ref so that it doesn't force re-rendering ie: unsubscribe / resubscribe
77
+ dataRef.current = newData
72
78
 
73
79
  // we only save network queries
74
80
  if (useStorage && context.source === "network") {
@@ -158,7 +164,11 @@ const getUseQuery = (register_query) => (
158
164
  return
159
165
  }
160
166
 
161
- if (!isEqualValues(data, newData)) {
167
+ if (isEqual(data, newData) && !isEqualValues(data, newData) && __DEV__) {
168
+ alert("EQUALITY MISMATCH THIS SHOULD NOT HAPPPEND!!!", data, newData)
169
+ }
170
+
171
+ if (!isEqualValues(dataRef.current, newData)) {
162
172
  applyContext(context)
163
173
  applyNewData(newData, context)
164
174
  } else {
@@ -170,8 +180,10 @@ const getUseQuery = (register_query) => (
170
180
  log && log("useQuery cleanup unsubscribe()")
171
181
  typeof unsubscribe === "function" && unsubscribe()
172
182
  }
183
+
184
+ // WARNING: do not change the hooks dependencies param or you risk creating infinite loops as it unsubscribes on cleanup
173
185
  // TODO: this isnt right we need to update on options change too
174
- }, [JSON.stringify(query), data, key])
186
+ }, [JSON.stringify(query), key])
175
187
 
176
188
 
177
189
  const loadNextPage = useCallback(() => {