Commit 6428fe3
authored
fix(react-db): use collection.status instead of snapshot in useLiveSuspenseQuery to avoid infinite fallback loops (#1427)
fix(react-db): read collection.status instead of snapshot in useLiveSuspenseQuery (#1418)
result.status can be stale because it comes from the useSyncExternalStore snapshot,
while result.collection is a live mutable reference.
This may cause an inconsistent render where:
- result.status === "loading"
- result.collection.status === "ready"
Switching to result.collection.status ensures Suspense uses the latest state
and prevents infinite fallback loops.
Changes:
- introduce collectionStatus variable
- replace all status checks (loading, idle, error, ready) with collectionStatus
- move isEnabled check before accessing result.collection1 parent cde8af1 commit 6428fe3
2 files changed
Lines changed: 17 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | 173 | | |
180 | 174 | | |
181 | 175 | | |
| |||
189 | 183 | | |
190 | 184 | | |
191 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
192 | 196 | | |
193 | 197 | | |
194 | | - | |
| 198 | + | |
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
198 | 202 | | |
199 | 203 | | |
200 | 204 | | |
201 | | - | |
| 205 | + | |
202 | 206 | | |
203 | 207 | | |
204 | 208 | | |
| |||
0 commit comments