Repository navigation
Description
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):
- Peer B types
see example.com(with the space). Autolink linksexample.comon B. - B selects the paragraph and runs Remove link (
unsetHyperlink). B shows<p>see example.com </p>. - Peer A receives the remote change. A's autolink runs on it and links the word again, in A's local state only.
- A types
Zat the start of the paragraph. - 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 oneReplaceStepover 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.tshas 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)
- In the autolink
appendTransaction, return early when every transaction is a remote y-sync change that is not a y-undo. - Keep the strip pass and the add pass unchanged for local transactions.
- 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.comlinks 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
- A test reproduces both triggers before the fix and fails; it passes after (sabotage proof in the PR).
-
bun run test:unitand the full package Cypress suite pass. - Bench before and after posted in this issue.
- Re-run the collab checks after Take y-tiptap 3.3.0 with Tiptap 3.33.1 and drop the local y-tiptap patch #701 lands.
Out of scope
- The partial-format strip: Hyperlink: keep the whole link when part of it is formatted #770.
- An upstream Tiptap issue (optional; not drafted here).
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
HMarzban commentedon Nov 12, 2026
Ruling 9 evidence: jsdom suite and live pad check (2026-11-12)
Two setups:
Y.Docs. Results are pass/fail. Three full runs gave identical output.:3001atc9cd2c98a, anext devbuild. 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, noty-sync$. The y-undo key isy-undo$1, and the autolink key ishyperlinkAutolink$2. All 393 logged remote transactions carriedy-sync$1withisChangeOrigin: trueandisUndoRedoOperation: 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. SogetMeta('y-sync$')never matches live. Match the plugin with/^y-sync\$\d*$/. The$2on autolink shows that suffixes depend on load order.How to tell y-undo from a peer change. y-tiptap's
_typeChangedhandles both. It setsisChangeOrigin: trueandisUndoRedoOperation: transaction.origin instanceof Y.UndoManager. So the remote test isisChangeOrigin && !isUndoRedoOperation.All three triggers happen live (3 of 3 each; controls 0 of 10 valid runs). Only
hyperlinkAutolink$2added the mark, and always on a remotey-sync$1transaction. A hook wrapped all 27appendTransactionplugins before the view existed. The schema also has an upstreamlinkmark andhandleClickLink$, but noautolink$key.Z, both pages showZsee [example.com](https://example.com). A's write lands when the harness focuses A and sets its caret, about 15 ms beforeZ. A caret move by A alone, or by B alone, also stored the link (3 of 3 each).example.comat the end of the H1 title (block index 0). A's and B's Y.Docs receive it. The next block'svisit example.orgstayed 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.focusplussetTextSelection), 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).
y-sync$y-sync$1c9cd2c98aisChangeOriginonlyy-sync$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_textURLs. Markdown writes already linkhttps://andwww.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.
/^y-sync\$\d*$/.appendedTransactionroot is remote.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) andwf3/v-e9-collab-relink/. Live data:wf4/p4-live-collaband the verifier'swf4/verify-p4. Re-run:wf3/e9-collab-relink/harness/matrix.sh, andcd wf4/p4-live-collab && bun collab.ts --runs 3 --only t1x.HMarzban commentedon Nov 13, 2026
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:
/^y-sync\$\d*$/; the live key isy-sync$1. Never readgetMeta('y-sync$').isChangeOrigin: trueandisUndoRedoOperation: false, or when itsappendedTransactionroot is such a transaction.Accepted cost: clients no longer autolink bare domains or URLs that a peer or the server wrote. Server-side Markdown writes already link
https://andwww.URLs.HMarzban commentedon Nov 13, 2026
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./^y-sync\$\d*$/, because the app's live key isy-sync$1. The lookup is cached per plugin set.isChangeOrigin && !isUndoRedoOperation, or when itsappendedTransactionroot is remote.jsdom suite.
src/interactions/__tests__/autolinkCollab.test.tshas 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:
isChangeOriginonlyy-sync$Live check.
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 intoremoteSync.ts; the re-check after it is further down.U3 is settled by accepting the split. The test asserts both peers.
Cost.
dist/index.js.Re-checked on the final code (2026-11-13, after the refactor into
remoteSync.ts).remoteSync.tsgives the same failures as before: no skip 6,isChangeOriginonly 1, no root check 1, string key 6 (of 13).Still owed.
feat(extension-hyperlink): add HyperlinkBase and ruled autolink fixes
perf(webapp): load HyperlinkBase in the pad and composer
HMarzban commentedon Nov 16, 2026
Measured, 2026-11-16: #771 bench case and receiver time.
045a6a62f, with the bench change below.scripts/bench/behaviour.tshas a newcollabcase. Two editors run on two synced Y.Docs. B typessee example.comand removes the link. A moves its caret, typesZand moves its caret again. The case checks both peers.scripts/bench/workloads.tshasremoteType25andremoteType2000. A peer types 1,000 keys at the end of 25 or 2,000 blocks. Only the receiver'sY.applyUpdateis timed for each key, at 1 Y update per key.Behaviour
c9cd2c98a(before #771)isRemoteSyncskip removedc9cd2c98a, A links the word again after B's unlink. A'sZthen stores the link on both peers. The other two base failures belong to Hyperlink: decide what Enter inside a link does #778 (Enter) and Hyperlink: autolink misses a URL in the middle of a one-chunk insert #780 (chunk).Receiver time per remote keystroke (jsdom, 9 rounds, median)
c9cd2c98a→ HEAD, 1c9cd2c98a→ HEAD, 2c9cd2c98a→ HEAD, 1c9cd2c98a→ HEAD, 2c9cd2c98a→ HEAD rows also hold Hyperlink: keep PURE comments so helper-only imports tree-shake #774, Hyperlink: add HyperlinkBase without the prebuilt popovers #775, Hyperlink: decide what Enter inside a link does #778, Hyperlink: autolink misses a URL in the middle of a one-chunk insert #780 and843305131.c9cd2c98a→ HEAD runs: a few were above their control in one run only (boldAll25 +7 % against +1 % in run 2, typeEnd25 +2 % against +0 % in run 1). None was above its control in both runs.Gates
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/demoin 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.HMarzban commentedon Nov 16, 2026
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.chore(extension-hyperlink): add a collab case to the bench