Skip to content

Hyperlink: decide what Enter inside a link does #778

Closed

Description

@HMarzban

Part of #769. Decision first; code only if the ruling changes today's behaviour. Found while fixing #770.

Summary

Pressing Enter inside a link splits it into two paragraphs. Today the first half loses its link, and the second half keeps a link to the old target. Upstream @tiptap/extension-link keeps both halves linked. Neither is clearly right, so the maintainer rules.

Reproduce

Content <p><a href="https://example.com">example.com</a></p>, caret after exam, press Enter.

Behaviour Result
Today (and with the #770 fix) <p>exam</p><p><a href="https://example.com">ple.com</a></p>
Upstream @tiptap/extension-link 3.32.2 both exam and ple.com linked to https://example.com

Why today's result: the strip pass sees the text change (the '\n' between blocks makes a split count as a change). exam alone is not a URL, so it loses the link. ple.com alone is a URL, so it keeps its link to https://example.com.

Decision needed (maintainer)

Ruling 2 of the review:

Fix (only for B or C)

The strip pass in extensions/extension-hyperlink/src/interactions/autolink.ts (lines 43-73). For B, treat a block split of one link as a mark-preserving change. For C, compare each half with the old href, not with detect.

Benchmark

Field Value
Metric A new behaviour case enter inside a link in scripts/bench/behaviour.ts, with the ruled result as "want".
Before Today's result above.
After not measured yet
Confounds #770, #772.
Condition jsdom on Bun.
How to run NODE_ENV=production bun scripts/bench/run.ts
Pass rule The case passes; every other case still passes.
Guard Undo of the Enter restores one whole link in one step.
Owner Maintainer: the ruling. Agent in the repo: the case, and code for B or C.
Claim None.

Acceptance checks

  • The ruling recorded in this issue.
  • The behaviour case added with the ruled result (even for A, to pin it).
  • For B or C: unit tests with sabotage proof, the full package Cypress suite, a pad check.

Activity

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

    @HMarzban
    CollaboratorAuthor

    Ruling 2 evidence (2026-11-12)

    Condition: jsdom 26.1.0, Bun 1.4.4, Tiptap core and StarterKit 3.32.2. Upstream is @tiptap/extension-link 3.32.2. Enter goes through handleKeyDown. Results are deterministic, n = 1 per case, and a verifier re-ran them byte-identical. marks a new paragraph, and [text] is a linked run.

    Content, pos Today B = upstream C C-urlonly*
    example.com, 3 ex ¶ [ample.com] [ex] ¶ [ample.com] ex ¶ ample.com ex ¶ ample.com
    example.com, 5 exam ¶ [ple.com] [exam] ¶ [ple.com] exam ¶ ple.com exam ¶ ple.com
    example.com, 8 example ¶ [.com] [example] ¶ [.com] example ¶ .com example ¶ .com
    example.com, 10 example.c ¶ [om] [example.c] ¶ [om] example.c ¶ om example.c ¶ om
    click here, 3/5/8/10 both linked both linked both unlinked both linked
    example.com → https://other.example/x, 3/5/8/10 keeps a link (pos 5: exam ¶ [ple.com]) both linked both unlinked both unlinked

    *C-urlonly is not one of the listed options. It applies C only when the old link text is a URL.

    Findings.

    • No option avoids every loss. Today and B keep text that names another host (ple.com → https://example.com) in 6 of 20 cases. B also links non-URL pieces such as [ex] and [example.c] to the old target. C drops click here labels in 4 of 4. Every C reading drops a custom href in 4 of 4.
    • Today checks only the first half. .com (pos 8) and om (pos 10) stay linked although neither is a URL. So the reason in this issue's body is not accurate.
    • B is a one-line change at autolink.ts:54, and it equals upstream on every case.
    • One undo restores one whole link in 20 of 20 cases, in every variant. Yjs undo was not tested.
    • The 474 package tests pass on every variant. A pin test is needed for whichever result is ruled.

    Recommendation: B. It never removes a link the user made, it does not depend on the caret position, and it matches upstream. Its cost: both halves point at the old target, even pieces such as [ex]. Today has the same mismatch on one half. Shipped code for any C reading must use ungated detect, not gated forWrite.

    Not run: Cypress, a pad check, Yjs undo.

    Raw data (<wf3> = the maintainer's local workflow folder wf3/, kept outside the repo): <wf3>/e2-enter-in-link/matrix.tsv and the verifier's verify-e2/. Re-run: cd <wf3>/e2-enter-in-link && POS=1,3,5,8,10 bun harness.ts <today|upstream|B|C> out.json, with C_URL_ONLY=1 or C_LITERAL=1 for the C readings.

  5. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

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

    Enter inside a link keeps both halves linked to the old target, as upstream @tiptap/extension-link 3.32.2 does. It never removes a link the user made, and it is the same at every caret position.

    Accepted cost: a half that is not a URL on its own (for example exam) stays linked to the old target. Today one half already has this mismatch.

    Pin the result with a unit test, and add an enter inside a link case to scripts/bench/behaviour.ts. One undo after the Enter must still restore one whole link.

  6. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

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

    Enter inside a link now keeps both halves linked to the old target, as in @tiptap/extension-link 3.32.2. The strip pass in autolink.ts no longer adds a block separator when it compares the text. So a block split counts as the same text.

    Unit tests. There are 20 new cases in autolink.test.ts.

    • Contents: example.com, a click here label, a link with a bold part, and a custom href.
    • Positions: 1, 3, 5, 8 and 10.
    • Each case checks the two paragraphs, the href on every character, one undo step, and the exact HTML after one undo.
    • With the old line restored, 12 of 20 fail. The label cases and position 1 pass on both versions, because they pin behaviour that already worked.
    • Package gates: unit tests pass, and Cypress passes 289 of 289 in 22 specs.

    Live check (y-undo).

    • Condition: local pad, headless Chromium, real Enter and Meta+Z, more than 1 s between steps.
    • Type example.com , then press Enter after exam. Result: [exam] ¶ [ple.com], both linked to https://example.com.
    • One Meta+Z gives back one paragraph with one whole link.

    Bench.

    • Condition: jsdom, Bun 1.4.4, darwin arm64, 9 rounds, two runs, with a control copy.
    • Bytes: +3 B minified, −3 B gzip on dist/index.js.
    • Behaviour: 18/19 before, 19/19 after. The new case "enter inside a link" goes from 0/1 to 1/1.
    • Speed: every row is within its control in at least one run. boldAll2000 showed +10% against a control of +6% in run 1, then +1% in run 2. The change adds no work.

    Accepted cost. A half that is not a URL on its own keeps the old href.

    Not run: iOS Safari, Android Chrome, two peers, Enter in a list item, and the see example.com prefix case.

  7. 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.

    Step Result
    Type visit example.org , put the caret after exam, press Enter Two paragraphs, exam and ple.org, both linked to https://example.org
    Mod-z One paragraph, one whole link example.org

    All three acceptance checks are met: the ruling (option B), the behaviour case (0/1 to 1/1), and 20 unit cases with sabotage proof (12 of 20 fail on the old line). The fix is f52630eed, 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

EditorExtensionquestion

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions