Skip to content

fix(#406): stop ChatView.dom.test leaking a react-virtual timer past teardown#409

Merged
khaliqgant merged 1 commit into
mainfrom
fix/chatview-virtual-timer-flake
Jul 17, 2026
Merged

fix(#406): stop ChatView.dom.test leaking a react-virtual timer past teardown#409
khaliqgant merged 1 commit into
mainfrom
fix/chatview-virtual-timer-flake

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jul 17, 2026

Copy link
Copy Markdown
Member

Closes #406.

Problem

ChatView.dom.test.ts intermittently false-reds CI: all tests pass but vitest reports one unhandled error —
ReferenceError: window is not defined from @tanstack/virtual-core Timeout._onTimeout firing 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 an isScrolling-reset debouncetargetWindow.setTimeout(() => cb(offset, false), isScrollingResetDelay) (default 150ms). Its unmount cleanup only removeEventListeners 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-down window → 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; shouldAdvanceTime keeps the clock progressing on real time so RTL waitFor / async act resolve 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 .gitignore with a node_modules (no trailing slash) entry so a worktree node_modules symlink can't be committed.

Verification

Ran the file 20x consecutively:

=== 20x results: passed=20 failed=0 post-teardown-errors=0 ===

(grep for window is not defined / Unhandled Error / _onTimeout across all 20 runs → none.)
Single-run assertions still pass (2/2), and the run is faster (~848ms vs prior).

🤖 Generated with Claude Code

Review in cubic

…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>
@khaliqgant khaliqgant added the no-agent-relay-review Disable agent-relay automated PR review/fixes label Jul 17, 2026
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@khaliqgant, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b009f77d-faae-40a7-b316-7dd67040b9a9

📥 Commits

Reviewing files that changed from the base of the PR and between bea859f and 675c18c.

📒 Files selected for processing (2)
  • .gitignore
  • src/renderer/src/components/chat/ChatView.dom.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/chatview-virtual-timer-flake

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaliqgant
khaliqgant marked this pull request as ready for review July 17, 2026 16:12
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

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.

@khaliqgant
khaliqgant merged commit 188c3d5 into main Jul 17, 2026
4 checks passed
@khaliqgant
khaliqgant deleted the fix/chatview-virtual-timer-flake branch July 17, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-agent-relay-review Disable agent-relay automated PR review/fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChatView.dom.test.ts leaks a @tanstack/virtual timer past jsdom teardown (CI flake)

1 participant