Skip to content

fix(markdown-viewer): wait for ProseMirror's post-focus selection sync in the WebKit keyboard selection proof - #10391

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/markdown-webkit-keyboard-selection
Nov 25, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/markdown-webkit-keyboard-selection

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the WebKit flake in the markdown-viewer HTTP e2e ("edit and reload an off-screen cell on a narrow screen": Keyboard selection did not select text ... anchorOffset 1, focusOffset 1).

Root cause. prosemirror-view's focus handler schedules a setTimeout(…, 20) that writes ProseMirror's state selection back to the DOM if the DOM selection differs from the one it last observed. The test clicks "bold" (which focuses the editor) and presses ArrowLeft / Shift+ArrowRight within a few milliseconds. In WebKit, selectionchange is dispatched as a separate task after the key's native selection change, so the 20 ms timer can run in between: the DOM already holds the extended selection, ProseMirror's state does not yet, and the timer collapses the DOM back to the stale caret. No transaction is involved.

Evidence from CI traces on this branch (temporary instrumentation, since removed):

  • Failing attempt: keydown Shift+ArrowRight → selectionchange dom=bold:1/bold:1, with no ProseMirror transaction in between.
  • Passing attempts show the same revert landing on ArrowLeft instead: Selection.collapse(bold,2) called from ProseMirror's setSelection ← selectionToDOM ← an anonymous timer callback, 26–29 ms after the editor's focus event. When it hits ArrowLeft the test still passes (it then selects "l" rather than "o"); when it hits Shift+ArrowRight it fails.
  • A control-vs-fix loop (25 WebKit reloads each): the control arm selected "l" once (the revert), the fixed arm selected "o" 25/25.

This is a test race, not a product bug: a person cannot press a key within 20 ms of clicking.

Fix. Before the click, the test arms a same-delay (20 ms) timer from a focus listener registered after ProseMirror's (or immediately, if the editor already has focus). Timers with equal delays fire in the order they were set, so when that flag flips, ProseMirror's post-focus sync has already run. The test waits on the flag before pressing keys. There are no sleeps, retries, or longer timeouts, and the existing diagnostic message stays.

Type of Change

  • Bug fix (test flake)

Testing

  • CI checks / e2e (markdown-viewer) with the traces and loops described above (experiment commits were dropped from the branch).
  • checks / e2e (markdown-viewer) must pass on the final commit.

Checklist

  • Test-only change; no product code touched
  • Temporary instrumentation removed
  • Waits on an exact ordering condition, with no sleeps or retries

@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 25, 2026 1:03am UTC

Request Review

@waleedlatif1
waleedlatif1 force-pushed the fix/markdown-webkit-keyboard-selection branch from e775f3c to 838f57b Compare November 25, 2026 01:03
@waleedlatif1 waleedlatif1 changed the title test(markdown-viewer): experiment — trace webkit keyboard selection (do not merge) fix(markdown-viewer): wait for ProseMirror's post-focus selection sync in the WebKit keyboard selection proof Nov 25, 2026
@waleedlatif1
waleedlatif1 marked this pull request as ready for review November 25, 2026 01:03
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This test-only change appears safe to merge.

Summary

Adds a focus-linked wait before the Markdown editor’s keyboard-selection check.

  • The keyboard selection proof waits for the editor’s focus sync.

The end-to-end suite was not run during this review.

Reviews (1) · Last reviewed commit: "fix(markdown-viewer): wait for ProseMirr..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai 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 issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 92c7057 into staging Nov 25, 2026
85 of 87 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/markdown-webkit-keyboard-selection branch November 25, 2026 01:38

This branch was previously deployed

1 inactive deployment
Preview — 838f57be Deployed Nov 25, 2026 by vercel[bot]
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