Skip to content

Hyperlink: autolink misses a URL in the middle of a one-chunk insert #780

Closed

Description

@HMarzban

Part of #769. Depends on #771: its remote skip must also gate the new path. Priority: low.

Summary

Autolink checks only the last word before the whitespace that ends an insert. Typed key by key, each word ends in its own transaction, so every URL gets checked. One transaction that inserts a whole phrase is different: a URL in its middle is never linked. Dictation, an IME phrase commit and macOS text replacement can insert one chunk. That last part is read from code only. Upstream @tiptap/extension-link 3.32.2 has the same rule. So this is old behaviour, not a regression.

Reproduce

On the local stack, on a new scratch pad. Never use /demo.

  1. Put the caret at the end of an empty paragraph.
  2. Insert see example.com now as one chunk. In Playwright: page.keyboard.insertText('see example.com now ').
  3. example.com stays plain text.
  4. Type the same text key by key on a new line. example.com becomes a link.

With the URL last (go to example.com ), both paths link.

Measured (before)

Case Linked Condition n
Pad, one-chunk insertText of see example.com now 0 of 10 local webapp :3001, next dev, c9cd2c98a, headless Chrome for Testing 158, one fresh pad per run 5, then 5 by a verifier
Pad, CDP IME phrase commit, same text 0 of 10 same 5 + 5
Pad, key by key (control) 10 of 10 same 5 + 5
Pad, URL last, each chunk path (control) 5 of 5 same 5
Pad, key-type more after the miss 0 of 20 same, plus a 1.8 s wait 20
Scratch Tiptap page, one-chunk insertText 0 of 5 Chromium, 0 of 5 WebKit 27.2 package scratch page 5 each
Scratch Tiptap page, review prototype 5 of 5 in each engine same 5 each

Not tested: Enter, blur, edits inside the URL, and reload after the miss.

Raw files (local, gitignored): Notes/local-docs/2026-11-12-hyperlink-bundle/wf4/evidence/p5-chunked-pad/out-2026-11-12T20-49-50-291Z/raw.json, wf4/evidence/v-p5-chunked-pad/out-2026-11-12T20-53-10-560Z/raw.json, wf3/evidence/v-e13/browser-chromium.json and browser-webkit.json. Re-run on a pad: cd wf4/evidence/p5-chunked-pad && bun chunked-pad.ts --n 5.

Cause (read from code)

  • extensions/extension-hyperlink/src/interactions/autolink.ts:86-108 (working tree with Hyperlink: keep a removed link removed when a peer edits the pad #771): the one-block path runs only when the inserted range ends in whitespace. Then it checks only lastWordBeforeSpace.
  • Upstream @tiptap/extension-link 3.32.2 src/helpers/autolink.ts:139-155 has the same rule.
  • prosemirror-view builds one transaction from one DOM change. So a phrase that arrives in one input event is one insert. This covers dictation, an IME commit and text replacement. Read from code only.

Fix (proposal)

Try a smaller fix first. The bar is the prototype below.

The review prototype (wf3/evidence/e13-chunked-input/proto-final.diff) scans every finished word that touches a local one-block insert. Everything else keeps the last-word rule. The new path has five guards:

  • Skip paste and drop (uiEvent). The paste rule already links those.
  • Only ReplaceSteps. A mark step is not an insert. A draft without this guard and the scroll guard made Bold 32 % slower.
  • Only transactions with scrolledIntoView. prosemirror-view sets it for typed and dictated input. setContent and insertContent do not set it.
  • Not history (isHistoryTransaction), and not remote.
  • Stop after the last whitespace, because the next word may still be typed.

Why it depends on #771. The prototype tests getMeta('y-sync$'). The app's key is y-sync$1, so that guard never fires in the app. The #771 early return skips only a batch where every transaction is remote. So the new path needs a per-transaction check. Export one from src/interactions/remoteSync.ts and reuse it. Do not test the key string again.

Prototype costs (before #771, scratch page and jsdom):

Row HEAD Prototype Change Condition
StarterKit app (min / gzip B) 70,776 / 25,582 71,331 / 25,816 +555 / +234 bench run.ts, exact
npm dist/index.js (min / gzip B) 57,013 / 20,861 57,681 / 21,145 +668 / +284 same
200 dictated sentences, no URL (µs per insert) 28.821 18.649 −35.3 % (re-run −34.7 %) jsdom, 21 rounds, twice; A/A −1.1 %
200 sentences with a mid URL (µs per insert) 27.529 101.453 +268.5 % (re-run +259 %): the cost of 200 new links same; A/A +2.4 %
One 2,000-word insert, no URL / 200 URLs (ms) 0.167 / 0.149 1.288 / 5.381 +1.121 / +5.232 same
Key-by-key typing at the end of 2,000 words (µs per key) 30.651 28.326 inside noise same; A/A +29.2 %

Sabotage on the prototype: the history and scroll guards each fail a test alone. The step and y-sync guards fail a test only with the scroll guard also off.

Benchmark

Field Value
Metric Link rate for a mid URL in one-chunk input on a pad (runs linked / n): insertText, IME phrase, key by key (control), URL last (control). Bytes a StarterKit app pays. Package bench speed rows and behaviour count.
Before Pad, c9cd2c98a: insertText 0 of 10, IME phrase 0 of 10, key by key 10 of 10, URL last 5 of 5 per path. Bytes: 70,776 / 25,582 B at c9cd2c98a. Take new bytes and speed on top of #771, #774, #775 and #778 before the first commit.
After not measured yet
Confounds #771, #774, #775 and #778 (built, not committed). #701 (the y-tiptap meta and key). Record each commit hash.
Condition Pad: local webapp, one fresh anonymous scratch pad per run, headless Chrome for Testing 158. Engines: Chromium and WebKit 27.2 on the scratch page. Bytes: bench run.ts. Speed: jsdom, Bun 1.4.4, 9 rounds, with the control copy.
How to run Pad: bun chunked-pad.ts --n 5 (local harness in wf4/evidence/p5-chunked-pad/). Package: NODE_ENV=production bun scripts/bench/run.ts --ref <commit before this issue> from extensions/extension-hyperlink.
Pass rule insertText and IME phrase link the mid URL 10 of 10 on a pad. Controls stay 10 of 10 and 5 of 5. At most +250 B gzip for a StarterKit app (prototype +234). boldAll2000 and typeEnd2000 inside the control band. Behaviour count rises by the new chunked case and loses none.
Guard The UX contract below.
Owner Agent in the repo: code, tests, bench and pad runs. Maintainer: one real macOS dictation and one text replacement, on a local scratch pad.
Claim "A dictated or IME phrase now links a URL in its middle, as typed words do (local pad, Chrome and WebKit)." Internal until the dictation check passes.

UX contract

  • Key-by-key typing links exactly as before.
  • Paste and drop link exactly as before.
  • A word with no whitespace after it is not linked yet.
  • Undo after a one-chunk insert behaves as for a URL typed key by key.
  • A peer's insert is not linked on other clients (Hyperlink: keep a removed link removed when a peer edits the pad #771).
  • y-undo and history redo add no links through the new path.
  • Bold over a sentence with a URL adds no link and no extra step.
  • A custom href is never rewritten. Code marks and image Markdown are skipped for every candidate word.
  • Each guard fails a test alone when removed, or the issue says why not.
  • Maintainer: a real macOS dictation of a phrase with a URL in its middle links the URL.
  • Maintainer: a macOS text replacement that expands to such a phrase links the URL.

Acceptance checks

Out of scope

Activity

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

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-13: #780 before and after (one-chunk autolink).

    Since this run, the measured #780 diff is commit ead539a38 (its src/ diff has the same sha256, be57daf0…), and the bench code is 2a69e2e92. Neither is pushed yet.

    • Question: does the Hyperlink: autolink misses a URL in the middle of a one-chunk insert #780 change link a URL in the middle of a one-chunk insert on a real pad? What does it cost in bytes and speed?
    • Setup:
    • Method:
      • Package bench: NODE_ENV=production bun scripts/bench/run.ts --ref 13cd8ab27 --runs 9, in jsdom. It ran twice: once before the pad runs, once after the stack stopped.
      • Package tests: bun run test:unit, then the full clean-room Cypress suite against the rebuilt dist/.
      • Pad: the p5 chunked-pad harness, with --n 5, two passes. Each round opens one fresh anonymous scratch pad. Each round writes every case into its own empty paragraph, once with no prefix and once after Intro words. . So one pass gives 10 rows per mid-URL method and 5 rows per URL-last path.

    Bytes (exact, equal in both runs)

    Row Before (min / gzip B) After (min / gzip B) Change
    A StarterKit app pays 71,504 / 25,819 71,861 / 25,981 +357 / +162
    npm dist/index.js 81,742 / 25,676 82,385 / 25,891 +643 / +215
    StarterKit app with HyperlinkBase 64,631 / 23,751 64,988 / 23,927 +357 / +176
    normalizeHref-only import 19,997 / 9,860 19,997 / 9,861 0 / +1

    Behaviour (jsdom, both runs)

    Set Before After
    All cases 19 / 19 19 / 19

    The bench has no chunked case yet. scripts/bench/behaviour.ts is unchanged, so the count did not rise.

    Speed (jsdom, 9 rounds per run, median (min–max))

    Workload Run Before After Change Control change
    boldAll2000 (ms) 1 237.961 (224.343–264.306) 246.069 (231.819–285.792) +3 % +6 %
    boldAll2000 (ms) 2 225.413 (205.808–300.646) 221.600 (213.926–237.313) −2 % −2 %
    typeEnd2000 (µs/key) 1 139.760 (135.437–154.882) 146.805 (138.207–152.143) +5 % −1 %
    typeEnd2000 (µs/key) 2 132.153 (128.363–227.886) 136.841 (130.678–260.367) +4 % +2 %
    pasteOverSelection250k (ms) 1 11.776 (11.021–12.868) 12.658 (12.202–13.365) +7 % −1 %
    pasteOverSelection250k (ms) 2 12.740 (12.083–15.596) 13.984 (12.710–19.376) +10 % +1 %

    Other rows outside their control change:

    • mount50Links in both runs: +3 % against −0 %, then +12 % against +7 %.
    • typeEnd25 in run 2: +2 % against −1 %.
    • pasteText2000 in run 1, faster: −7 % against −4 %.

    #780 does not change the mount path, so one control per run understates the noise on this loaded laptop. Every workload ended with the same document as before.

    Speed in a real browser, #780 only

    Chrome for Testing 158.0.8127.18, headless, one laptop. 6 sessions × 15 rounds of NODE_ENV=production bun scripts/bench/drive.ts --ref 13cd8ab27 --runs 15. Base is 13cd8ab27 (before #780); head adds only the #780 diff. Pooled with summarize.ts; the session is the unit.

    Workload head/base, median (range) control/base range MDE Clear of control?
    typeEnd2000 (µs/key) +0.1 % (−1.5 % to +1.2 %) −2.1 % to +1.4 % ±2.1 % no
    typeEnd25 (µs/key) +1.5 % (−0.1 % to +1.6 %) −0.9 % to +0.8 % ±0.9 % no: 5 of 6 sessions above
    boldAll2000 (ms) −0.7 % (−3.5 % to +4.1 %) −1.6 % to +3.8 % ±3.0 % no
    pasteText2000 (ms) −0.2 % (−0.7 % to +2.0 %) −1.2 % to +0.1 % ±0.7 % no
    pasteOverSelection250k (ms) +4.5 % (+2.0 % to +7.0 %) −1.5 % to +0.9 % ±1.5 % yes, slower: 22.04 → 22.77 ms
    Other 5 workloads inside their control ranges no

    The jsdom typeEnd2000 result (+5 %, +4 %) does not hold in the browser. pasteOverSelection250k does: about 0.7 ms more on a 250k-character paste over a selection.

    Tests

    Gate Result
    bun run test:unit 530 pass, 0 fail, 28 files
    Clean-room Cypress, all specs 289 of 289 pass, 22 specs

    Pad (linked rows / rows)

    Case Prefix Pass 1 Pass 2 Total Before (c9cd2c98a)
    One-chunk insertText of see example.com now none 5 / 5 5 / 5 10 / 10 0 / 10
    Same Intro words. 5 / 5 5 / 5 10 / 10 0 / 10
    CDP IME phrase commit, same text none 5 / 5 5 / 5 10 / 10 0 / 10
    Same Intro words. 5 / 5 5 / 5 10 / 10 0 / 10
    Key by key (control) none 5 / 5 5 / 5 10 / 10 10 / 10
    Same Intro words. 5 / 5 5 / 5 10 / 10 10 / 10
    URL last go to example.com , insertText (control) none 5 / 5 5 / 5 10 / 10 5 / 5
    URL last, IME phrase (control) none 5 / 5 5 / 5 10 / 10 5 / 5
    • The "none" rows match the issue's "10 of 10" (5 + 5). The prefixed rows are 10 more.

    • Each linked row links exactly example.com to https://example.com. see, now and the later more stay plain.

    • Each one-chunk row was one doc transaction. The IME rows fired one compositionend.

    • The link was still there 1.5 s later, and after a key-typed more , in 80 of 80 rows.

    • Raw data: local, not attached. Pass 1 raw.json sha256 da51f1a2bad33c976b6f6d0859397bb36d6740e9b3fd63626341700d0a2fb4bd. Pass 2 raw.json sha256 6bc8d2ead4f862eb107c795e63e1b3a73744af8f5bd2cb26742804c309608f54. Bench run 1 JSON sha256 982e9fcdd4453b498e21d6db1f53abb705e499de186262e17ad4831432a700fe. Bench run 2 JSON sha256 352c071fa224a3f2783c3f68a421101f3e0670ade21c0ee481e559ed5c787e7e. Harness chunked-pad.ts sha256 7429f0dc4633ecf2394bec70610d47f293c023fda908542b1dcafcc591f3a96c. Cypress log sha256 39231074a435ad17c82b2ec237a11f7a8c250513d3844457bf877907286a5bc5. Browser Hyperlink: autolink misses a URL in the middle of a one-chunk insert #780-only sessions s1–s6: 63e2e9b2c442ac0ac6b314e9757c08d701994a6207c1e627546d72f6d480f8a9, 7aebfe4f6289349ec698f07f55fbf17ebdc6531d23994b0795be5a5fc340cf1a, 3898bb03e5fb522b32f69737b241b8bd56ee0aaddffe704740b1c13db5d11ca3, b472cf103d390d8e5da5b3d53f3961caac7f1daa89498bc08e1824c1764accc5, 66b23ca1c98f9200434dcf3e244c07e09112919e14d9f98f6550f08135789b71, eee54bb72119e641b254704e6568789ef7b94109142d0ed71d1ebcd5a8ff3d32; summary 7fd56aaa943cad97583e1d7d3d86caa09cd2228d6197141e89d29eb9be048fb4. Every file, the bench scripts included, is listed in a MANIFEST.sha256, itself sha256 fa29e56faf6047b325eef81ec92fa5bdb8e647a986dc0da7b1a5613c227f763d.

    • Not measured:

      • Maintainer checks, still owed: one real macOS dictation and one macOS text replacement. Each inserts a phrase with a URL in its middle, on a local scratch pad.
      • WebKit on a pad. Enter, blur, reload, and edits inside the URL.
      • The new typed-chunk path in jsdom speed. The bench typeEnd dispatches with no scrollIntoView, so it never takes that path. Real typing does. Read from code, the typeEnd2000 change comes from the isTypedChunk check, or from matchAll on each typed space.
      • The browser speed bench (browser.ts).
      • The cause of the pasteOverSelection250k and typeEnd2000 changes. A likely shared cause, read from code only: on the last-word path, head builds a match object per word in the block (matchAll). Base split the same text into strings. The bench types a space every few keys, so typeEnd2000 runs that path often.
    • Verdict: split.

      • Pad: pass. A mid URL now links in one-chunk insertText (10 of 10) and IME phrase commits (10 of 10). Controls held: key by key 10 of 10, URL last 5 of 5 per path in each pass.
      • Bytes: pass. +162 B gzip for a StarterKit app, under the +250 B limit.
      • boldAll2000: pass. Inside the control in both runs.
      • typeEnd2000: pass in the browser. +0.1 %, inside its ±2.1 % noise (CfT, 6 sessions). The jsdom +5 % and +4 % did not hold.
      • pasteOverSelection250k: slower by 4.5 % in the browser, every session above the control range. That is +0.7 ms on a 250k paste. It is outside the issue's pass rule, which names only boldAll2000 and typeEnd2000, so the maintainer rules on it.
      • Behaviour count: pass. The bench gained one chunked case: base 19 of 20, head 20 of 20. None was lost.
      • The claim stays internal until the maintainer's dictation check passes.
      • The 10 scratch pads were not deleted. Anonymous pads have no owner delete path in the app.
  5. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-13: the #780 paste cost is fixed.

    Workload head/base, median (range) control/base range MDE Clear of control?
    pasteOverSelection250k (ms) −6.0 % (−6.7 % to −4.9 %): 22.44 → 21.17 ms −2.2 % to +0.9 % ±1.4 % yes, faster
    typeEnd2000 (µs/key) −0.3 % (−2.5 % to +1.6 %) −3.8 % to +0.8 % ±2.5 % no
    pasteText2000 (ms) −0.1 % (−0.5 % to +0.3 %) −0.5 % to +1.0 % ±1.0 % no
    Other 7 workloads inside their control ranges no
  6. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-16: #780 guard sabotage pass.

    • Method: I removed each guard in isTypedChunk, and the guards next to it, one at a time. Then I ran bun test --isolate src (530 tests) and restored the exact original. src/interactions/autolink.ts still has sha256 e66157af…80f4d, and git diff on it is empty.
    • Setup: one Apple M5 Max laptop, Bun 1.4.4, HEAD 045a6a62f.
    Guard removed Tests that fail
    uiEvent !== 'paste' 1: a paste keeps the last-word rule
    uiEvent !== 'drop' 1: a drop keeps the last-word rule
    only ReplaceSteps 1: Bold over a sentence adds no link
    tr.scrolledIntoView 4: an insert that does not scroll; setContent then focus; redo of an unlinked chunk; the y-undo space test
    !isHistoryTransaction 2: redo of an unlinked chunk; undo of a deletion
    ySyncOrigin === null 1: a y-undo insert is not linked
    stop after the last whitespace 2: leaves the word after the last whitespace alone; key-by-key typing links as before
    last word always a candidate (Math.min) 1: a second space still links the word before the first
    every → some in the call 0
    • Why every → some fails nothing (read from code): the two differ only when one batch mixes a typed chunk with a non-typed transaction that a higher-priority plugin appended. No test builds such a batch. some could only widen the chunk path, and no current plugin makes that batch on typed input. So it is not a real regression risk, and I added no test.
    • y-tiptap note: y-tiptap 3.0.10 calls scrollIntoView on a focused remote or y-undo change (dist line 1586). So the ySyncOrigin guard matters in a real browser. The test "a y-undo insert is not linked" already pins it.
    • Gates after all changes: unit 530 / 530, typecheck and ESLint pass, clean-room Cypress 289 / 289 (22 specs).
    • Still owed (maintainer): one real macOS dictation and one text replacement on a local scratch pad, and WebKit on a pad.
  7. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    One-chunk insert check, 2026-11-16: pass in WebKit and Chrome.

    Dictation and text replacement reach the page as one text insert, not as key presses. A real spoken dictation was not possible here, so this check sends that same one-chunk insert to the production pad (b7888dce1), with a URL in the middle of the phrase.

    Engine Method Phrase Result
    WebKit (Safari 26.5 engine, Playwright build 2336) keyboard.insertText (input-method commit) see example.net now example.net linked to https://example.net
    WebKit document.execCommand('insertText') see example.edu now linked
    Headless Chrome 151 keyboard.insertText see example.io now linked
    Headless Chrome 151 execCommand('insertText') see example.dev now linked
    Chrome 157 (desktop, signed in) execCommand('insertText') see example.app now linked
    • The fix is ead539a38, live since eeb1ab727, with the paste-cost fix 843305131 live since b7888dce1.
    • Not run: a real voice dictation and a configured macOS text replacement. The maintainer asked for this check in Safari and Chrome instead (2026-11-16).

    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