Skip to content

fix: keep seeded content out of undo and stabilise the bubble-in-row matrix - #79

Merged
HMarzban merged 53 commits into
mainfrom
fix/bubble-matrix-flake
Nov 15, 2026
Merged

HMarzban merged 53 commits into
mainfrom
fix/bubble-matrix-flake

Conversation

@HMarzban

Copy link
Copy Markdown
Contributor

What and why

selection-bubble.spec.ts "bubble-in-row matrix" failed intermittently under load in Chromium and WebKit (6 of 40 runs at --repeat-each=20 --workers=6, both projects). Two separate root causes, one of them an app bug a user can hit.

Root cause 1 (app): addToHistory: false was lost when a plugin appended a transaction

  • UniqueID and the outline's TOC id plugin append a heading-id transaction to any change that adds a heading with text.
  • y-tiptap 3.3.0 reads addToHistory from each doc-changing transaction in turn, so the appended transaction (no meta) overrode the root's addToHistory: false, and the whole dispatch landed in the Yjs undo stack.
  • In the app: the Playground seed (headings with text) became an undo step. On a fresh Playground, Undo was enabled and wiped the seeded content, together with any edit made within the next 500 ms (the Yjs UndoManager capture window merges them). Verified on a production build with a fresh DB: Undo is aria-disabled="false" on main and "true" on this branch.
  • In the test: the fixture was loaded through EditorPage.setContent (undoable). When the first bubble Bold landed less than 500 ms later, it merged into the fixture's step, and undo() wiped the page. Next step: "some words" not found. Instrumented runs showed the stack at 1 item after the Bold, and the doc empty after undo.

Fix: patches/@tiptap%[email protected] (repo already uses patchedDependencies). A doc-changing transaction counts as addToHistory: false if it, or its appendedTransaction root, says so. This is a one-line change in ySyncPlugin's state apply. The scope is local dispatches made with addToHistory: false that get appended transactions. Ordinary user edits, including ones with appended ids, are recorded exactly as before. The new unit test tests/unit/lib/y-undo-history-intent.test.ts covers:

  • seed not undoable;
  • an edit right after it is its own step;
  • user setContent still undoable and redoable with ids;
  • a guard that a collaborator's new heading adds no local undo step (it passes with and without the patch).

The first two fail without the patch.

Root cause 2 (test): a click retry scrolled the page and the bubble flipped mid-click

The Link popover failures and the "mark missing from the bubble" failures share this cause. Event logging showed:

  1. The bubble was still sliding in, so Playwright's click saw "element is not stable" and retried.
  2. On the retry, Playwright scrolled its target into view with a forced alignment, and the wrapper scrolled by about 95 px.
  3. The text moved under the sticky row, so the bubble re-placed itself below the text between mousedown and mouseup.
  4. The click landed on main.document-editor-wrapper, not the button.

The bubble flipping when the band above is under the row is intended. A user would have to scroll while holding the button down.

Fix: the matrix runs on the fixture without its 30 filler paragraphs. That page scrolls by the row's height at most, which never brings the text near the row. The spec's openDoc now loads fixtures with setMeta("addToHistory", false), as the app seeds. The matrix also asserts Undo starts disabled. The existing 200 ms settle after the fixture is kept (see follow-ups).

How verified

  • Matrix, --project=chromium --project=webkit --workers=6:
    • before: 6 failed out of 40 (also 1 or 2 out of 40 in later runs);
    • after: 120/120, three times (including on the final code).
  • Whole selection-bubble.spec.ts, both projects, --workers=6 --repeat-each=2/3: green apart from pre-existing flakes. They appear at the same rate with main's spec, measured as 2 of 160 on each side (see follow-ups).
  • Specs that undo or redo (action-preview, mobile-bar, mobile-bar-followups, paint-format, palette, slash-menu, text-style-marks, toolbar, toolbar-row, toolbar-density, tabs), chromium: 215 passed, 19 skipped.
  • bun run check, bun run lint, bun run typecheck, bun run test (1241 pass).
  • Budget gate: bun run build && bun scripts/check-editor-chunk-size.ts passes.
  • Deploy path: with unpatched 3.3.0 already in node_modules, bun install --frozen-lockfile with this lockfile applies the patch.

Bytes

Patched vs unpatched production builds, same env:

  • Eager editor chunk group: +18 B gz (397,407 to 397,425).
  • Palette, first Alt+/: 0 B (20,475 of 20,480 both ways).

Deploy

Run bun install before bun run build. The new patchedDependencies entry patches @tiptap/y-tiptap at install time.

Follow-ups

  • Upstream the y-tiptap fix. The patch is pinned to 3.3.0 while package.json allows ^3.3.0, so a bump will fail the install until the patch is redone or dropped.
  • EditorPage.setContent is still an undo step. Other specs that undo shortly after it have the same 500 ms merge hazard.
  • In Chromium, a mouse drag right after the content lands opens no bubble. It reproduces 5/5 without the 200 ms settle in openDoc; not investigated here.
  • The bubble re-places itself on scroll while a pointer is held on it, so a click can be lost if the page scrolls mid-press.
  • Pre-existing flakes under load, also seen with main's spec:
    • Alt+F10 / focus tests: "keyboard colour pick", "focus leaving the bubble", "Tab past the last item". These tests press keys before the focus move they cause has landed.
    • "shows for a selection made before its chunk arrived" never unroutes its chunk interceptor. Its in-flight route.fetch() error is then reported against the next test, "the bubble ends with the Paint format brush".

The phone status pill spans the docked bar's width 8px above it, in
the band where the presence and Discord/GitHub/Privacy chips float, so
a refused "/" pick, a removed format's Undo or an unavailable cell's
reason covered them. Hide the chips while the bar holds a pill, as
they already hide for the selection bar; they come back when it closes.
The colour hover preview drew one decoration over each selection range,
so Red text or Yellow highlight showed over inline code and code blocks
although applying never colours them: inlineCode excludes every mark
and a code block allows none.

setActionPreview now takes { attrs, mark } and decorates only the inline
nodes addMark would mark (the parent allows the mark and no mark on the
node excludes it), merging adjacent runs. A collaborator's redraw keeps
the same rule.

A highlight preview's run that starts after the selection nests the
blurred selection's span inside its mark, so the colour panel's
stylesheet keeps that tint off.
…loads

A brush press before the lazy formatting engine landed went through
runWithEngine, which runs a queued action only if the selection has not
moved. For Paint format the next selection is the intended next step, so
the press was dropped and the brush never showed pressed.

The brushes now keep the press in paint-pending.ts: pressed at once, with
the copy cursor and the pill, the pressed text kept as a session range
that follows edits. Once the engine lands it arms on that range and paints
a mouse selection made meanwhile (on touch, the second tap). Other queued
actions keep the unmoved-selection rule.
A pointer-up that started in the text set the pending press's apply
flag even for a plain click, and landing then painted whatever was
selected, a keyboard selection too. Read the selection a frame after
the pointer-up, as the armed listener does, keep it only when it is
other text, and on landing paint only if it is still that selection;
otherwise just arm. The touch second press keeps its selection the
same way.
# Conflicts:
#	CHANGELOG.md
#	tests/TESTING.md
# Conflicts:
#	CHANGELOG.md
#	tests/TESTING.md
UniqueID and the outline append a heading-id transaction to a change
made with addToHistory: false. y-tiptap 3.3.0 took the history flag
from the last doc-changing transaction of a dispatch, so the Playground
seed became an undo step: Undo was enabled on a fresh Playground and
wiped it, together with any edit made within the Yjs capture window.

Patch y-tiptap so an appended transaction keeps its root transaction's
addToHistory: false. User edits stay undoable as before.
The matrix failed about one run in seven under load, two ways:

- Its fixture was an undo step, so the first Bold could join it within
  the Yjs capture window and the undo after it wiped the page. The
  spec's fixtures now load with addToHistory: false, as the app seeds a
  document, and the matrix checks that Undo starts disabled.
- A bubble still sliding in made Playwright retry the click and scroll
  its target, which brought the text under the sticky row; the bubble
  flipped below the text between mousedown and mouseup and the click
  landed on the page (a missing mark, or no Link popover). The matrix
  now runs on a page too short to bring the text under the row.
# Conflicts:
#	CHANGELOG.md
#	tests/TESTING.md
A "/" typed while an earlier fetch of the menu chunk was still failing
(the chunk runtime fetches a failed chunk once more, a moment later)
joined that fetch. When it failed, nothing loaded the chunk again while
the menu stayed open, so the menu never showed even once the chunk could
load. A failed load is now fetched once more straight away.
@HMarzban
HMarzban merged commit d9ea78d into main Nov 15, 2026
2 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