Skip to content

v6.5.6

Choose a tag to compare

@childrentime childrentime released this 07 Sep 03:30
· 20 commits to main since this release

Two bug fixes, both found and fixed by @rawsun007.

🐞 Bug Fixes

useIdle: cancels its timers on unmount

The effect's cleanup removed the event listeners but left both timers running: the idle countdown — ms long, a minute by default — and the 50ms timer inside the throttled activity handler. The mounted flag stopped the state update, so nothing warned; the timers just kept the effect's closure alive until they fired.

const { unmount } = renderHook(() => useIdle(60000))
unmount()
jest.getTimerCount() // 1 on 6.5.5, 0 now

Both are cancelled in cleanup now, the same way useThrottleFn and useDebounceFn already cancel theirs. (#222)

useCycleList: derives the next index from the current state

set read index from the render closure, so two calls in the same batch both computed from the same value and the second overwrote the first:

const [item, next, prev] = useCycleList(['a', 'b', 'c'])

// inside one event handler
next(); next()   // 6.5.5: advanced a single step → 'b'.  Now: 'c'
next(); prev()   // 6.5.5: landed on 'c'.               Now: back on 'a'

An empty list also made (index + i) % 0 NaN, which was stored as the index and never recovered. Both paths now go through the functional updater form, matching useCounter, and an empty list leaves the index untouched. (#221)

✅ Tests

391 tests, up from 378. useIdle gains its first spec file (5 tests — initial state, going idle after ms, activity clearing idle and restarting the countdown, and no timer left behind after unmount with and without prior activity); so does useCycleList (8 tests — init, forward and backward wrap-around, a step, several calls in one batch, a next/prev pair cancelling out, and an empty list). Five of the new tests fail on 6.5.5.

Full changelog: v6.5.5...v6.5.6