Commit aee8920
committed
Fix coalescing breaking isLoading/activeQueryId invariant (v1.0.15)
CRITICAL BUG: The impossible state (isLoading=true + activeQueryId=null) was caused
by coalescing paths setting isLoading without setting activeQueryId.
The Bug You Found:
User reported seeing isLoading=true but activeQueryId=null, which should be
impossible. This breaks the core invariant that activeQueryId should be set
whenever isLoading=true.
Root Cause:
When a request coalesced to an existing in-flight request:
- Line 1519: Collection coalescing set isLoading=true, no activeQueryId
- Line 1576: Item coalescing set isLoading=true, no activeQueryId
Timeline:
1. First request: activeQueryId=qid1, isLoading=true
2. Second request coalesces: isLoading=true (again), activeQueryId still qid1
3. First request completes: activeQueryId=null, isLoading=false
4. Second request sees: activeQueryId=null, isLoading=true ← IMPOSSIBLE STATE
The Fix:
1. Removed isLoading=true assignments from coalescing paths
2. Added isCollectionLoading() function (parallel to isItemLoading)
3. Updated fetchCollection to sync isLoading with in-flight state
4. Updated fetchItem already had this sync (line 1713-1716)
5. Exported isCollectionLoading in public API
Now both fetchItem and fetchCollection sync isLoading with actual in-flight
state, maintaining the invariant without breaking it in coalescing paths.
The Invariant:
if (isLoading === true) then (activeQueryId !== null OR in-flight request exists)
Version: 1.0.14 → 1.0.151 parent 9d80f0e commit aee8920
2 files changed
+19
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1241 | 1241 | | |
1242 | 1242 | | |
1243 | 1243 | | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
1244 | 1249 | | |
1245 | 1250 | | |
1246 | 1251 | | |
| |||
1516 | 1521 | | |
1517 | 1522 | | |
1518 | 1523 | | |
1519 | | - | |
| 1524 | + | |
| 1525 | + | |
1520 | 1526 | | |
1521 | 1527 | | |
1522 | 1528 | | |
| |||
1572 | 1578 | | |
1573 | 1579 | | |
1574 | 1580 | | |
1575 | | - | |
1576 | | - | |
| 1581 | + | |
| 1582 | + | |
1577 | 1583 | | |
1578 | 1584 | | |
1579 | 1585 | | |
| |||
1699 | 1705 | | |
1700 | 1706 | | |
1701 | 1707 | | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
1702 | 1715 | | |
1703 | 1716 | | |
1704 | 1717 | | |
| |||
2139 | 2152 | | |
2140 | 2153 | | |
2141 | 2154 | | |
| 2155 | + | |
2142 | 2156 | | |
2143 | 2157 | | |
2144 | 2158 | | |
| |||
2164 | 2178 | | |
2165 | 2179 | | |
2166 | 2180 | | |
| 2181 | + | |
2167 | 2182 | | |
2168 | 2183 | | |
2169 | 2184 | | |
| |||
0 commit comments