Commit 5496c6a
authored
fix(appkit-ui): stabilize useAnalyticsQuery params reference to avoid infinite refetch (#321)
* fix(appkit-ui): stabilize useAnalyticsQuery params reference
useAnalyticsQuery treated `parameters` as a useMemo dep by reference. A
typical call site passes a fresh object literal every render
(`useAnalyticsQuery("k", { limit: sql.number(10) })`), which invalidated
the payload memo and re-ran `start` -> infinite refetch. The workaround
was for every consumer to wrap params in `useMemo` — a recurring footgun.
Stabilize the params reference inside the hook using a useRef + shallow
structural equality check. Analytics query params are produced by the
`sql.*` builders and are always 1-level objects keyed to primitives, so
shallow equality is sufficient and substantially cheaper than a full
deep-equal. No public API change.
Also considered: stable-stringify + cache-keying on the string. Rejected
because params are tiny, structural equality is what users actually
want, and TanStack Query / SWR ship the same approach.
Updates the LLM guide which previously told consumers to always memoize
params.
Co-authored-by: Isaac
Signed-off-by: James Broadhead <jamesbroadhead@gmail.com>
* fix(appkit-ui): bump tsconfig lib from ES2021 to ES2022
The override added DOM lib but accidentally downleveled inherited
ES2022 from the root tsconfig, breaking Object.hasOwn (used in the
shallowEqualParams helper).
Signed-off-by: James Broadhead <jamesbroadhead@gmail.com>
* docs: drop obsolete useMemo guidance from llm-guide
The hook now stabilizes parameters internally, so the bullet was just
telling an LLM not to do something it wouldn't have done unprompted.
Co-authored-by: Isaac
Signed-off-by: James Broadhead <jamesbroadhead@gmail.com>
---------
Signed-off-by: James Broadhead <jamesbroadhead@gmail.com>1 parent 5f5ee05 commit 5496c6a
4 files changed
Lines changed: 154 additions & 4 deletions
File tree
- docs/docs/development
- packages/appkit-ui
- src/react/hooks
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
| |||
Lines changed: 93 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
Lines changed: 60 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
13 | 62 | | |
14 | 63 | | |
15 | 64 | | |
| |||
79 | 128 | | |
80 | 129 | | |
81 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
82 | 137 | | |
83 | 138 | | |
84 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
85 | 143 | | |
86 | 144 | | |
87 | 145 | | |
| |||
94 | 152 | | |
95 | 153 | | |
96 | 154 | | |
97 | | - | |
| 155 | + | |
98 | 156 | | |
99 | 157 | | |
100 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
0 commit comments