fix(#406): stop ChatView.dom.test leaking a react-virtual timer past teardown#409
Conversation
…teardown @tanstack/react-virtual schedules an isScrolling-reset debounce (a setTimeout, default 150ms) on every scroll and does NOT clear it on unmount. When that timer survived into the DOM-env teardown it fired as `ReferenceError: window is not defined` inside Timeout._onTimeout — an unhandled error vitest reports even though every assertion passed, false-redding CI (cost a false-red on #401, green on rerun). Fix: drive the suite on fake timers (`shouldAdvanceTime: true` keeps waitFor / async act resolving on real-time progress) and `vi.clearAllTimers()` in afterEach BEFORE `vi.useRealTimers()`, so any timer react-virtual left pending is dropped while the env still exists. Closes the race deterministically. Also hardens .gitignore with a `node_modules` (no trailing slash) entry so a worktree node_modules symlink can't be committed. Verified: the test file run 20x consecutively — 20/20 passed, 0 post-teardown errors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Closes #406.
Problem
ChatView.dom.test.tsintermittently false-reds CI: all tests pass but vitest reports one unhandled error —ReferenceError: window is not definedfrom@tanstack/virtual-coreTimeout._onTimeoutfiring after the DOM environment is torn down. Cost a false-red on #401 (green on rerun).Root cause
@tanstack/virtual-core(observeOffset) registers a scroll handler that, on every scroll event, schedules anisScrolling-reset debounce —targetWindow.setTimeout(() => cb(offset, false), isScrollingResetDelay)(default 150ms). Its unmount cleanup onlyremoveEventListeners the scroll handler; it never clears that pending timeout. The "mounts a different row window after scrolling" test dispatches a scroll near the end, leaving a ~150ms timer queued. If the env teardown wins the race, the callback runs against a torn-downwindow→ the unhandled ReferenceError.Fix
Drive the suite on fake timers and drop pending timers before restoring real ones:
beforeEach:vi.useFakeTimers({ shouldAdvanceTime: true })— the debounce lands in a registry we control;shouldAdvanceTimekeeps the clock progressing on real time so RTLwaitFor/ asyncactresolve normally.afterEach:cleanup()→vi.clearAllTimers()→vi.useRealTimers(). The stray debounce is dropped while the env still exists, closing the race deterministically (no reliance on the timer firing "in time").Also hardens
.gitignorewith anode_modules(no trailing slash) entry so a worktreenode_modulessymlink can't be committed.Verification
Ran the file 20x consecutively:
(grep for
window is not defined/Unhandled Error/_onTimeoutacross all 20 runs → none.)Single-run assertions still pass (2/2), and the run is faster (~848ms vs prior).
🤖 Generated with Claude Code