Skip to content

Hyperlink: keep a removed link removed when a peer edits the pad #771

Closed

Description

@HMarzban

Part of #769. Depends on #770 (same file). Needs the ruling below before code.

Summary

A user's unlink does not stick while another person is on the pad. The other peer's autolink links the word again in its own state. That peer's next edit then syncs the link back to everyone. Upstream @tiptap/extension-link 3.32.2 does the same, so this is Tiptap-wide behaviour that we can fix in our extension.

Reproduce

Two editors on one Y.Doc pair, synced both ways (or two browser tabs on one local pad):

  1. Peer B types see example.com (with the space). Autolink links example.com on B.
  2. B selects the paragraph and runs Remove link (unsetHyperlink). B shows <p>see example.com </p>.
  3. Peer A receives the remote change. A's autolink runs on it and links the word again, in A's local state only.
  4. A types Z at the start of the paragraph.
  5. Both peers now show <p>Zsee <a href="https://example.com">example.com</a> </p>. The unlink is lost.

Second trigger: A bolds across paragraph 1 and paragraph 2, where paragraph 1 ends with an unlinked example.com and no trailing space. A stays unlinked, but B links the word (the nodesInChangedRanges.length > 1 branch, autolink.ts:85).

Cost of the extra work on the receiver: no visible change per remote keystroke (2.8 / 3.2 / 2.9 ms medians, n = 5, jsdom).

Cause (read from code)

  • y-tiptap (replaceChangedChildren) sends a remote edit as one ReplaceStep over the whole changed top-level block.
  • Autolink treats that whole block as the changed range. So its trailing-whitespace test reads the whole paragraph, not what was typed.
  • extensions/extension-hyperlink/src/interactions/autolink.ts has no check for remote transactions.
  • y-sync does not send the appended mark back at once. The mark leaves with that peer's next local edit.

Decision needed (maintainer)

Ruling 9 of the review. Pick one:

  • A (recommended). Skip autolink on remote y-sync transactions that are not y-undo. Each user's own typing still autolinks on their own client. Server-written URLs (MCP, REST inject content) are then never autolinked by clients; if they should be, link them on the server when they are written.
  • B. Keep autolink on remote transactions, but only for the text the remote step inserted (narrow the range). More code, and it still links server writes on every client at once.
  • C. Do nothing; document it as upstream behaviour.

Why A: it is the smallest change, and a remote client should not change content it did not type. Caveat: y-tiptap sets isChangeOrigin on y-undo transactions too (its dist, about line 1582). A plain getMeta('y-sync$')?.isChangeOrigin check would also skip autolink after a y-undo. The fix must tell the two apart, and a test must pin y-undo.

Fix (after the ruling, for option A)

  1. In the autolink appendTransaction, return early when every transaction is a remote y-sync change that is not a y-undo.
  2. Keep the strip pass and the add pass unchanged for local transactions.
  3. If server writes must be linked, file a separate server issue. Do not do it here.

A scratch probe that returns early on getMeta('y-sync$')?.isChangeOrigin stopped both triggers in the review. Do not ship that probe as is (the y-undo caveat above).

Benchmark

Field Value
Metric Behaviour: a new collab case in scripts/bench/behaviour.ts (two editors, two synced Y.Docs): the unlink stays after the other peer types. Speed: receiver time per remote keystroke.
Before Case fails today. Receiver per remote keystroke about 2.8-3.2 ms (jsdom, n = 5).
After not measured yet
Confounds #701 (y-tiptap 3.3.0) changes the remote step shape. Measure before and after on the same y-tiptap version, and re-run after #701.
Condition jsdom on Bun, in-memory Yjs, y-tiptap as resolved from apps/webapp. Plus two real browser tabs on a local pad.
How to run NODE_ENV=production bun scripts/bench/run.ts after the case is added. The bench needs yjs and @tiptap/extension-collaboration as dev dependencies of the package; add them with this issue.
Pass rule The collab case passes; every other behaviour case still passes; no speed row moves outside the control band.
Guard The UX contract below.
Owner Maintainer: the ruling. Agent in the repo: code, tests, bench. Maintainer: the two-browser production check.
Claim "Removing a link sticks while others edit the pad."

UX contract

  • The local user's own typing still autolinks with a peer online. Typing example.com links it at once.
  • Two peers type next to the same link at once. Neither peer gains or loses a link the other did not make.
  • y-undo of an autolinked word behaves as today (add a test).
  • Server-written URLs follow the ruling (test one MCP write locally).
  • Two real browsers on one pad: unlink in one, type in the other. The link stays removed on both.

Acceptance checks

Out of scope

Related: #632 (same file; a removed SKILL.md link also comes back), #146 (URL decision pipeline), #696 (Remove with a co-editor), #701, #520.

Activity

  1. added this to the v2.3.8 milestone on Nov 12, 2026
  2. self-assigned this
    on Nov 12, 2026
  3. added
    bug
    Editor
    on Nov 12, 2026
  4. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    Ruling 9 evidence: jsdom suite and live pad check (2026-11-12)

    Two setups:

    • jsdom (wf3). jsdom 26.1.0, Tiptap 3.32.2, y-tiptap 3.0.10, yjs 13.6.33. Two or three editors share in-memory Y.Docs. Results are pass/fail. Three full runs gave identical output.
    • Live (wf4). Local webapp :3001 at c9cd2c98a, a next dev build. Headless Chrome 158 (build 1254), with one anonymous context per page. y-tiptap 3.0.10, yjs 13.6.33, @hocuspocus/provider 3.4.4. n = 3 per trigger, and every trigger has a control.

    Plugin keys on the live pad. The y-sync key is y-sync$1, not y-sync$. The y-undo key is y-undo$1, and the autolink key is hyperlinkAutolink$2. All 393 logged remote transactions carried y-sync$1 with isChangeOrigin: true and isUndoRedoOperation: false. That includes the join's first render. Local doc changes (483) carried no y-sync meta. A verifier re-run gave the same split. So getMeta('y-sync$') never matches live. Match the plugin with /^y-sync\$\d*$/. The $2 on autolink shows that suffixes depend on load order.

    How to tell y-undo from a peer change. y-tiptap's _typeChanged handles both. It sets isChangeOrigin: true and isUndoRedoOperation: transaction.origin instanceof Y.UndoManager. So the remote test is isChangeOrigin && !isUndoRedoOperation.

    All three triggers happen live (3 of 3 each; controls 0 of 10 valid runs). Only hyperlinkAutolink$2 added the mark, and always on a remote y-sync$1 transaction. A hook wrapped all 27 appendTransaction plugins before the view existed. The schema also has an upstream link mark and handleClickLink$, but no autolink$ key.

    • Trigger 1: unlink, then a peer types. With A and B idle, the unlink held for 5 s. After A types Z, both pages show Zsee [example.com](https://example.com) . A's write lands when the harness focuses A and sets its caret, about 15 ms before Z. A caret move by A alone, or by B alone, also stored the link (3 of 3 each).
    • Trigger 2: Bold across two paragraphs by A. B adds the mark on the remote transaction. Both pages hold the link within milliseconds, with no action by B. So "A stays unlinked" does not hold live.
    • Join trigger. Page C opens the pad while A and B stay open. With no user action, C links example.com at the end of the H1 title (block index 0). A's and B's Y.Docs receive it. The next block's visit example.org stayed unlinked. Only this one layout was tested.

    Correction to the jsdom wording. "Its next edit stores it" is too narrow. Live, any later transaction on the relinking page stores the mark. That includes a caret move or a remote cursor (yjs-cursor$1) transaction. The caret moves were programmatic (commands.focus plus setTextSelection), not mouse clicks. The timings are unverified: 4–7 ms for trigger 2 (re-run 6.6–6.9 ms), and 472–511 ms after load for C.

    jsdom suite (16 tests).

    Build key y-sync$ key y-sync$1
    HEAD c9cd2c98a 10 pass / 6 fail 10 / 6
    Option A 16 / 0 16 / 0
    Option B prototype (narrowed range) 11 / 5 11 / 5
    A without the skip 10 / 6 10 / 6
    A, isChangeOrigin only 15 / 1 (y-undo U3) 15 / 1
    A, no appended-root check 15 / 1 15 / 1
    A, string key y-sync$ 16 / 0 10 / 6

    One difference under A. In y-undo case U3, peer A shows the link and peer B does not. On HEAD both show it. The Y.Doc holds no link in either build. In jsdom the peers agree again after A's next edit. The U3 test checks only peer A, so the ported test must check both. U3 has not run live.

    Server writes (MCP, REST), jsdom only. Today, online clients add a link the server did not write in 3 of 5 cases. In jsdom, the stored pad got it when one of them typed. Live, any later transaction may store it. Server writes were not run live. Under A, every client shows what the server wrote. A gives up client autolink of bare domains and of replace_text URLs. Markdown writes already link https:// and www. URLs on the server.

    Option B fixed trigger 1 only in jsdom. It does not cover the join. Option C keeps the join trigger, which stores a link with no edit at all.

    Recommendation: A.

    • Match the plugin by name with /^y-sync\$\d*$/.
    • Also skip a transaction whose appendedTransaction root is remote.
    • Assert both peers in U3.

    The scratch diff is 26 lines added and 1 removed, in interactions/autolink.ts. Every live relink ran on a transaction that this gate skips, so A should cover all three triggers. That is inferred: no gated build ran live, and y-undo did not run live.

    Pass rule for the after check.

    Raw data: wf3/e9-collab-relink/out/ (matrix.txt, server-HEAD.json, server-Aclean.json, optionA-clean.diff) and wf3/v-e9-collab-relink/. Live data: wf4/p4-live-collab and the verifier's wf4/verify-p4. Re-run: wf3/e9-collab-relink/harness/matrix.sh, and cd wf4/p4-live-collab && bun collab.ts --runs 3 --only t1x.

  5. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

    Ruled: option A (maintainer, 2026-11-13)

    Autolink skips remote y-sync transactions that are not y-undo. The conditions from the evidence comment apply:

    1. Match the y-sync plugin by /^y-sync\$\d*$/; the live key is y-sync$1. Never read getMeta('y-sync$').
    2. A transaction is remote when its y-sync meta has isChangeOrigin: true and isUndoRedoOperation: false, or when its appendedTransaction root is such a transaction.
    3. Settle the U3 split (peer B after a y-undo): the test asserts both peers.
    4. Before closing: a live two-browser check of the gated build, and a live y-undo case.

    Accepted cost: clients no longer autolink bare domains or URLs that a peer or the server wrote. Server-side Markdown writes already link https:// and www. URLs.

  6. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

    Built: option A (2026-11-13). Not committed yet.

    Autolink now skips a batch when every doc-changing transaction in it is a remote y-sync change. The detection lives in src/interactions/remoteSync.ts.

    • The y-sync plugin is matched by /^y-sync\$\d*$/, because the app's live key is y-sync$1. The lookup is cached per plugin set.
    • A transaction counts as remote when it has isChangeOrigin && !isUndoRedoOperation, or when its appendedTransaction root is remote.
    • Local typing, paste and y-undo still autolink.

    jsdom suite. src/interactions/__tests__/autolinkCollab.test.ts has 13 tests. It runs two or three editors on synced Y.Docs.

    • HEAD c9cd2c98a: 7 pass, 6 fail. With the fix: 13 pass.

    • Each sabotage makes tests fail:

      Sabotage Tests that fail
      No skip 6
      isChangeOrigin only 1, the U3 undo test
      No root check 1
      String key y-sync$ 6

    Live check.

    • Condition: local webapp (next dev), headless Chrome for Testing 158, Playwright 1.64.1, n = 3 per case. The table below ran before a refactor that moved the same logic into remoteSync.ts; the re-check after it is further down.
    • "Relinked" means that a link nobody typed is in the Y.Doc at the end.
    Case Before After
    B unlinks, A moves its caret and types; a third page stays open 3 of 3 relinked 0 of 3
    A bolds across two paragraphs 3 of 3 0 of 3
    C opens a pad whose title ends in a URL 3 of 3 0 of 3
    • Autolink adds fed by remote transactions went from 21 to 0. Adds fed by local typing stayed at 3, and adds fed by y-undo stayed at 3.

    U3 is settled by accepting the split. The test asserts both peers.

    • Right after a y-undo, A shows the link and B does not.
    • After A's next transaction, both show it, and the Y.Doc holds it. Live, B got the link 15–25 ms after the undo, with no user action (n = 3).
    • A real fix needs a y-tiptap change.

    Cost.

    • Before the refactor: +289 B minified and +121 B gzip on dist/index.js.
    • Behaviour: 18/18 before and after.
    • Speed: jsdom, 9 rounds, two runs, within the control's noise.
    • The ruling accepts that text a peer or the server writes is not autolinked on other clients.

    Re-checked on the final code (2026-11-13, after the refactor into remoteSync.ts).

    • Sabotage on remoteSync.ts gives the same failures as before: no skip 6, isChangeOrigin only 1, no root check 1, string key 6 (of 13).
    • Live, local webapp, headless Chrome 158, n = 3 per case: trigger 1, trigger 2 and the join trigger all end with 0 links in every peer's Y.Doc (0 of 3 relinked each). Local typing still autolinks and syncs to every peer. After a y-undo, all three peers hold the link again.

    Still owed.

  7. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-16: #771 bench case and receiver time.

    • Question: does the bench now pin the unlink bug? What does each remote keystroke cost the receiver, before and after?
    • Setup: one Apple M5 Max laptop, Bun 1.4.4, jsdom 26.1.0, Tiptap 3.32.2, y-tiptap 3.0.10, yjs 13.6.33. The laptop was loaded: load average 3.34 to 10.47 during the timed runs. Head is the working tree on 045a6a62f, with the bench change below.
    • Bench change (not committed):
      • scripts/bench/behaviour.ts has a new collab case. Two editors run on two synced Y.Docs. B types see example.com and removes the link. A moves its caret, types Z and moves its caret again. The case checks both peers.
      • scripts/bench/workloads.ts has remoteType25 and remoteType2000. A peer types 1,000 keys at the end of 25 or 2,000 blocks. Only the receiver's Y.applyUpdate is timed for each key, at 1 Y update per key.

    Behaviour

    Ref All cases collab
    c9cd2c98a (before #771) 18 / 21 0 / 1
    HEAD with only the isRemoteSync skip removed 20 / 21 0 / 1
    HEAD 21 / 21 1 / 1

    Receiver time per remote keystroke (jsdom, 9 rounds, median)

    Run Workload Before After Change Control change
    c9cd2c98a → HEAD, 1 remoteType25 68.155 µs 51.223 µs −24.84 % +8.91 %
    c9cd2c98a → HEAD, 2 remoteType25 64.489 µs 48.244 µs −25.19 % +1.07 %
    #771 alone remoteType25 76.362 µs 56.19 µs −26.42 % −3.01 %
    c9cd2c98a → HEAD, 1 remoteType2000 1904.48 µs 1718.759 µs −9.75 % −9.64 % (noise)
    c9cd2c98a → HEAD, 2 remoteType2000 1250.544 µs 1021.6 µs −18.31 % −7.44 %
    #771 alone remoteType2000 2131.78 µs 1860.204 µs −12.74 % +1.77 %

    Gates

    • Unit 530 / 530, typecheck and ESLint pass, clean-room Cypress 289 / 289 (22 specs). The CI byte budget passes, at 26,040 B against a limit of 26,040 B.

    Still owed (maintainer)


    Production check, 2026-11-16. docs.plus at b7888dce1 (deployed 2026-11-15). Chrome on macOS, signed in. One scratch pad, never /demo. Each result was read from the editor DOM after the action. n = 1.

    Two tabs on one pad. Unlink docs.plus/demo in tab A. In tab B, type at the end of that line, move the caret across the unlinked text, and type a character inside it. Result: no link on that text in either tab, and the GitHub link on the same line stays.

  8. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Bench case committed as e0132e886 (chore(extension-hyperlink): add a collab case to the bench). Production two-tab check passed (comment above). The post-#701 re-run moved to #701 by ruling. Release credit v2.3.8. Closing as done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

EditorExtensionbugtiptap

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions