Skip to content

fix(muya): produce correct file:// URLs for UNC/WSL network paths - #4788

Closed
jyte wants to merge 3 commits into
marktext:developfrom
jyte:fix/unc-file-urls-only
Closed

jyte wants to merge 3 commits into
marktext:developfrom
jyte:fix/unc-file-urls-only

Conversation

@jyte

@jyte jyte commented Jun 29, 2026

Copy link
Copy Markdown

When a document is opened from a UNC path (e.g. \server\share... or \wsl.localhost\Distro...), getImageSrc() and resolveLocalImageSrc() produced invalid file:// URLs with 4 slashes (file:////server/share/...) that Chromium cannot load, causing 'Load image failed' errors.

Root cause: both muya's path resolver and the desktop's export/print resolver prepend 'file://' to UNC paths, producing the malformed URL 'file:////server/share/...' instead of the correct authority-based form 'file://server/share/...'.

Fix: add a pathToFileUrl() helper that detects UNC paths (starting with // after backslash normalisation) and produces the correct authority form. Applied consistently in:

  • packages/muya/src/utils/image.ts: getImageSrc() and correctImageSrc()
  • packages/desktop/src/renderer/src/util/resolveImageSrc.ts

Fixes #4577, #4563 (use case 1)

Closes #4577

Summary

Allows to render diagrams for files opened over network in windows.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added (or explain why not needed)
  • Manually tested on: Windows

Notes for reviewers [optional]


By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

jyte added 3 commits June 29, 2026 13:09
When a document is opened from a UNC path (e.g. \server\share\... or
\wsl.localhost\Distro\...), getImageSrc() and resolveLocalImageSrc()
produced invalid file:// URLs with 4 slashes (file:////server/share/...)
that Chromium cannot load, causing 'Load image failed' errors.

Root cause: both muya's path resolver and the desktop's export/print
resolver prepend 'file://' to UNC paths, producing the malformed URL
'file:////server/share/...' instead of the correct authority-based form
'file://server/share/...'.

Fix: add a pathToFileUrl() helper that detects UNC paths (starting with
// after backslash normalisation) and produces the correct authority form.
Applied consistently in:
- packages/muya/src/utils/image.ts: getImageSrc() and correctImageSrc()
- packages/desktop/src/renderer/src/util/resolveImageSrc.ts

Fixes marktext#4577, marktext#4563 (use case 1)
@jyte jyte mentioned this pull request Jun 29, 2026
3 of 6 tasks
@jyte

jyte commented Jun 30, 2026 •

Copy link
Copy Markdown
Author

Should I close the PR ? PR#4789 include this fix and add other fixes

niyo-oyin added a commit to niyo-oyin/marktext-ja that referenced this pull request Jul 30, 2026
Upstream PRs applied (all diff-reviewed, tests included and passing):
- marktext#4776: preserve ordered-list source markers — opening and saving no
  longer rewrites 1./1./1. to 1./2./3. (marktext#4772, silent doc mutation)
- marktext#4788: UNC/WSL paths become valid file:// authority URLs
  (file://server/share/…, not file:////…) so network images load
  (marktext#4577, marktext#4563)
- marktext#4952: table columns size to content (min-width 10em → 2em, marktext#4894)
- marktext#4773: malformed percent-escape in a clicked link no longer throws an
  unhandled URIError (marktext#4749)
- marktext#4873: Shift+digit/punctuation keybindings recordable and matchable
  again (patch-package fix for @hfelix/electron-localshortcut, marktext#4863)
- marktext#4910: sidebar icons match by extension first, so Dockerfile-Notes.md
  gets the markdown icon (marktext#4890)
- marktext#4317: restored windows are clamped to the target display's work area
  (multi-monitor / DPI, marktext#2928, marktext#1947)

Found while integrating marktext#4776: cloneStateTree shallow-copied meta, so
array-valued fields (order-list sourceMarkers, table aligns) stayed
SHARED between a getState() clone and the live document — mutating a
returned tree corrupted the document. Meta arrays are now copied, and
the clone walks an explicit work list instead of recursing, so
pathological nesting (600-level lists, marktext#4747) can no longer overflow
the call stack (10k-depth regression test).

Also: folder search debounces its per-keystroke ripgrep run (300ms,
Enter searches immediately, IME-composing keys ignored) (marktext#3556), and a
new undoFloor spec pins that undoing past the opened baseline never
empties the document (marktext#5028 — legacy-engine bug, does not reproduce on
@muyajs/core).

muya 1536/1536, desktop 783/783, lint/tsc/madge clean. PLANS.md gains a
prioritized backlog from the full 563-item issue/PR survey.
@Jocs

Jocs commented Sep 3, 2026

Copy link
Copy Markdown
Member

I prefer close this PR, and fix conflicts in #4789

@Jocs Jocs closed this Sep 3, 2026
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.

[Bug] MarkText cannot display images on a file share, all images show up as "Load image failed"

2 participants