Skip to content

fix(editor): let live preview resolve link targets through the host app#560

Merged
murongg merged 1 commit into
markrahq:v2from
jian45154:fix/live-preview-link-resolver
Jul 22, 2026
Merged

fix(editor): let live preview resolve link targets through the host app#560
murongg merged 1 commit into
markrahq:v2from
jian45154:fix/live-preview-link-resolver

Conversation

@jian45154

Copy link
Copy Markdown
Contributor

Fixes #559

What

Local attachment links (FILE://) lost their <a href> rendering in live preview after the Milkdown → CodeMirror migration: buildDecorations in preview.ts hardcoded resolveSafeLinkTarget, so only http/https/mailto/tel and scheme-less targets could render as anchors, with no way for the host app to allow its local-attachment scheme.

  • Add an optional resolveLinkTarget hook to LivePreviewConfig (mirrors linksPlugin.resolveTarget and imagePreviewPlugin.resolveSource, including the try/catch + trim semantics of resolvedLinkSource). Default behavior is unchanged when the hook is not provided.
  • Pass the existing app resolver from CodeMirrorPaperSurface so imported attachments render as anchors again.
  • Align the clears finalized image source editing app test with the current CodeMirror widget UX (preview stays visible, inline source row opens); its old expectations described removed Milkdown behavior and always failed.
  • Test-infra: raise asyncUtilTimeout to 5s and testTimeout to 15s in @markra/app — on slower machines the 1s/5s defaults produced rotating timeout flakes across the suite. Feel free to drop this commit if you prefer.

Why it went unnoticed

ci.yml only triggers on main, so pushes to v2 never ran the frontend suite. Two App.test.tsx tests covering this behavior fail deterministically on v2:

  • imports local attachments into an unsaved document when external files are not copied
  • clears finalized image source editing when document search opens

(The pre-existing typecheck:test failure in packages/editor/src/codemirror/ai-preview.test.ts on v2 is unrelated and left untouched.)

Verification

  • @markra/editor tests: 245 passed (adds 2 focused tests for the new hook: resolver-allowed target renders an anchor, resolver-rejected target renders a plain span).
  • @markra/app tests: 1357 passed, including the two previously failing tests.
  • pnpm build passes.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

@jian45154 is attempting to deploy a commit to the murongg's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
markra-web Ready Ready Preview, Comment Jul 22, 2026 11:18am

@murongg murongg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix — local attachment links now render correctly in the regular live preview. There is one remaining rendering path that needs the same resolver before this is complete.

Visual table cells use the separate renderInlineMarkdown path. That renderer still hardcodes resolveSafeLinkTarget, while renderVisualTableCell only forwards the image resolver. As a result, the same link still loses its anchor semantics inside a visual table:

| Attachment |
| --- |
| [Reference.pdf](FILE:///mock-files/Reference.pdf) |

I reproduced this with a focused table test using tablePreviewPlugin({ links: { resolveTarget } }): expected A, received SPAN.

Please pass the link resolver through InlineMarkdownRenderOptions and the table rendering path, including the current editor state/view context, and add a regression test for a custom-resolved link inside a visual table cell.

Non-blocking: the global asyncUtilTimeout / testTimeout increase is unrelated to the link fix and would be easier to evaluate as a separate PR (or can be dropped here).

@jian45154
jian45154 marked this pull request as draft July 22, 2026 09:29
@jian45154
jian45154 marked this pull request as ready for review July 22, 2026 09:32
@jian45154
jian45154 force-pushed the fix/live-preview-link-resolver branch from 77365d7 to fe313cb Compare July 22, 2026 09:47
Live preview and visual table cells hardcoded resolveSafeLinkTarget when
deciding whether a link renders as an anchor, so local attachment links
(FILE://) imported via Import Local Files lost their href after the
CodeMirror migration.

- Add an optional resolveLinkTarget hook to LivePreviewConfig, mirroring
  linksPlugin.resolveTarget and imagePreviewPlugin.resolveSource, and
  pass the existing app resolver from CodeMirrorPaperSurface.
- Add resolveLinkTarget to InlineMarkdownRenderOptions and forward the
  tablePreviewPlugin links resolver with editor state/view context from
  renderVisualTableCell, matching the image resolver plumbing.
- Align the image source editing app test with the CodeMirror widget UX;
  its old expectations described removed Milkdown behavior.
- Test infra: raise asyncUtilTimeout/testTimeout in @markra/app and
  clear the shared jsdom selection between tests, fixing order-dependent
  selection collapses and slow-machine timeout flakes.

Fixes markrahq#559

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jian45154
jian45154 force-pushed the fix/live-preview-link-resolver branch from fe313cb to e8aed0c Compare July 22, 2026 10:55
@jian45154
jian45154 requested a review from murongg July 22, 2026 10:56
@murongg
murongg merged commit ecd7dda into markrahq:v2 Jul 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Editor]: Local attachment links (FILE://) no longer render as anchors after CodeMirror migration

2 participants