Skip to content

Cancel review animations and timers when the Markdown preview closes - #24644

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-markdown-review-frame-cleanup-20261002
Oct 3, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-markdown-review-frame-cleanup-20261002

Conversation

@nwparker

@nwparker nwparker commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​457 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​457
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​106 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​86

ELI5

Closing a Markdown preview cancels its waiting review animations and highlight timers.

What Changed

Review clicks could leave waiting frames behind after the preview closed. Those frames could start a highlight timer later; rapid clicks could also leave an older timer behind. Preview teardown now tracks and cancels every frame and timer belonging to the detached preview. A generation check makes late callbacks harmless.

Live clicks keep their two frames, smooth scroll, highlight, order and 900 ms expiry. Large-document search and immediate source-line navigation are preserved.

Why

The preview already owns its DOM lifetime, and the editor already tracks frames. Reusing those owners fixes abandoned work while keeping live navigation and rapid clicks unchanged. Coalescing clicks or changing highlight timing would change the experience.

Linked Issue

Internal maintainer-requested performance audit; no pre-existing issue, under the template's maintainer exception.

Visual Proof

N/A — live rendering and interactions are unchanged; only callbacks belonging to a closed preview are canceled.

Testing

The actual review hooks pass 15 lifecycle tests, including 64 close/reopen cycles, StrictMode, rapid live clicks, virtual navigation, same-node replacement, synchronous frames and reentrant cleanup. Ten cases fail against stock, with live compatibility controls retained. Earlier source-qualified owner and neighbor verification passed 162 tests; the five Markdown files are unchanged since that verification except for two required inert search mocks.

The same five Markdown source files passed complete CI on the prior qualified head53a5b080, including all five Node24 test shards, relay integration, typecheck, static analysis, normal/Windows packaging and test-selection evidence. Main8cd retains their exact baselines; upstream retention/chat fixture repairs and every other main file are preserved. Full CI passed for final resolved headf958d486: all five Node24 test shards, relay integration, typecheck, static analysis, normal/Windows packaging and final test-selection checks. CI run. All local tests used ORCA_BACKGROUND_LAUNCH=1; scoped lint and formatting passed.

  • Manual rendered Electron navigation checked
  • Automated lifecycle and compatibility regressions added
  • Full exact-head CI passed

Review

Independent reviewers and root approved the scoped cleanup and preservation of current-main behavior. Pullfrog reported no new issue on the prior seven-file head; its five Markdown files are unchanged. CodeRabbit reported no actionable code issue on the unchanged cleanup. Independent reviewers and root verified the preservation of both upstream fixtures. The generic docstring-coverage suggestion is declined under AGENTS.md, which calls for brief comments explaining non-obvious reasons. No actionable code finding or review thread was unresolved on the prior reviewed head. Current exact-head CI and Pullfrog checks passed, no review thread was unresolved at merge, and the final bot disposition is recorded.

Agent skill upstream boundary

  • Not applicable; no upstream skill material changed.

Notes

No scheduling policy, polling, coalescing, persistence, file identity or remote protocol changed. Folder workspaces, local/SSH/WSL ownership and native mobile are unaffected. Hidden Electron scheduling and physical Windows/Linux scroll and selection journeys are unclaimed; focused tests establish owner cleanup and unchanged live timing. Final merge risk is Low for this scoped change.

Checklist

  • Small, focused change with measured before/after behavior
  • User-facing behavior, mechanism and approach explained
  • Visual proof N/A explained
  • Independently reviewed for correctness and performance
  • Cross-platform and remote/workspace impact considered
  • Full exact-head CI passed

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b1df3f11-2222-4a3f-b58e-49975302f93a
📥 Commits

Reviewing files that changed from the base of the PR and between 8cf97064e22782c5abff4a6d05ff1eb4267fe5f7 and 8fd47cab66375434286694f611965378ad0845db.

📒 Files selected for processing (1)
  • src/main/claude/claude-child-work-evidence-retention.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The preview foundation now tracks review-action animation frames, timeouts, and a generation counter. Review-note actions check mount state and generation before updating attention or scrolling. Preview cleanup invalidates pending actions, clears tracked timeouts, and cancels tracked frames. Lifecycle tests cover unmounts, stale callbacks, concurrent pulses, replacement, reentrancy, and synchronous animation-frame behavior. The Claude child-work evidence-retention test now supplies a prompt registry to the drain call.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 8fd47

The lifecycle changes have broad reported focused coverage, but the required exact-head platform/provider CI has not run. Wait for it to validate platform scheduling and visible review navigation before merging.

Architecture Summary

Architecture risk: 🔵 Low · up to 8fd47

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (ui) was modified; 6 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/renderer/src/components/editor/markdown-preview-review-timer-cleanup.ts: Added an exported helper that clears the latest timeout when non-null, resets its ref, and clears pending timeouts other than the latest timeout.
  • observed — Modified behavior in src/renderer/src/components/editor/markdown-preview-review-frame-lifecycle.test.tsx: Added test helpers that create a mounted review surface with hook fixtures, optional StrictMode and virtual navigation, queued animation frames, and cleanup tracking. Mounting throws when required hook state or the rendered review card is missing.
  • observed — Modified behavior in src/renderer/src/components/editor/markdown-preview-review-frame-lifecycle.test.tsx: Added timer and global setup before each test, plus unmounting and restoration of timers, mocks, and globals after each test.
  • observed — Modified behavior in src/renderer/src/components/editor/markdown-preview-review-frame-lifecycle.test.tsx: Added assertions that review-note navigation uses virtual source-line navigation immediately when it succeeds, without querying rendered cards or scheduling frames. The tests also check that callbacks captured before root removal do not scroll or start timers, and that unsuccessful or unavailable virtual navigation falls back to smooth scrolling.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: canceling review animations and timers when the Markdown preview closes.
Description check ✅ Passed The description covers the required sections, explains the change and rationale, documents testing and review, and states why visual proof is not applicable. It also clearly identifies that manual ren…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — Preview review-note navigation cleanup.

  • Track review frames: the click highlight/scroll requestAnimationFrames now schedule through requestMarkdownPreviewEditorRevealFrame and register in pendingReviewActionFrameIdsRef, so teardown can cancel them.
  • Track all pulse timers: the 900 ms highlight-expiry setTimeouts are recorded in pendingReviewActionTimeoutIdsRef in addition to the single latest ref; a new clearMarkdownPreviewReviewTimers helper clears the latest plus every pending id.
  • Generation guard: reviewActionFrameGenerationRef is bumped on setRootRef(null); every async step in the click path re-checks isCurrent() (mounted and same generation), so captured callbacks and late actions after unmount do nothing.
  • Teardown: cleanupPreviewSurfaceTimers now snapshots/resets both pending arrays, cancels the snapshotted review frames, and clears the pulse timers.
  • Tests: new 14-case markdown-preview-review-frame-lifecycle.test.tsx covering 64 mount/click/unmount cycles, StrictMode, rapid clicks, same-node replacement, reentrant disposal, and synchronous-frame shims.

I verified the new tests actually fail against stock (pre-PR) code — 9 of 14 fail, including the 128-pending-frames-after-64-unmounts assertion — so this pins a real leak rather than asserting a tautology. The new test passes on head, and pnpm run check:code-quality:changed and pnpm tc:web are clean. Rapid clicks still leave two live pulse timers (matching stock behavior), but the orphan is now tracked, so teardown clears it; keeping the pending array authoritative for cleanup is sound.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/perf-markdown-review-frame-cleanup-20261002 branch 2 times, most recently from 2202da4 to 72cc429 Compare October 3, 2026 07:11

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — delta since the prior pullfrog review (727e585 → 72cc429).

  • Rebased onto current main: 72cc4293 sits on main 53f9ea78; the review-frame/timer cleanup in use-markdown-preview-review-actions.ts, use-markdown-preview-viewport.ts, use-markdown-preview-foundation.ts, and markdown-preview-review-timer-cleanup.ts is byte-identical to the previously approved revision. The extra content seen in these files vs the old base (largePreview, largeNavigationRef, scrollToSourceLine, useMarkdownPreviewDomSearch, frontmatter removal) is inherited main churn, not PR-authored.
  • Test adapted to the new base: mountSurface gained largePreview/largeNavigationRef parameters and the review card now carries data-source-line/data-source-end-line attributes.
  • New control for the large-preview path: a test asserts that virtual sourceLine navigation stays immediate (active comment set, then source line, no DOM query), and that a later annotated-block click's captured pulse callbacks stay inert after setRootRef(null).

I reran the suite on head (15/15 pass) and against stock (product files reverted to HEAD~1): 10 tests fail, including the new virtual-navigation control and the 128-pending-frames-after-64-unmounts assertion, so this delta remains real coverage rather than a tautology. The prior approval stands; nothing in the new commits changes the cleanup's correctness.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/perf-markdown-review-frame-cleanup-20261002 branch 2 times, most recently from 8cf9706 to 8fd47ca Compare October 3, 2026 22:46

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — delta since the prior pullfrog review (72cc429 → 8fd47ca).

  • Repaired the Claude retention test fixture: claude-child-work-evidence-retention.test.ts now passes prompts: new ClaudePromptRegistry() (imported from ./claude-structured-prompt-replies) into drainClaudeChildWork, satisfying the session parameter's required prompts field. Without it the test fails the node typecheck, since base 1de8396 already types the parameter as Pick<ClaudeSession, 'childWork' | 'translator' | 'prompts'>.

The five Markdown review-frame/timer files are unchanged since the previously approved revision; the cleanup logic is identical. I reran markdown-preview-review-frame-lifecycle.test.tsx (15) and claude-child-work-evidence-retention.test.ts (3) on head — 18/18 pass — and confirmed the base signature requires prompts, so this is a necessary test-only fix with no production behavior change.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/perf-markdown-review-frame-cleanup-20261002 branch from 8fd47ca to 53a5b08 Compare October 3, 2026 23:12

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — delta since the prior pullfrog review (8fd47ca → 53a5b08), which also rebased the branch onto current main (60b1664).

  • Repaired the chat collision fixture: StructuredAgentSessionAttentionBridge.test.tsx now reads the publisher's tab, asserts the current publisher stamps executionHostId: 'runtime:env-1', then strips that field to reconstruct the legacy (unstamped) tab the case is meant to exercise, before running the subscription and delivery assertions.
  • Renamed the case: "keeps a legacy paired chat subscribed…" now reflects that it targets the older-client tab shape, preserving coverage of the unstamped path that resolveNotificationTabOwner falls through to worktree-based resolution for.
  • No product change: the four Markdown review-frame/timer files, the lifecycle test, and the Claude retention fixture are byte-identical to the previously approved revision (verified by blob hash), so the cleanup's correctness is unchanged.

I confirmed Tab.executionHostId is optional, so the stripped legacyFields still satisfies Tab, and ran the suite on head — 15/15 pass. This is a necessary test-only fixture repair with no production behavior change.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker

nwparker commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Final reviewed head 53a5b080dc4633d1cfc1596f66e18a8efe14f9d0 has green full CI, including all five Node24 shards, relay integration, typecheck, static analysis, normal/Windows packaging and test-selection evidence. The inherited chat fixture repair preserves all ten original collision/subscription/notification/unread assertions and additionally checks the current publisher stamp; its real suite passes15, with the unchanged fixture reproducing the CI failure.

Pullfrog reports no new issue on this exact head; the chat fixture has independent second-eye and root approval. The prior CodeRabbit review covers unchanged six-file bytes and generated no actionable code finding. Its pending-CI concern now has the full green run. The generic docstring suggestion is declined under AGENTS.md's concise non-obvious-comment rule. No review thread is unresolved.

Final scoped risk is Low: live review navigation, scroll/highlight timing, search and source-line behavior are preserved; only a detached preview's waiting work is retired. Native rendered/platform journeys remain unclaimed, as documented in the body. No production host-routing, notification or Claude-session contract was changed by either fixture repair.

Track review frames with the existing frame owner, remember all active pulse timers, and retire only the detached preview generation.
@nwparker
nwparker force-pushed the nwparker/perf-markdown-review-frame-cleanup-20261002 branch from 53a5b08 to f958d48 Compare October 3, 2026 23:33
@nwparker

nwparker commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Final resolved head f958d486b7eef959a7af4c4781c04f3045597297 has green full CI: all five Node24 test shards, relay integration, typecheck, static analysis, normal/Windows packaging and final test-selection checks.

This is the original five-file Markdown scope. Every scope blob exactly matches the approved prior green head, and both fixture repairs now in main are inherited unchanged. Independent second-eye and root verified all five source hashes and main baselines. The current Pullfrog check succeeds; prior no-new-issue reviews cover the same cleanup bytes. No review thread is unresolved. CodeRabbit's earlier pending-CI concern now has a full green run; its generic docstring suggestion remains declined under AGENTS.md's concise-comment rule.

Final scoped risk remains Low: live navigation, search, scroll/highlight timing and source-line behavior are preserved. Only the detached preview's waiting callbacks are retired. Native rendered/platform journeys remain explicitly unclaimed.

@nwparker
nwparker merged commit 92965f3 into main Oct 3, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant