Skip to content

Fix flaky CKEditor caret placement in e2e tests (Firefox mid-word failure on master) - #473

Merged
bartekplus merged 5 commits into
masterfrom
claude/fix-ckeditor-midword-flake
Oct 5, 2026
Merged

bartekplus merged 5 commits into
masterfrom
claude/fix-ckeditor-midword-flake

Conversation

@bartekplus

@bartekplus bartekplus commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Master failed in E2E Full (firefox, 2/2):
CKEditor inline preview hides trailing word chars when caret is mid-word timed out waiting for the inline preview.

Root cause

The test seeds "The dog walked the street", sets the caret with a DOM selection at "Th|e", and types "r" at once.

CKEditor 5 copies a DOM selection into its model only when the next selectionchange event arrives, which is asynchronous. If the key arrives first (a slow runner), CKEditor inserts the "r" at its old model caret, offset 0 after setData. The new failure dump shows exactly this:

CKEditor state: {"dom":"rThe dog walked the street","model":"<p>rThe dog walked the street</p>","caret":1,...}

"rThe" is not the mid-word case, so FluentTyper correctly shows no preview, and the test times out. This is a race in the test, not a product bug. It is also not caused by #472: this test runs in the same shard, after the same tests, as before. It failed 1 time in the last 24 runs of that shard.

Fix

  • New helper setCkEditorCaret(page, paragraph, offset | "end"). It focuses the editing view and sets the caret with editor.model.change(writer => writer.setSelection(...)). CKEditor renders the model selection to the DOM, so the model and the DOM agree before the key is typed.
  • It replaces the DOM-selection caret code in all three CKEditor tests that had the same race:
    • CKEditor inline preview hides trailing word chars when caret is mid-word
    • CKEditor preserves paragraph break when accepting suggestion at line end
    • CKEditor grammar/text-edit replacement applies in active second paragraph
  • When the mid-word preview times out, the test now reports the editor state (DOM text, model text, caret, focus, FluentTyper attributes).

Evidence

A temporary probe workflow ran on this PR (it is removed in the last commit):

Run Setup Result
Before the fix, normal load 6 × Firefox shard 2/2, plus 10 runs of the test alone all passed (the flake is rare)
Before the fix, all CPU cores busy 8 jobs × 15 runs every job failed, several runs each, always with "dom":"rThe dog…"
After the fix, all CPU cores busy 8 jobs × 15 runs × the 3 changed tests all 360 test runs passed

Locally: all CKEditor e2e tests pass in Chrome, and bun run check passes. Firefox does not start on my machine (Firefox 156 cannot create a profile on this macOS version), so CI is the Firefox check.

🤖 Generated with Claude Code

bartekplus and others added 5 commits October 5, 2026 10:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three CKEditor tests put the caret with a DOM selection and then typed
at once. CKEditor 5 copies a DOM selection into its model only on the
next "selectionchange" event. When the key came first (a slow Firefox
runner), CKEditor typed at the old model caret: "rThe dog walked the
street" in place of "Thre dog walked the street". The mid-word test
then saw no preview and failed on master.

setCkEditorCaret now sets the selection with model.change and focuses
the editing view, so the model and the DOM agree before the key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bartekplus bartekplus changed the title Fix flaky Firefox CKEditor mid-word inline preview test Fix flaky CKEditor caret placement in e2e tests (Firefox mid-word failure on master) Oct 5, 2026
@bartekplus
bartekplus marked this pull request as ready for review October 5, 2026 09:11
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@bartekplus
bartekplus merged commit 57105c5 into master Oct 5, 2026
13 checks passed
@bartekplus
bartekplus deleted the claude/fix-ckeditor-midword-flake branch October 5, 2026 09:34
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