@homebound/beam 2.309.2 → 2.309.3

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.
@@ -26,21 +26,23 @@ function useComputed(fn, deps) {
26
26
  // If deps has changed, we're already re-running, so don't trigger a 2nd one
27
27
  current.hasRan = false;
28
28
  current.runner = (0, mobx_1.autorun)(() => {
29
- const { value: oldValue, hasRan: oldHasRun } = current;
29
+ const { value: oldValue, hasRan } = current;
30
30
  // Always eval fn() (even on 1st render) to register our observable.
31
31
  const newValue = fn(oldValue);
32
+ // If we've already run and the value hasn't changed, don't trigger a re-render
33
+ //
34
+ // Also, we avoid a deep equality, b/c if a `useComputed` is returning something complicated/cyclic,
35
+ // like ReactElement, deep equality will crawl into the guts of React/ReactFiber and cycle/infinite loop.
36
+ if (hasRan && (0, shallowEqual_1.shallowEqual)(newValue, oldValue))
37
+ return;
38
+ // Only change the identity of `current.value` after we've checked that it's not shallow equal
32
39
  current.value = newValue;
33
40
  current.hasRan = true;
34
41
  // Only trigger a re-render if this is not the 1st autorun. Note
35
42
  // that if deps has changed, we're inherently in a re-render so also
36
43
  // don't need to trigger an additional re-render.
37
- //
38
- // Also, we avoid a deep equality, b/c if a `useComputed` is returning something
39
- // complicated/cyclic, like ReactElement, deep equality will crawl into the guts
40
- // of React/ReactFiber and cycle/infinite loop.
41
- if (oldHasRun && !(0, shallowEqual_1.shallowEqual)(newValue, oldValue)) {
44
+ if (hasRan)
42
45
  setTick((tick) => tick + 1);
43
- }
44
46
  });
45
47
  // eslint-disable-next-line react-hooks/exhaustive-deps
46
48
  }, deps);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.309.2",
3
+ "version": "2.309.3",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",