Skip to content

Hyperlink: add HyperlinkBase without the prebuilt popovers #775

Closed

Description

@HMarzban

Part of #769. Depends on #774: without PURE annotations the saving is 0.

Summary

Hosts that draw their own link popovers still ship the three prebuilt forms (preview, edit, create). The docs.plus pad and chat composer pass all three slots (apps/webapp/.../getHyperlinkPopoverConfig.ts), so that code is dead in the webapp. This issue adds HyperlinkBase, the same mark without the prebuilt forms. Hyperlink stays as it is and keeps its fallback. It is the only byte cut from the review that reaches the docs.plus webapp.

Review numbers (2026-11-12, prototype on top of PURE sites 1-2; this issue takes its own before and after)

Row Hyperlink today With HyperlinkBase
The webapp-like app pays (min / gzip) 54,947 / 19,144 B −6,108 / −1,809 B
A StarterKit app pays 70,854 / 25,213 B −6,710 / −2,018 B
The full Hyperlink after the change — +285 / +87 B in a StarterKit app (the fallback moves into storage)

Why the first prototype was wrong

Tiptap configure deep-merges options. A prototype that put the prebuilt factories into option defaults broke two promises:

  • README lines 25 and 94, and docs/api.md lines 151 and 199, say an opener uses the prebuilt form when its popover slot is null.
  • It also broke the no-options case: the click gate (src/interactions/createLinkContext.ts:35, src/interactions/clickHandler.ts:61) and openPreviewAtSelection.ts:30 read the option slots, so a link click and Mod-k inside a link opened a preview where 2.3.0 does not.
  • In a 24-cell matrix (4 configs × 6 actions), it differed from 2.3.0 in 8 cells.

Fix (the shippable shape; 24 of 24 cells match 2.3.0 in the review)

  1. export const HyperlinkBase = /* @__PURE__ */ Mark.create(...), with the option defaults still null.
  2. export const Hyperlink = /* @__PURE__ */ HyperlinkBase.extend({ addStorage() { return { ...this.parent!(), prebuiltPopovers: { previewHyperlink, editHyperlink, createHyperlink } } } }).
  3. Add optional prebuiltPopovers to HyperlinkStorage.
  4. Add getPrebuiltPopovers(editor) in src/openers/getHyperlinkOptions.ts. It reads editor.storage.hyperlink?.prebuiltPopovers ?? {}.
  5. openPreviewHyperlink.ts:15, openEditHyperlink.ts:19 and openCreateHyperlink.ts:22 use popovers.x ?? getPrebuiltPopovers(editor).x, and drop their direct popover imports.
  6. Never put the factories into option defaults.
  7. Docs: README lines 25 and 94; docs/api.md lines 16, 151 and 199; the JSDoc at src/commands/surface.ts:28. Each says the fallback belongs to the full Hyperlink only. Add one README paragraph: choose HyperlinkBase when you pass your own popovers; choose Hyperlink otherwise.
  8. Webapp switch (TipTap.tsx:230, useTiptapEditor.ts:180) in a separate commit after the extension release.

Residual risk: an addStorage override that rebuilds the storage without this.parent() loses the fallback. Name it in the CHANGELOG.

Benchmark

Field Value
Metric Package bench byte rows with the app importing HyperlinkBase; the webapp's own route table after the switch.
Before Take it after #774 lands. Post it as a Measured comment.
After not measured yet
Confounds #774, #776.
Condition esbuild minify, ESM, browser, Bun zlib level 9, exact. Webapp: build:ci route table.
How to run Package bench; extend bytes.ts with a HyperlinkBase app case. Webapp: build:ci.
Pass rule The webapp-like case drops at least 1,500 B gzip; the full Hyperlink costs at most +120 B gzip.
Guard The UX contract below.
Owner Agent in the repo: code, tests, docs, bench. Maintainer: the release, and the phone checks after the webapp switch.
Claim "Hosts with their own link forms ship about 1.8 kB gzip less."

UX contract

  • A jsdom matrix for Hyperlink and HyperlinkBase. Configs: no options, configure({}), all slots null, the README Quickstart. Actions: click a link, Mod-k outside and inside a link (real keydown), each opener. Hyperlink matches 2.3.0 in all 24 cells.
  • HyperlinkBase with null slots opens nothing, and the openers return false. The Quickstart opens everything.
  • Before the webapp switch, list every opener call and slot the webapp fills: toolbar, Mod-k, link click, hovercard edit, chat composer, phone docked controls.
  • After the switch, on desktop and in mobile emulation: create, preview and edit open as before. On iOS emulation, the first Mod-k (or the toolbar link button) opens the create form and the keyboard in the same tap.
  • dist/index.d.ts diff shows additions only.

Acceptance checks

  • One fallback test each in src/openers/__tests__/openPreviewHyperlink.test.ts, openEditHyperlink.test.ts and openCreateHyperlink.test.ts, for both marks. Sabotage proof.
  • bun run test:unit, typecheck, the full package Cypress suite.
  • README Quickstart (examples/vanilla) runs unchanged; scripts/extension-preflight.sh passes.
  • CHANGELOG Added line (minor version).

Out of scope

  • Removing the fallback from Hyperlink (a major).
  • Feature factories for hovercard, pasteTitle and linkIcon (deferred to the product 3.0 major).

Activity

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

    @HMarzban
    CollaboratorAuthor

    Bytes on top of #774 (2026-11-12, scratch prototype)

    Same build setup as the #774 comment. StarterKit app, min / gzip B:

    Build Hyperlink HyperlinkBase Change
    On #774 (s5b) 70,776 / 25,582 64,042 / 23,560 −6,734 / −2,022
    Full Hyperlink after #775, on s5b 71,030 / 25,640 — +254 / +58
    HyperlinkBase without #774, against the full Hyperlink after #775 on A-literal 71,102 / 25,642 71,102 / 25,661 0 / +19

    Raw data (<wf3> = the maintainer's local workflow folder wf3/, kept outside the repo): <wf3>/v-e4-pure-build/results/bytes-AhmmOn-s5c-s5cbase-BaseS5b.json (s5b rows) and e4-pure-build/results/bytes-*.json (without #774). Re-run: cd <wf3>/v-e4-pure-build && NODE_ENV=production bun build.ts BaseS5b && bun bytes.ts BaseS5b.

  5. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

    Built (2026-11-13). Not committed yet. The webapp is not switched.

    Shape.

    • One internal factory, createHyperlinkMark(prebuilt), builds both marks.
    • HyperlinkBase = createHyperlinkMark({}).
    • Hyperlink = createHyperlinkMark({ preview, edit, create }).
    • The prebuilt forms sit in storage.prebuiltPopovers, an optional field, so an existing addStorage override still type-checks.
    • The openers and can() resolve a slot through one helper: the configured slot, else the prebuilt form.

    Behaviour.

    • Under Hyperlink, nothing changes. Openers fall back to the prebuilt forms, and editor.can().openCreateHyperlinkPopover() stays true. A 24-cell matrix matched the @docs.plus/[email protected] source.
    • Under HyperlinkBase with empty slots, nothing opens.
      • openPreviewHyperlink and openCreateHyperlink return false, and can() returns false.
      • openEditHyperlink still returns void, so index.d.ts gains only additions.
      • Mod-k outside a link is left to the browser. The README says so.
    • An extend whose addStorage skips this.parent() loses the fallback. The CHANGELOG says so.

    Bytes.

    • Condition: package bench; esbuild minify, ESM, browser; Bun zlib level 9; exact bytes, n = 1 per row.
    • "Pays" means the app minus a StarterKit-only app.
    • "Three own slots" means a stub factory in every slot.
    What a StarterKit app pays (min / gzip B) Before After
    Hyperlink, configure({}) 71,254 / 25,729 71,504 / 25,819
    Hyperlink, three own slots 71,367 / 25,774 71,617 / 25,845
    HyperlinkBase, configure({}) — 64,631 / 23,751
    HyperlinkBase, three own slots — 64,744 / 23,792
    • Rule 1: HyperlinkBase with three slots, against Hyperlink with three slots before, must save at least 1,500 B gzip. It saves 6,623 B minified and 1,982 B gzip: pass.
    • Rule 2: the full Hyperlink may cost at most +120 B gzip. It costs +250 / +90 B, and +250 / +71 B with three slots: pass.
    • The three-slot app stands in for the webapp row. The webapp route table will be measured in the switch commit.

    Tests and gates.

    • The jsdom matrix has 4 configs and 7 actions, including can().
    • Sabotage of the fallback or of the can() check makes it fail.
    • Unit tests pass. Cypress passes 289 of 289 in 22 specs. Typecheck, build and preflight pass.
    • Speed: jsdom, 9 rounds, within the control's noise.

    Still owed.

    • The webapp switch, with its route table and the list of opener calls.
    • Fix docs/popovers.md:94. It still says every opener falls back.
  6. HMarzban commented on Nov 13, 2026

    @HMarzban
    CollaboratorAuthor

    Webapp switched to HyperlinkBase (2026-11-13, not committed yet)

    The pad (TipTap.tsx) and the chat composer (useTiptapEditor.ts) now load HyperlinkBase. Every option is unchanged.

    Slot audit. getHyperlinkPopoverConfig and getHyperlinkPopoverConfigAtInvoke return three non-null slots on every branch: pad desktop, pad mobile and composer mobile. History and /editor get the same popovers. Click and Mod-k read the slot directly. No path relies on the prebuilt fallback, so nothing changes at runtime.

    Route table, local build:ci (Next 15.5.28, n = 1, exact kB; the only difference between the two builds is the switch):

    Route Before After
    / first load 953 kB 951 kB
    /[...slugs] first load 926 kB 924 kB
    _app first load 921 kB 919 kB
    Shared by all 966 kB 965 kB

    The after build holds none of the prebuilt form strings ("Please enter link text", the hyperlink-*-popover classes).

    Browser checks.

    • Webapp Cypress, local next dev: all 8 editor/hyperlink/* specs, document/hyperlink-icon-prefill, editor/slash/slash-menu and chatroom/composer-link-keys: 89 of 89 pass. The chat spec needs --config baseUrl=http://localhost:3001.
    • Phone emulation (375 × 812): the "Add link" sheet opens through the create slot, a tap on a link opens the preview sheet with Open, Copy, Edit and Remove, and Edit uses the webapp's own sheet switch.

    The webapp CHANGELOG lists the switch under [Unreleased].

  7. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    iOS check, 2026-11-16: not valid; a real iPhone is still owed.

    • iOS Simulator iPhone 18 Pro (iOS 27.0), Safari, signed out, a production scratch pad at b7888dce1. The pad loaded, and the pencil opened edit mode with the keyboard and the mobile toolbar.
    • One tap on the toolbar link button opened no sheet. The simulator delivered the click at the previous tap point (now on the keyboard), a known simulator lag. So the run proves nothing either way.
    • Owed: one tap on a real iPhone in Safari. In edit mode, one tap on the toolbar link button must open the create sheet and the keyboard together. Then check the preview and edit sheets, and the chat composer link button.
  8. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    iOS check, 2026-11-16: pass.

    • iOS Simulator iPhone 18 Pro (iOS 27.0), Safari, signed out, production pad at b7888dce1.
    • The simulator delivers each tap one call late (a known simulator lag, shown again today: the pencil tap landed on the next call). So the check placed the previous tap on the link button first. That makes the button receive exactly one clean tap.
    • In edit mode, with the caret in a paragraph, one tap on the toolbar link button opened the Add link sheet with the caret in the URL field, and the keyboard stayed up with the URL layout (.com key).
    • Not checked here: the chat composer link button, which needs a signed-in chat. The 28-cell matrix and the 89/89 webapp specs on this issue cover it.

    The change is f52630eed and 13cd8ab27, live since 3d90636a9. 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

ExtensionPerformanceenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions