Skip to content

fix(export): local images render on Print/Export PDF (asset scheme + missing-image warning) (#1086) - #1088

Merged
xiaolai merged 4 commits into
mainfrom
fix/1086-export-image-asset-scheme
Jul 2, 2026
Merged

fix(export): local images render on Print/Export PDF (asset scheme + missing-image warning) (#1086)#1088
xiaolai merged 4 commits into
mainfrom
fix/1086-export-image-asset-scheme

Conversation

@xiaolai

@xiaolai xiaolai commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Closes #1086

Problem

Local images rendered in the editor but showed the "Image not found" placeholder on Export PDF / Print, even when the file existed and the path was correct.

Root cause

resolveResources classified Tauri's asset scheme https://asset.localhost/… (emitted by convertFileSrc on newer macOS/WebKit, whitelisted in the CSP and fully handled by isAssetUrl/resolveRelativePath) as remote — because it starts with https:// — and passed it through untouched before the asset-aware resolver ran. The off-screen print/PDF WKWebView has no asset:// handler, so the image never loaded. (The issue's suggested fixes #1 and #2 were already satisfied: inlining runs in the main window, and sourceFilePath is threaded through every export command.)

Fix

  • Classify asset URLs as local regardless of scheme: isRemote: isRemoteUrl(src) && !isAssetUrl(src). Scheme-agnostic — covers asset://localhost/, https://asset.localhost/, and (Windows/WebView2) http://asset.localhost/. Covers inline + block images, single (PDF/Print) and folder (HTML) modes.
  • Surface missing images instead of the silent placeholder (issue fix refactor(tiptap): improve API usage and type safety #3): both Print and Export PDF now log each offending path and raise a count toast (exportImageWarning, added to all 10 locales) via warnMissingResources.
  • Unify the image-preview popup's relative-path detection on the shared mediaSecurity predicates + validateImagePath guard (issue fix refactor(popup): consolidate shared popup code and fix silent catches #4), so bare relative paths preview consistently with how they render inline.

Testing

TDD (RED→GREEN) regression tests for asset-URL inlining across schemes/modes and bare-relative / traversal handling in the preview. Full pnpm check:all green on the merge of this branch + #1087 (one unrelated flaky content-server watcher test needed a re-run).

xiaolai added 4 commits July 2, 2026 09:40
Local images rendered in the editor but showed a missing image on
Export PDF / Print. resolveResources classified Tauri's asset scheme
`https://asset.localhost/…` (emitted by convertFileSrc on newer
macOS/WebKit and Windows, whitelisted in the CSP) as a remote URL
because it starts with `https://`, and passed it through untouched —
before the asset-aware resolveRelativePath ever ran. The off-screen
print/PDF WKWebView has no asset:// handler, so the image never loaded.

Classify asset URLs as local regardless of scheme
(`isRemoteUrl(src) && !isAssetUrl(src)`) so they are inlined (single
mode) or copied (folder mode). Scheme-agnostic: covers both
`asset://localhost/` and `https://asset.localhost/`.

Also unify the image-preview popup's relative-path detection on the
shared mediaSecurity predicates (was a narrower local copy accepting
only `./` and `assets/`) and add the editor NodeView's validateImagePath
traversal guard, so a bare relative path like `evidence/page-1.png`
previews consistently with how it renders inline.

Regression tests cover asset-URL inlining/copying in both modes and
bare-relative / parent-traversal handling in the preview popup.
Images that resolveResources can't inline are swapped for the "Image
not found" placeholder in the print/PDF output. That substitution was
silent (dev-only exportWarn). Log every offending path and raise a
single count toast from both exportToPdfBrowser (Print) and
exportToPdfNative (Export PDF) so the user knows the output is missing
images. Adds exportImageWarning_one/_other across all 10 locales.
…1086)

Cross-model audit (Codex) found isAssetUrl() missed the http://asset.localhost/
scheme that Tauri's convertFileSrc emits on Windows/WebView2. Without it, a
Windows asset image URL stayed classified as remote (starts with http://) and
passed through untouched instead of being inlined — the same missing-image bug
the fix targets, on Windows. Add the http variant so asset classification is
complete across platforms; no macOS impact.
The missing-image warning + asset-scheme changes pushed
useExportOperations.ts and resourceResolver.ts past their frozen
check:all file-size baselines. Extract warnMissingResources into
exportResourceWarnings.ts, collapse the resolveResources call-site object
literals, fold the two asset.localhost checks into one regex, and tighten
comments. No behavior change; all export tests still green.
@xiaolai
xiaolai enabled auto-merge July 2, 2026 03:15
@xiaolai
xiaolai merged commit 16ab69e into main Jul 2, 2026
7 checks passed
@xiaolai
xiaolai deleted the fix/1086-export-image-asset-scheme branch July 2, 2026 03:25
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.

Local images show "Image not found" on Export PDF / Print (asset:// display scope vs fs.readFile export scope mismatch)

1 participant