fix: resolved comment checkmark toggles the card again (fixes #268)#269
Merged
fix: resolved comment checkmark toggles the card again (fixes #268)#269
Conversation
PagedEditor.updateSelectionOverlay fires from six paths — transactions, view-ready, font-load, ResizeObserver, layout effect, HiddenPM selection change — but the onSelectionChange callback fired unconditionally on every one of them. Any overlay redraw re-invoked consumers with the unchanged cursor; in the sidebar-expansion branch added by #244 that meant the ResizeObserver fired right after the click that set expandedSidebarItem, re-ran the cursor-mark detector against the (unchanged) cursor at the document end, and cleared the expansion within a frame — so the checkmark click looked like it did nothing. Fix at the source: dedup by PM state identity. States are immutable, so reference equality is the canonical "nothing changed" signal and covers selection / doc / stored-marks changes in one check. Overlay geometry redraw still runs — only the public callback is guarded. Also adds a comprehensive e2e suite (comments-sidebar.spec.ts, 11 tests) covering cursor-based expansion, resolve/reopen, and feedback-loop stability. The resize-specific test fails without the dedup (verified by stashing the fix) and passes with it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Resolved comments in the sidebar should stay collapsed to the checkmark marker unless the user clicks it. Previously, the cursor-mark detector treated resolved and active comments the same — any time the cursor passed through previously-commented text (editing near it, arrow keys, text selection), the old thread re-opened in the sidebar. Skip comments with done=true in the cursor→sidebar sync. Marker click is now the only way to re-open a resolved thread. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…lved Clicking Resolve now immediately collapses the card to its checkmark marker. The resolve handler updates React state only (no PM transaction), so the cursor-based collapse path never fired — the card hung around expanded until the user clicked somewhere in the doc. Explicitly clear expandedSidebarItem in the handler. This also cascades into the doc-body highlight: resolvedIdsForRender was already excluding the currently-expanded resolved comment so its range gets highlighted, then including all others so their yellow is hidden. With the card now collapsing on resolve, the highlight correctly disappears at the same instant. Clicking the checkmark re-expands the card AND re-shows the highlight on that comment's range only. 3 new e2e tests: - clicking Resolve immediately collapses the card - resolved comment highlight is hidden in the doc body by default - expanding a resolved comment re-shows the highlight on its range only Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Was doing comments.find() per mark per selection change; swap to the already-memoized Set lookup. O(n)→O(1), and the intent reads better. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two interaction gaps: 1. Expanded cards only collapsed when the user clicked inside the PM doc body, because that's what moved the cursor and triggered the cursor→ sidebar sync. Clicks in the grey area around the page didn't touch PM state, so the card hung around. Add a mousedown handler on the scroll container: if the target is not inside the pages, sidebar, or margin markers, clear expandedSidebarItem. 2. Toggling the sidebar off and back on preserved expandedSidebarItem across re-render, so a previously-expanded resolved comment came back as a full card instead of the checkmark default. Clear expansion on user-initiated toggle. 2 new e2e tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fallout from the state-identity dedup: updateSelectionOverlay no longer re-fires onSelectionChange for overlay-only redraws, so the button's geometry callers stopped getting called on window resize / sidebar toggle / loading→ready. The button's `left` is computed from the page's right edge, and the page re-centers on resize, so the button would strand at the stale coordinate while the page moved underneath it. Extract the position logic into a stable callback and drive it from its own ResizeObserver + window-resize listener + zoom effect. Re-run on state.isLoading changes so the observer gets attached after the loading subtree swaps in (the scroll container doesn't exist on first mount). 2 new e2e tests (regression-verified by stashing the fix): - floating button re-anchors to page right edge after window resize - floating button tracks page right edge across multiple resize steps Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Regression in 0.0.34: clicking the checkmark of a resolved comment in the sidebar did not re-open the comment card. Reported in #268.
Root cause
The cursor-based sidebar expansion refactor (#244) moved expansion state to the parent (
DocxEditor), driven byPagedEditor.onSelectionChange. ButPagedEditor.updateSelectionOverlay()fires that callback from six call sites — transactions, view-ready, font-load, aResizeObserveron the container, a[layout]effect, and HiddenPM's selection-change path. Four of those fire even when PM state hasn't changed.Click flow for the resolved checkmark:
onMouseDownstops propagation, so the PM cursor does not move.onClick → toggleExpand→setExpandedSidebarItem('comment-X').CommentCard→ container size changes.ResizeObserverfires →updateSelectionOverlay→onSelectionChange(from, to)with the unchanged cursor.cursorSidebarItem = null→setExpandedSidebarItem(null).Fix
Dedup at the source by PM state identity in
updateSelectionOverlay:PM states are immutable, so reference equality is the canonical "nothing changed" signal — covers selection, doc, and stored-marks changes in one check. Overlay geometry redraw still runs; only the public callback is guarded.
Why this over a consumer-side guard in
DocxEditor:onSelectionChangebenefits (toolbar sync, cursor-mark detection, useronSelectionChangeprop), not just the sidebar branch.(from, to)compare would wrongly skip.Tests
New
e2e/tests/comments-sidebar.spec.ts— 11 scenarios across three groups:Also adds
data-comment-id/data-comment-resolvedattributes toResolvedCommentMarkerfor reliable test targeting, and registers the new suite inCLAUDE.mdso future PRs touchingUnifiedSidebar/sidebar/**/updateSelectionOverlayrun it.Test plan
bun run typecheckcleancomments-sidebar.spec.tstests passresize while a resolved card is expanded does not collapse itfails onmainwithout the dedup (verified by stashing PagedEditor.tsx and re-running)🤖 Generated with Claude Code