Repository navigation
Conversation
The markdown editor document runs in a WebView whose origin is a placeholder host, so a relative  resolved against it and rendered as a broken image. Nothing on mobile resolved those paths to file content. The session now scans a loaded markdown doc for relative image srcs, resolves each against the doc's worktree-relative directory, and reads the bytes over the same files.readPreview a file tab's image doc uses. The data URLs reach the editor through a new setImageSources host command that swaps only the display src; the authored src rides in data-orca-src and serialization reads that, so a displayed image never round-trips its data URL into the saved file. Missing or unreadable images stay the broken glyph they already were, and the doc publishes before the image reads settle, so a slow image never delays the document. (cherry picked from commit 1268466)
Keep dupi's repository-relative image design and authored Markdown attrs. Scope async image replies to the document's initial map so reload, close, local edits and Save cannot attach stale bytes or drop current images. Reuse the shared staged raster probe and preview ceilings: two reads at a time, admission in source order, a 4 MiB UTF-8 map JSON budget and 32 Mi aggregate known raster pixels. Unknown raster headers consume the full pixel allowance; over-budget images retain their authored placeholders. Restore authored display paths when maps clear, reuse entity decoding, and refresh only the affected document-state recorder goldens. Based on dupi's diagnosis and preserved commit from PR #24469.
There was a problem hiding this comment.
Caution
This PR's headline behavior does not work on the native app. The native WebView transport wraps the image map in an extra JavaScript string literal, so the document receives a string where setImageSources expects a Record<string, string>, and no relative image ever gets its display URL. The browser build (.web.tsx) passes the object directly, so the Chromium-based proof screenshots and the bundle test both miss it.
Reviewed changes
- Display/authored split —
<img data-orca-src>carries the authored path,applyImageSourcesswaps onlysrc, andhtml-inline-markdownserializesdata-orca-src ?? srcso Save keeps the original path. - Host reads — new
markdown-relative-image-srcs.tscollects relative inline image tokens, resolves them against the document directory, and reads previews two at a time under a 4 MiB map budget and an aggregate 32 Mi-pixel budget;readRasterImagePreviewDimensionsis extracted for reuse. - Ownership —
readMarkdownTabpublishes text first and patchesimageSourcesonly while it owns the document; Save preserves the map; tests cover edit/close/reload/save races. - Seam —
setImageSourcesis threaded through the contract, both host components, the document bundle, the controller, andMobileMarkdownReader.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| setImageSources: (sources: Record<string, string>) => | ||
| inject( | ||
| `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${escapeInjectedJavaScriptString(JSON.stringify(sources))});` |
There was a problem hiding this comment.
escapeInjectedJavaScriptString(JSON.stringify(sources)) double-encodes: the argument that reaches window.__orcaRichMarkdown.setImageSources is a string, but the bundle's API is typed Record<string, string> and applyImageSources indexes it (sources[authored] → undefined), so the authored src is left in place and the image stays broken on device. The .web.tsx sibling passes the object directly, and native-document-bundle.test.ts calls handle.setImageSources({...}) on the evaluated handle — both bypass this transport, which is why nothing caught it.
Technical details
# Native image-source transport passes a string, not the map
## Affected sites
- `mobile/src/components/MobileRichMarkdownEditor.tsx:73-75` — injects `escapeInjectedJavaScriptString(JSON.stringify(sources))`, yielding `setImageSources("{\"a\":\"b\"}")`; the runtime argument is a string.
- `mobile/src/components/MobileRichMarkdownEditor.web.tsx:100-103` — correct: `api.setImageSources(sources)` with the object.
- `mobile/src/components/rich-markdown/native-document-entry.ts:14` — `window.__orcaRichMarkdown = createRichMarkdownEditorDocument().send`, so `setImageSources` is the object-typed method with no parsing.
- `mobile/src/components/rich-markdown/native-document-bundle.test.ts:101-117` — exercises the handle directly rather than the `inject` transport, so it does not cover the broken path.
## Required outcome
- The injected call must hand the document an object (e.g. inject the JSON as a JS object literal, or have the bundle parse a JSON string — the former matches the existing `RichMarkdownEditorApi` type and the web sibling).
- Add a test that drives the real transport (`inject`) end to end, not just the handle, so this cannot regress.
## Verification
- Repro with a happy-dom test evaluating `RICH_MARKDOWN_EDITOR_DOCUMENT_SCRIPT` and injecting the transport's exact expression: `img.src` stayed `docs/a.png` instead of the data URL.| setImageSources: (sources: Record<string, string>) => | |
| inject( | |
| `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${escapeInjectedJavaScriptString(JSON.stringify(sources))});` | |
| setImageSources: (sources: Record<string, string>) => | |
| inject( | |
| `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${JSON.stringify(sources)});` | |
| ) |
| }) | ||
| : prev | ||
| ) | ||
| resolveMarkdownImages(tab.id, tab.relativePath, result.content, imageSources) |
There was a problem hiding this comment.
resolveMarkdownImages runs even when the ownership guard above returned prev (superseded or closed read), so a stale read still fires its files.readPreview requests. With a refresh/retry while a resolution is pending, more than MAX_CONCURRENT_IMAGE_READS (2) reads can be in flight for one tab — the result is discarded by the owner check, so it is only wasted host work, not a wrong map. Gating the call on the read that actually published (or cancelling superseded reads) would keep the per-document bound the constant's comment claims.
Render standalone embedded images in Markdown file previews and open them in the existing full-screen viewer. Resolve relative paths through authorized paired-host reads. Thanks to @dudupii for reporting and diagnosing #24468 and implementing the broader solution in #24469; related editor integration is preserved in #25594. This independently implemented preview fix leaves editor image serialization, inline images, and pinch zoom as separate work. Validation: focused tests, iPhone simulator proof, and all CI checks passed.

ELI5
Pictures beside a Markdown file appeared as broken placeholders on mobile. The editor can now read them from the paired host while keeping the original paths in the document.
What Changed
Preserves dupi’s authored implementation from #24469: existing
files.readPreviewreads supply display data URLs to the native and web editor documents.data-orca-srcretains each authored path for serialization. Text appears before the image reads finish.The follow-up keeps replies owned by the current document across edits and Save, drops replies after close/reload, restores authored paths when a display map clears, and reuses the editor’s entity decoder. Reads run two at a time; admission follows source order, with a 4 MiB UTF-8 display-map JSON budget and 32 Mi aggregate known raster pixels. The existing staged header probe is exposed for reuse, with its prior oversized-image verdict preserved.
Why
This reuses the checked image-file operation, host authorization, and current document engine. It avoids a second file service/cache or rewriting Markdown with embedded image bytes. The source/display distinction was checked against Orca’s desktop image node view, Tiptap Image 3.31.3, and ProseMirror View 1.42.3. Mobile continues to use its existing editor engine; no library code changes.
Credit to dupi (@dudupii) for the report, diagnosis and implementation. Original commit
1268466ef29099038eb180cf79ff703ed09636b0is preserved as an authored cherry-pick. This branch is based on the reviewed #25540 support ancestor; its diff shows only this image work.Linked Issue
Addresses #24468. Device acceptance remains open; no automatic issue closure.
Visual Proof
Actual generated native editor document in hidden Chromium over CDP, at its placeholder origin. Controlled PNG fixtures are solid rectangles. The after images use bytes obtained by the production mobile client over an authenticated, encrypted WebSocket to an owned compiled Orca host. Before: 0×0 relative images. After: 160×72 and 100×40. Remote/data decoder controls and authored Markdown are unchanged.
Testing
pnpm tc, full lint and changed-code quality; mobile typecheck, lint and test typecheck ratchet; fresh native generators, Electron e2e build and verified mobile web bundle.MobileMarkdownReadercomplexity warning; that component’s sole change is the image-map prop. The repository quality gate reports zero new React Doctor findings.Red tests reproduced stale replies, map loss on Save/clear, entity-key mismatch, excessive concurrent reads and aggregate retention. The seven affected recorder goldens were regenerated through the existing recorder; all 1,594 recorder controls pass. Shared probe controls preserve late JPEG headers, truncated/unknown headers and invalid oversized payload behavior.
Review
Risk: low to medium. No physical Android/iOS device, native Expo runtime, native Windows/Linux, or live SSH acceptance was performed. Existing SSH-provider preview-budget tests pass; reads still execute on the host through the existing operation, without wire/CSP changes.
The current inline-image grammar is retained: reference images, titles and parentheses in paths are not newly supported. The scan includes code-example tokens, which can consume the first-24-source cap. Leading
/means workspace-rooted, without desktop absolute-path parity. Exact repeated tokens share a read; distinct spellings of one path may read twice.Images beyond the count/byte/pixel budget remain placeholders. Unknown raster headers consume the entire pixel allowance and can omit later valid images. The pixel budget covers known dimensions; it is not a strict decoded-memory cap for SVG, animation frames or unknown headers. Each two-image batch waits for both reads before admission, so a slow sibling can delay image display while text remains usable. The fixture retained 584 display-string bytes / 636 complete map JSON bytes and 15,520 known raster pixels per document; browser/native copies and decoder allocations are additional.
Agent skill upstream boundary
Checklist