Commit 354c1f3
committed
fix(ui): re-fire expiry notifications on each natural expiry (#84)
Root cause: useTimerExpiry tracked fired events via a firedRef Set keyed
on `id:startedAt`. After expiry, a restart sets a new startedAt (T2).
Because timersRef lags one render behind state, a brief window existed
where the hook ran with the new startedAt but remaining still computed
as 0 (stale snapshot). This added id:T2 to firedRef prematurely, so the
second natural expiry found the key already present and silently skipped.
Fix — two changes to useTimerExpiry:
1. Compute remaining directly from t.startedAt and t.remaining on the
timer object from the `timers` prop, bypassing timersRef entirely.
This is always up-to-date because TimerPanel/TimerPanel re-renders
with fresh `timers` state before useTimerExpiry sees it.
2. Evict the runKey from firedRef when a timer is actively running with
rem > 0. This ensures that if the key was somehow pre-added (e.g. a
stale render before the eviction fix was in place), the next active
run clears it so the subsequent natural expiry can fire.
Adds a regression test that verifies: expire → restart (running, no
fire) → expire again → fires a second time.
Closes #841 parent ca5659c commit 354c1f3
2 files changed
Lines changed: 61 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
212 | 221 | | |
213 | 222 | | |
214 | 223 | | |
| |||
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
222 | | - | |
223 | | - | |
224 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
225 | 248 | | |
226 | 249 | | |
227 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
155 | 191 | | |
156 | 192 | | |
157 | 193 | | |
| |||
0 commit comments