Skip to content

Hyperlink: keep the whole link when part of it is formatted #770

Closed

Description

@HMarzban

Part of #769. Land this first: #771, #772 and #773 edit the same file and run their tests on top of it.

Summary

With autolink: true, formatting part of a link removes the link from part of its text. Bold over ple. in the link example.com leaves a plain exam and a link that holds only ple.com. The pad sets autolink: true (apps/webapp/src/components/TipTap/TipTap.tsx:233). The chat composer sets it too (apps/webapp/src/components/chatroom/components/MessageComposer/hooks/useTiptapEditor.ts:184). It is also the extension default (extensions/extension-hyperlink/src/hyperlink.ts:235). So every pad and every chat message can hit it. Upstream @tiptap/extension-link keeps the whole link.

Reproduce

  1. Open any pad.
  2. Type see example.com (the space turns it into a link).
  3. Select ple. inside the link and press Mod-b.
  4. Today: exam is plain text, and only ple.com is linked. Expected: all of example.com stays one link, with ple. bold.

The same happens with italic, strike, underline and inline code, with bold over two links at once, and with plain typing inside a link that already holds a bold part (from Markdown import, HTML paste or an earlier bold).

Cause (read from code)

extensions/extension-hyperlink/src/interactions/autolink.ts, the strip pass (lines 43-73 after the fix).

  • getMarksBetween returns one entry per text node. Another mark splits one link into several text nodes.
  • The old code took newMarks[0], the first text node only, and read its text (exam).
  • urls.detect('exam') is false, so the pass removed the link from that piece.

Fix (ready in the working tree, not committed)

Candidate "c2" from the review. It needs both parts. Each part alone fails 2 of 17 review cases.

  1. Read the whole link on both sides with getMarkRange(doc.resolve(pos), type, attrs), not one text node.
  2. Skip when the mapped text of the old link equals its new text, joined with '\n' between blocks. A mark-only change keeps the text, so the link stays. The '\n' makes a split into two blocks count as a text change.

Files:

  • extensions/extension-hyperlink/src/interactions/autolink.ts: the fix (+14 / −4 lines).
  • extensions/extension-hyperlink/src/interactions/__tests__/autolink.test.ts: 13 new cases.
  • extensions/extension-hyperlink/CHANGELOG.md: a Fixed line and an Internal line under [Unreleased].
  • extensions/extension-hyperlink/scripts/bench/: the package bench (see Benchmark). The maintainer asked for it to land with this issue.

Benchmark

Field Value
Metric Behaviour cases passing (18 jsdom cases, scripts/bench/behaviour.ts). Bytes a StarterKit app pays for Hyperlink (min / gzip). Six jsdom speed workloads, median of 9 rotated rounds.
Before 5 / 18 cases. 70,854 / 25,213 B. Speed: see the bench table. All on main at 9f132692e, 2026-11-12.
After 16 / 18 cases (the 2 left belong to #772). 70,997 / 25,258 B (+143 / +45). Speed: every workload inside the control noise band, except boldPartOfLink −26 %, where the fix does less work and changes the output by design. Working tree, 2026-11-12.
Confounds None. Only src/interactions/autolink.ts changed.
Condition jsdom on Bun 1.4.4, darwin arm64, one laptop. esbuild minify, Bun zlib level 9.
How to run From extensions/extension-hyperlink: NODE_ENV=production bun scripts/bench/run.ts (before commit, base = main). After commit: --ref <commit>~1.
Pass rule Behaviour count rises; no speed row moves outside the control band; bytes stay under +100 B gzip for a StarterKit app.
Guard The UX contract below.
Owner Agent in the repo: code, tests, bench, CHANGELOG. Maintainer: the chat-composer check and the production pad check after deploy.
Claim "Formatting part of a link keeps the whole link (16 of 18 behaviour cases, from 5)." No speed claim.

UX contract

Behaviour that must not change, and the check that proves it:

  • A broken URL still loses its link: deleting .com removes it (unit test).
  • A space typed inside a link keeps the whole link, as today and upstream (unit test).
  • A custom label such as "click here" stays linked when part of it is bold (unit test).
  • Code still removes the link where it lands, because the code mark excludes other marks (unit test).
  • One Mod-z after the bold gives back the plain link in one step. One redo gives back the bold with the whole link (unit test with prosemirror-history; real keys in the playground).
  • Pad (y-undo, link icons on): Mod-b, Mod-z, Mod-Shift-z on part of a link keep one whole link, and the selection stays put (local dev-local, 2026-11-12).
  • Two tabs on one pad: a bold and an italic from one tab show the same single link in the other (local dev-local, live Hocuspocus, 2026-11-12).
  • Mod-k inside a split link opens the preview for the whole link (playground).
  • Chat composer (prosemirror-history): bold part of a link, undo, redo. The link stays whole. Not checked in the webapp yet.
  • Production pad after deploy: the reproduce steps above.

Acceptance checks

  • src/interactions/__tests__/autolink.test.ts: 13 cases. With the fix reverted, 9 fail; with it, 0 fail (sabotage proof).
  • bun run test:unit: 453 of 453 pass.
  • bun run typecheck is clean. ESLint and Prettier are clean on every changed file.
  • Full package Cypress suite, env -u ELECTRON_RUN_AS_NODE bun run test:e2e: 289 of 289 pass across 23 specs.
  • dist/index.d.ts cannot change: the diff touches no export (read from code).
  • Chat composer check above.
  • Commit through the commit-review skill, then post the bench table from --ref <commit>~1 in a comment.
  • After deploy: the production pad check, then close.

Out of scope

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

    Measured (2026-11-12, working tree, not committed yet)

    Package bench, base = main at 9f132692e, head = working tree with the fix:

    base = main, head = working tree. jsdom on Bun 1.4.4, darwin arm64, 9 rounds, 2026-11-12T15:48:47.688Z.
    A speed change smaller than the control's is noise.

    Metric base head Change
    Bytes: npm dist/index.js (min / gz) 57,127 / 20,500 57,291 / 20,566 +164 / +66
    Bytes: a StarterKit app pays (min / gz) 70,854 / 25,213 70,997 / 25,258 +143 / +45
    Bytes: normalizeHref-only import (min / gz) 368,030 / 121,399 368,173 / 121,447 +143 / +48
    Behaviour: all cases 5/18 16/18 +11
    Behaviour: strip 0/10 10/10
    Behaviour: undo 1/2 2/2
    Behaviour: keep 4/4 4/4
    Behaviour: href 0/2 0/2
    Speed: pasteText2000 (ms) 749.999 723.232 -4% · control +2%
    Speed: boldAll2000 (ms) 464.938 477.259 +3% · control +5%
    Speed: typeEnd2000 (µs/key) 229.353 231.718 +1% · control +1%
    Speed: pasteOverSelection250k (ms) 29.092 29.497 +1% · control -4%
    Speed: boldPartOfLink (ms) 0.233 0.173 -26% · control +7% · output differs
    Speed: mount1000Links (ms) 36.512 35.187 -4% · control +5%

    Still failing on head: href: custom href after a space; href: custom href after bold 1-13.

    Checks run:

    • Unit: src/interactions/__tests__/autolink.test.ts 13 cases; 9 fail with the fix reverted, 0 with it. bun run test:unit 453 / 453.
    • Cypress: full package suite 289 / 289 across 23 specs (env -u ELECTRON_RUN_AS_NODE bun run test:e2e).
    • Playground, real keys: Mod-b on ple., Mod-z, Mod-Shift-z, then Mod-k on the split link. One whole link throughout; selection unchanged.
    • Local pad (dev-local, y-undo, link icons on): the same keys; one whole link; one undo step.
    • Two tabs on one local pad, live Hocuspocus: a bold and an italic from tab A show as one link with both marks in tab B.

    Still owed: the chat composer check in the webapp, the commit, and the production pad check after deploy.

  5. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    Chat composer check: needs a signed-in user

    On a local dev-local pad, a signed-out visitor gets no chat composer, so the composer check (bold part of a link, Mod-z, Mod-Shift-z) needs a signed-in account. The composer uses prosemirror-history, the same undo route the playground check and the unit tests cover, and both pass. Owner: maintainer, on a signed-in local or staging session.

  6. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    Committed

    c9cd2c98a on main, 2026-11-12, not pushed yet. One commit holds #770, #772, #773 and #776 together, by the maintainer's choice, so it cites each with Refs, and none closes on push. It is the same code the measured comments above describe.

    Open before this issue closes:

    • Chat message box check, signed in: bold part of a link, Mod-z, Mod-Shift-z.
    • Production pad check after deploy: the reproduce steps in the issue body.
  7. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    The bench table against the commit's parent (--ref c9cd2c98a~1) is on the tracking issue: #769 (comment). Behaviour 5 / 18 → 18 / 18 for the whole commit.

  8. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    In-app check at c9cd2c98a (2026-11-12, local webapp :3001)

    Setup: headless Chrome for Testing 158.0.8127.18 (build 1254), Playwright 1.64.1, Bun 1.4.4, Apple M5 Max, 1440x900. A local test user was signed in. All keys were real keyboard events.

    In the chat composer:

    • Typing see example.com autolinks it.
    • Selecting ple. and pressing Mod-b gives one link holding exam<strong>ple.</strong>com.
    • One Mod-z gives back the plain link.
    • Mod-Shift-z gives the bold back, still in one link.
    • The selection stays on ple. through all three steps.
    • No message was sent.

    This passed in 6 of 6 sessions, plus 2 of 2 verifier re-runs: 8 of 8 in total.

    Negative control. The verifier rewrote the served autolink chunk to the parent logic. With that, the check failed in 0 of 2 sessions. Bold gave <strong>ple.</strong>com with exam unlinked, which is the #770 symptom. This is not the parent build, because other HEAD code still ran.

    The app runs the fix. The served chunks hold the whole-link getMarkRange and the same-text skip from c9cd2c98a.

    Earlier jsdom result (wf3): the parent gave exam[ple] ¶ [.com], and c9cd2c98a gives example ¶ [.com] (Enter at pos 8).

    Limits:

    • The chat was opened by focusing the TOC "Open chat" button and pressing Enter, because the idle trigger refuses clicks.
    • Only headless desktop was tested. There is no mobile or headed run.

    The issue's Owner row gives the chat-composer check to the maintainer, so this is evidence for that tick. The production pad check after deploy is still owed.

    Raw data: local workflow folders wf4/p3-signed-in-ux (runs 7–12) and wf4/v-p3-signed-in-ux (v1, v2, s1, s2).

  9. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    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.

    Surface Steps Result
    Pad Type see example.com , select ple., Mod-b One link to https://example.com, text example.com, ple. bold inside it
    Pad Mod-z, then Mod-Shift-z The link stays whole both times; the bold goes off, then back on
    Chat composer (title heading) The same three steps; the composer was cleared and never sent One whole link through bold, undo and redo

    Both acceptance boxes pass on the live build. The fix is c9cd2c98a, live since 3d90636a9 (2026-11-13) and still in b7888dce1. 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