Don't repaint comments when no highlight moved#3
Open
Fyko wants to merge 1 commit into
Open
Conversation
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.
Symptom
Open a document whose own content mutates on a timer (e.g. a live clock doing
el.textContent = ...every second) and the comments/annotations sidebar flashes on every tick — even though nothing about the comments changed.Root cause
The runtime injected into the document watches
document.bodywith aMutationObserver(collab-client.ts) so highlights stay anchored as the document reflows. Any mutation — including a one-character text swap from a clock — schedules a re-measure and posts a freshhighlights:positionsreport to the shell.In the shell, the non-animated branch of the
highlights:positionshandler (shell-client.ts) setsshouldRender = trueunconditionally:So every report triggers
renderComments(), repainting the sidebar even when every anchor is in the exact same place. A ticking document = a repaint per tick = the flash.Fix
Diff the incoming positions against the current ones and only repaint when something actually moved:
Real reflows (a highlight added/removed, content shifting an anchor) still report different positions and repaint as before; only the no-op reports are dropped. This also quiets unrelated spurious reports (resize jitter, etc.), not just clocks.
The document runtime still re-measures on mutation (cheap), it just no longer forces a paint when the result is identical.
Tests
pixelPositionsEqualextracted as a pure helper with unit coverage (identical / moved / added / removed).50 passed, typecheck clean.