fix(desktop): keep markdown link and image attributes as strings so a paste can't stop the editor saving
Problem
Pasting rich text into a markdown editor could put it into a state where it silently stops saving. The pasted content appears on screen, but the editor's onChange never fires again and onBlur no longer saves — every later serialization of that document throws.
Reported as DESKTOP-1A6 (desktop 1.29.0, renderer, unhandled, on a paste event).
Root cause
@tiptap/core's default attribute parser runs element.getAttribute(name) through fromString, which coerces numeric- and boolean-looking strings:
function fromString(value) {
if (typeof value !== "string") return value;
if (value.match(/^[+-]?(?:\d*\.)?\d+$/)) return Number(value);
if (value === "true") return true;
if (value === "false") return false;
return value;
}
Any attribute that does not declare its own parseHTML gets that treatment. @tiptap/extension-link declares title: { default: null } with no parseHTML (its href has one, which is why only title was exposed), so an anchor carrying title="2024" loads a link mark whose title is the number 2024. prosemirror-markdown then does:
mark.attrs.title ? ` "${mark.attrs.title.replace(/"/g, '\\"')}"` : ""
Truthy, not a string — TypeError. Both markdown surfaces serialize on every update (onUpdate → getMarkdown), so once such a link is in the document the throw repeats on every keystroke and nothing downstream ever receives the content again.
This is the same coercion #6663 fixed for image src/alt/title. That fix landed on SafeImage in the renderer and never reached MarkdownEditor, because the two surfaces keep separate copies of these extensions. So the editor had two live instances of the same crash class: the link title reported here, and image alt/title — LinearImage overrode only src, and only incidentally, to rewrite Linear-hosted URLs through the proxy.
Fix
Declare the verbatim parsing once, in renderer/lib/tiptap/markdown-attributes.ts, and use it from every extension that feeds the markdown serializer:
verbatimStringAttributes(...names)— used bySafeImage(src/alt/title) andLinearImage(alt/title, composing with its own proxyingsrc).SafeLink— one shared mark, imported by both extension lists, each still applying its own.configure().
renderer/lib/tiptap/ already exists and is already imported by both surfaces, so this adds no new coupling direction. Both files come out net smaller, and the duplication that let the earlier fix drift is gone.
No behaviour change for attributes that were already strings, and the Linear image proxy rewrite is untouched.
Verification
Reproduced first — the new tests fail on main with the exact production error:
484 | : "](" + mark.attrs.href.replace(...) + (mark.attrs.title ? ` "${mark.attrs.title.replace(/"/g, '\"')}"` : "") + ")";
^
TypeError: mark.attrs.title.replace is not a function.
(fail) link attribute parsing > keeps a numeric link title as a string and serializes it
(fail) link attribute parsing > keeps a boolean-looking link title as a string
9 pass
2 fail
After the fix:
$ cd apps/desktop && bun test src/renderer/components/MarkdownRenderer/components/TipTapMarkdownRenderer/
66 pass
0 fail
151 expect() calls
Ran 66 tests across 5 files. [922.00ms]
$ bunx biome check <the four changed files>
Checked 4 files in 8ms. No fixes applied.
$ cd apps/desktop && bun run typecheck
$ tsc --noEmit (clean)
The round-trip tests cover SafeLink and the helper — the code both surfaces now share, including the exact production path. LinearImage stays module-local inside MarkdownEditor.tsx and is covered by typecheck rather than by its own test; its extension list is built inline in the component, which cannot be mounted without the authenticated route provider tree.
No user-facing strings changed, so check:i18n does not apply.
Refs DESKTOP-1A6
Refs DESKTOP-100
Summary by CodeRabbit
-
Bug Fixes
- Fixed Markdown links and images so text-based attributes, including titles and alternative text such as “2024” or “true,” retain their original string values.
- Improved Markdown round-tripping to preserve link titles and title-less links without unintended conversions.
-
Tests
- Added coverage for preserving link attributes and maintaining unchanged Markdown through editing and rendering.