Repository navigation
Closed
Description
Part of #769. Depends on #770 (same file).
Summary
Autolink replaces a link's custom target with its label. A link whose label looks like a URL but points elsewhere loses its real target when the user types a space after it or bolds it. The user's target is lost without any sign. Upstream @tiptap/extension-link keeps the custom target.
Reproduce
Content: <p><a href="https://other.example/x">example.com</a> after</p> (a label that looks like a URL, a different target).
- Put the caret right after
example.com(position 12) and type a space. Or select positions 1-13 and pressMod-b. - Today: the link's
hrefbecomeshttps://example.com. Expected: it stayshttps://other.example/x.
Real case: the user edits a link's target with Mod-k, then keeps typing next to it.
Cause (read from code)
- The add pass in
extensions/extension-hyperlink/src/interactions/autolink.ts:117-139finds the last word before the whitespace and callstr.addMark(from, to, type.create({ href })). - It never checks whether that range already carries a hyperlink mark, so the new mark replaces the old one.
- Upstream skips such ranges:
@tiptap/extension-link3.32.2,src/helpers/autolink.ts:184-190, usesgetMarksBetween(link.from, link.to, newState.doc).some(...)beforeaddMark.
Fix
In the add pass, skip a detected URL whose range already carries a hyperlink mark. Match the upstream rule. The partial-format fix (#770) does not touch this path.
Benchmark
| Field | Value |
|---|---|
| Metric | Behaviour group href in scripts/bench/behaviour.ts (2 cases: custom href after a space, after bold 1-13). Bytes a StarterKit app pays. |
| Before | href 0 / 2 (on main and with #770). Bytes: the #770 after value. |
| After | not measured yet |
| Confounds | Land after #770 and measure against it. |
| Condition | jsdom on Bun 1.4.4, one laptop. esbuild minify, Bun zlib level 9. |
| How to run | NODE_ENV=production bun scripts/bench/run.ts --ref <commit before this fix> |
| Pass rule | href 2 / 2; every other behaviour case still passes; bytes under +50 B gzip; speed inside the control band. |
| Guard | The UX contract below. |
| Owner | Agent in the repo: code, tests, bench. Maintainer: the pad check after deploy. |
| Claim | "A link keeps its own target when you type next to it." |
UX contract
- A plain
example.comstill autolinks. - Typing a URL right after an existing link (no space) still autolinks the new URL, and the old link keeps its own
href. - Pad: edit a link's target with
Mod-k, then type a space after it. The target stays. - Every Hyperlink: keep the whole link when part of it is formatted #770 test still passes.
Acceptance checks
- Unit tests in
src/interactions/__tests__/autolink.test.ts: a space at 12 and bold 1-13 keephttps://other.example/x. They fail with the fix reverted. -
bun run test:unitand the full package Cypress suite pass. - Bench before and after posted here. CHANGELOG
Fixedline.
Out of scope
- The strip pass (Hyperlink: keep the whole link when part of it is formatted #770).
Activity
HMarzban commentedon Nov 12, 2026
Measured (2026-11-12, working tree, not committed yet)
Fix: the add pass in
src/interactions/autolink.tsskips a detected URL whose range already carries a hyperlink mark (newState.doc.rangeHasMark(from, to, type)), as upstream does.Package bench, base = a copy of
src/with #770 only, head = #770 + this fix:dist/index.js(min / gz)normalizeHref-only import (min / gz)jsdom on Bun 1.4.4, darwin arm64, 9 rounds. Speed rows are within the noise band (the
controlcopy moved up to ±9 % in the same run).Checks run:
bun run test:unit: 456 / 456.[Unreleased]→Fixedline.Still owed: the full package Cypress suite (runs once with #776), the pad check (
Mod-ka new target, then type a space after the link), the commit.HMarzban commentedon Nov 12, 2026
Pad check (local
dev-local, 2026-11-12)On a local pad with this fix and #770, #776 and #773 built in: a link
example.com→https://other.example/x, caret right after it, a real space key, then typedmore. The link kepthttps://other.example/x. A typeddocs.plusfollowed by a real space key still autolinked tohttps://docs.plus.Not done: the
Mod-kedit-then-type flow through the webapp form.HMarzban commentedon Nov 12, 2026
Committed
c9cd2c98aonmain, 2026-11-12, not pushed yet. One commit holds #770, #772, #773 and #776 together, by the maintainer's choice, so it cites each withRefs, and none closes on push. It is the same code the measured comments above describe.Open before this issue closes:
Mod-kflow: change a link's target in the form, then type next to the link.HMarzban commentedon Nov 12, 2026
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. All keys were real keyboard events.
On a fresh scratch pad:
docs at example.comautolinks it tohttps://example.com.https://other.example/x, then Apply.moreare typed.The href stays
https://other.example/xafter the save, after the space and aftermore. The link text staysexample.com, andmorestays unlinked. This passed in 6 of 6 sessions, plus 2 of 2 verifier re-runs: 8 of 8. Four of the 8 sessions placed the caret with a real ArrowRight, and four withcommands.focus.Negative control. The verifier rewrote the served autolink chunk to the parent logic. With that, the check failed in 0 of 2 sessions: the href went back to
https://example.comafter the space. This is not the parent build.The app runs the fix: the served chunks hold the
rangeHasMarkfilter fromc9cd2c98a. One setup step was not a key: the pad caret went to the end withcommands.focus('end'). Only headless desktop was tested.This evidence covers the contract line "Pad: edit a link's target with Mod-k, then type a space after it." The production pad check after deploy is still owed.
Raw data: local workflow folders
wf4/p3-signed-in-ux(runs 7–12) andwf4/v-p3-signed-in-ux(v1, v2, s1, s2).fix(extension-hyperlink): keep links intact when autolink runs
perf(webapp): load HyperlinkBase in the pad and composer
HMarzban commentedon Nov 16, 2026
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.Steps: type
example.comso it autolinks. Open the link's preview, press Edit, set the URL tohttps://other.example/xand Apply. Put the caret after the link and type a space andmore.Result: the link keeps
https://other.example/x. Autolink did not rewrite it from the label. Cypress 289/289 was recorded on #773. The fix isc9cd2c98a, live since3d90636a9and still inb7888dce1. Release credit v2.3.8. Closing as done.