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.
|
| ), | ||
| setImageSources: (sources: Record<string, string>) => | ||
| inject( | ||
| `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${escapeInjectedJavaScriptString(JSON.stringify(sources))});` |
There was a problem hiding this comment.
Native image map becomes a string When a Markdown document opens on the phone,
escapeInjectedJavaScriptString stringifies the already-stringified image map. The editor receives a string instead of an object, so it cannot look up any image paths and repository-relative images remain broken.
| `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${escapeInjectedJavaScriptString(JSON.stringify(sources))});` | |
| `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(JSON.parse(${escapeInjectedJavaScriptString(JSON.stringify(sources))}));` |
| setMarkdownDocs((prev) => { | ||
| const doc = prev.get(tabId) | ||
| if (!doc || doc.status !== 'ready') { | ||
| return prev | ||
| } | ||
| return new Map(prev).set(tabId, { ...doc, imageSources }) |
There was a problem hiding this comment.
| await Promise.all( | ||
| collectMarkdownImageSrcs(content) | ||
| .slice(0, MAX_RESOLVED_IMAGE_SRCS) |
There was a problem hiding this comment.
Code examples use image slots The 24-image limit is applied to matches in raw Markdown, including image syntax inside fenced or inline code that the editor never renders as an image. If 24 such examples appear before a real image, that image is skipped and remains broken despite its file being available.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 6ee47b68-ef06-4746-8c96-c10663c1e976
📒 Files selected for processing (19)
mobile/src/components/MobileRichMarkdownEditor.tsxmobile/src/components/MobileRichMarkdownEditor.web.tsxmobile/src/components/mobile-rich-markdown-editor-contract.tsmobile/src/components/rich-markdown/create-rich-markdown-editor-document.tsmobile/src/components/rich-markdown/document-host-seams.tsmobile/src/components/rich-markdown/document-scope.tsmobile/src/components/rich-markdown/editor-content.tsmobile/src/components/rich-markdown/editor-image-sources.test.tsmobile/src/components/rich-markdown/editor-image-sources.tsmobile/src/components/rich-markdown/html-inline-markdown.tsmobile/src/components/rich-markdown/markdown-inline-render.tsmobile/src/components/rich-markdown/native-document-bundle.test.tsmobile/src/components/use-mobile-rich-markdown-editor-controller.tsmobile/src/session/MobileMarkdownReader.tsxmobile/src/session/markdown-relative-image-srcs.test.tsmobile/src/session/markdown-relative-image-srcs.tsmobile/src/session/mobile-session-route-types.tsmobile/src/session/use-mobile-session-document-readers.test.tsmobile/src/session/use-mobile-session-document-readers.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| setImageSources: (sources: Record<string, string>) => | ||
| inject( | ||
| `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${escapeInjectedJavaScriptString(JSON.stringify(sources))});` |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Check whether the WebView handle (host bridge) parses string arguments before calling setImageSources.
rg -n -C5 'setImageSources|__orcaRichMarkdown' mobile/src/components/rich-markdownRepository: stablyai/orca
Length of output: 17528
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- changed file ---'
cat -n mobile/src/components/MobileRichMarkdownEditor.tsx | sed -n '1,125p'
printf '%s\n' '--- escape helper references/definition ---'
rg -n -C6 'escapeInjectedJavaScriptString' mobile/src
printf '%s\n' '--- host bridge and document API ---'
cat -n mobile/src/components/rich-markdown/host-bridge.ts | sed -n '1,180p'
cat -n mobile/src/components/rich-markdown/create-rich-markdown-editor-document.ts | sed -n '1,80p'
cat -n mobile/src/components/rich-markdown/editor-image-sources.ts | sed -n '1,100p'
printf '%s\n' '--- PR diff for relevant file ---'
git diff --no-ext-diff --unified=15 cb11a9ff1ae9b2c2d31e117f86ba71dd8b3271d8 1268466ef29099038eb180cf79ff703ed09636b0 -- mobile/src/components/MobileRichMarkdownEditor.tsx mobile/src/components/rich-markdownRepository: stablyai/orca
Length of output: 41618
Pass an object to setImageSources.
escapeInjectedJavaScriptString serializes its input. Passing JSON.stringify(sources) serializes the source map twice, so the document receives a string. applyImageSources then cannot find map entries, and relative images remain unresolved.
🐛 Suggested fix
- `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${escapeInjectedJavaScriptString(JSON.stringify(sources))});`
+ `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${JSON.stringify(sources).replace(/<\/script/gi, '<\\/script')});`📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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).replace(/<\/script/gi, '<\\/script')});` |
|
|
||
| // Why: relative images cannot render in the editor's WebView, and reading them is N more RPCs — | ||
| // the doc publishes first and the resolved map lands on the ready doc when the reads settle. | ||
| const resolveMarkdownImages = useCallback( | ||
| (tabId: string, relativePath: string, content: string) => { | ||
| if (!client) { | ||
| return | ||
| } | ||
| void readMarkdownImageSources(client, worktreeId, relativePath, content).then( | ||
| (imageSources) => { | ||
| if (Object.keys(imageSources).length === 0) { | ||
| return | ||
| } | ||
| setMarkdownDocs((prev) => { | ||
| const doc = prev.get(tabId) | ||
| if (!doc || doc.status !== 'ready') { | ||
| return prev | ||
| } | ||
| return new Map(prev).set(tabId, { ...doc, imageSources }) | ||
| }) | ||
| } | ||
| ) | ||
| }, | ||
| [client, setMarkdownDocs, worktreeId] | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,180p' mobile/src/session/use-mobile-session-document-readers.ts
rg -n 'readMarkdownTab|setMarkdownDocs|markdownDocs' mobile/src/sessionRepository: stablyai/orca
Length of output: 13910
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- outlines ---'
ast-grep outline mobile/src/session/use-mobile-session-terminal-webview.ts
ast-grep outline mobile/src/session/use-mobile-session-tab-switching.ts
ast-grep outline mobile/src/session/use-mobile-session-markdown-actions.ts
ast-grep outline mobile/src/session/use-mobile-session-tab-reconciliation.ts
ast-grep outline mobile/src/session/use-mobile-session-screen-state.ts
ast-grep outline mobile/src/session/use-mobile-session-tab-application.ts
printf '%s\n' '--- caller/state excerpts ---'
sed -n '1,190p' mobile/src/session/use-mobile-session-terminal-webview.ts
sed -n '1,190p' mobile/src/session/use-mobile-session-tab-switching.ts
sed -n '1,270p' mobile/src/session/use-mobile-session-markdown-actions.ts
sed -n '1,130p' mobile/src/session/use-mobile-session-tab-reconciliation.ts
sed -n '1,210p' mobile/src/session/use-mobile-session-screen-state.ts
sed -n '1,130p' mobile/src/session/use-mobile-session-tab-application.ts
printf '%s\n' '--- document types and image helper ---'
rg -n -A35 -B10 'type MarkdownDocState|interface MarkdownDocState|readMarkdownImageSources|imageSources|type MobileSessionTab' mobile/src/session mobile/src | head -n 500
printf '%s\n' '--- relevant tests ---'
sed -n '1,220p' mobile/src/session/use-mobile-session-document-readers.test.tsRepository: stablyai/orca
Length of output: 41675
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 47735
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- reconciliation and application ---'
sed -n '1,240p' mobile/src/session/use-mobile-session-tab-reconciliation.ts
sed -n '1,290p' mobile/src/session/use-mobile-session-tab-application.ts
sed -n '1,280p' mobile/src/session/use-mobile-session-screen-state.ts
printf '%s\n' '--- markdown rendering and active content ---'
sed -n '1,180p' mobile/src/session/MobileSessionActiveContent.tsx
rg -n -A80 -B20 'imageSources|Markdown.*Editor|Markdown.*Preview|markdownDocs.get|onRefresh|localContent' mobile/src/session mobile/src | head -n 600
printf '%s\n' '--- exact tab identity and read callers ---'
rg -n -A45 -B15 'readMarkdownTab\\(|switchSessionTab\\(|setSessionTabs|sessionTabs|tab.id|documentVersion|filePath|relativePath' mobile/src/session --glob '*.{ts,tsx}' | head -n 1000
printf '%s\n' '--- changed hunk and baseline comparison ---'
git diff --no-ext-diff --unified=80 cb11a9ff1ae9b2c2d31e117f86ba71dd8b3271d8..1268466ef29099038eb180cf79ff703ed09636b0 -- mobile/src/session/use-mobile-session-document-readers.tsRepository: stablyai/orca
Length of output: 41793
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- reconciliation and application ---'
sed -n '1,240p' mobile/src/session/use-mobile-session-tab-reconciliation.ts
sed -n '1,290p' mobile/src/session/use-mobile-session-tab-application.ts
sed -n '1,280p' mobile/src/session/use-mobile-session-screen-state.ts
printf '%s\n' '--- markdown rendering and active content ---'
sed -n '1,180p' mobile/src/session/MobileSessionActiveContent.tsx
rg -n -A80 -B20 'imageSources|Markdown.*Editor|Markdown.*Preview|markdownDocs.get|onRefresh|localContent' mobile/src/session mobile/src | head -n 600
printf '%s\n' '--- exact tab identity and read callers ---'
rg -n -A45 -B15 'readMarkdownTab\(|switchSessionTab\(|setSessionTabs|sessionTabs|tab.id|documentVersion|filePath|relativePath' mobile/src/session --glob '*.{ts,tsx}' | head -n 1000
printf '%s\n' '--- changed hunk and baseline comparison ---'
git diff --no-ext-diff --unified=80 cb11a9ff1ae9b2c2d31e117f86ba71dd8b3271d8..1268466ef29099038eb180cf79ff703ed09636b0 -- mobile/src/session/use-mobile-session-document-readers.tsRepository: stablyai/orca
Length of output: 42103
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- exact rendering and refresh ---'
cat -n mobile/src/session/MobileSessionMarkdownReader.tsx | sed -n '1,150p'
cat -n mobile/src/session/MobileSessionActiveContent.tsx | sed -n '90,135p'
cat -n mobile/src/session/use-mobile-session-markdown-actions.ts | sed -n '125,185p'
printf '%s\n' '--- exact clean-tab reread and active read ---'
cat -n mobile/src/session/use-mobile-session-tab-switching.ts | sed -n '110,155p'
cat -n mobile/src/session/use-mobile-session-terminal-webview.ts | sed -n '105,130p'
printf '%s\n' '--- image helper and tab identity ---'
cat -n mobile/src/session/markdown-relative-image-srcs.ts | sed -n '100,140p'
cat -n mobile/src/session/mobile-session-route-types.ts | sed -n '40,105p'Repository: stablyai/orca
Length of output: 16964
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- every imageSources reference ---'
rg -n -C5 'imageSources' mobile src --glob '*.{ts,tsx}' || true
printf '%s\n' '--- editor declaration and callers ---'
rg -n -C12 'export function MobileRichMarkdownEditor|function MobileRichMarkdownEditor|MobileRichMarkdownEditor' mobile/src --glob '*.{ts,tsx}'
printf '%s\n' '--- editor image rendering/configuration ---'
rg -n -C8 'image|markdown|resolve|data:' mobile/src/components/MobileRichMarkdownEditor* mobile/src/components --glob '*Markdown*' --glob '*.{ts,tsx}' 2>/dev/null || trueRepository: stablyai/orca
Length of output: 45665
Guard image-source publication by document generation.
readMarkdownTab can run again for the same tab while an earlier readMarkdownImageSources call is pending. The callback checks only ready status, so the earlier map can replace the newer document's map. The web editor applies this map to displayed images. Track a per-tab generation and require the captured content to match before publishing.
Suggested fix
-import { useCallback } from 'react'
+import { useCallback, useRef } from 'react'
...
const { worktreeId, client, setMarkdownDocs, setFileDocs } = scope
+ const markdownReadGenerationRef = useRef<Map<string, number>>(new Map())
...
- (tabId: string, relativePath: string, content: string) => {
+ (tabId: string, relativePath: string, content: string, generation: number) => {
...
- if (!doc || doc.status !== 'ready') {
+ if (
+ !doc ||
+ doc.status !== 'ready' ||
+ doc.content !== content ||
+ markdownReadGenerationRef.current.get(tabId) !== generation
+ ) {
return prev
}
...
if (!client) {
return
}
+ const generation = (markdownReadGenerationRef.current.get(tab.id) ?? 0) + 1
+ markdownReadGenerationRef.current.set(tab.id, generation)
setMarkdownDocs((prev) => new Map(prev).set(tab.id, { status: 'loading' }))
...
- resolveMarkdownImages(tab.id, tab.relativePath, result.content)
+ resolveMarkdownImages(tab.id, tab.relativePath, result.content, generation)
...
- resolveMarkdownImages(tab.id, tab.relativePath, fileResult.content)
+ resolveMarkdownImages(tab.id, tab.relativePath, fileResult.content, generation)There was a problem hiding this comment.
Caution
The fix does not work on native phones. MobileRichMarkdownEditor.tsx:75 double-encodes the image map into a JSON string, so the editor receives a string where it expects an object and never resolves a single relative image. Only the react-native-web sibling (which passes the object) works. The new bundle test calls the handle directly and never exercises the native transport, which is why CI is green.
Reviewed changes
Reviewed the complete 19-file diff at 1268466.
- Relative image resolution —
markdown-relative-image-srcs.tsscans a doc for non-external image srcs, resolves each against the document's directory (worktree-rooted/, rejects..climb-out, decodes escapes, strips?/#), keeps editor-renderable images (raster + SVG), and reads them throughfiles.readPreview, answering authored-src → data-URL. - Session wiring —
use-mobile-session-document-readers.tspatches the readyMarkdownDocStatewith the resolved map after the doc publishes; the route type gains an optionalimageSources. - Editor display — a new
setImageSourceshost command stores the map and re-applies it whenever the surface is rebuilt;data-orca-srckeeps the authored src so a displayed image never round-trips into the saved file. - Serialization —
html-inline-markdown.tsnow readsdata-orca-srcbeforesrc. - Tests — collection/resolution, the session patch, the editor display-slot swap and round-trip, and the bundled document driven through the injected handle.
ℹ️ Saving a Markdown tab drops its resolved image sources
saveMarkdownTab replaces the ready doc with a fresh object that omits imageSources, unlike the ...existing spreads every other update in the session uses. After a save the doc is still ready, so nothing re-runs resolveMarkdownImages; if the editor remounts (tab switch) or the surface rebuilds, relative images render broken again with no recovery path.
Technical details
# Saving loses the resolved image map
## Affected sites
- `mobile/src/session/use-mobile-session-markdown-actions.ts:193-202` (untouched by this PR) — the save-success `setMarkdownDocs` publishes `{ status, content, localContent, baseVersion, isDirty, editable }` and drops `imageSources`.
- `mobile/src/session/use-mobile-session-document-readers.ts` — `resolveMarkdownImages` only runs from `readMarkdownTab`, which is not re-invoked for an already-ready doc.
## Required outcome
- A saved document keeps its resolved `imageSources` (or transparently re-resolves them), so switching away and back does not reintroduce broken images.
## Suggested approach
- Spread `...existing` in the save-success update, or call `resolveMarkdownImages` after a successful save.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)) produces a JavaScript string literal, so the document's setImageSources receives the JSON text as a string. applyImageSources then evaluates sources[src] on that string (always undefined), so no relative image resolves on a phone. The web sibling passes the object and works, and the bundle test calls the handle directly, so neither surfaces this.
Technical details
# Native transport passes a JSON string where the document expects an object
## Affected sites
- `mobile/src/components/MobileRichMarkdownEditor.tsx:75` — double-encodes via `escapeInjectedJavaScriptString(JSON.stringify(sources))`; the injected argument evaluates to a string.
- `mobile/src/components/MobileRichMarkdownEditor.web.tsx:100-103` — passes the object directly, which is the contract `RichMarkdownEditorApi.setImageSources` declares.
- `mobile/src/components/rich-markdown/native-document-bundle.test.ts:108` — calls `handle.setImageSources({...})` directly, bypassing the native transport (unlike `setMarkdown`, which is injected at line 145).
## Required outcome
- The script injected by the native transport must evaluate to a `Record<string, string>` when it runs, matching the handle and the web transport.
## Suggested approach
- Inject the JSON as a value (`${JSON.stringify(sources)}`) instead of passing it through `escapeInjectedJavaScriptString`, and add a bundle test that drives `setImageSources` through `inject(...)`.| const sources: Record<string, string> = {} | ||
| await Promise.all( | ||
| collectMarkdownImageSrcs(content) | ||
| .slice(0, MAX_RESOLVED_IMAGE_SRCS) |
There was a problem hiding this comment.
collectMarkdownImageSrcs scans raw Markdown, so image syntax inside fenced or inline code — which the editor renders as text, not as an image — still consumes the MAX_RESOLVED_IMAGE_SRCS budget and issues a read. A document with 24 such examples before a real image leaves that real image broken even though its file is available. Consider skipping fenced/inline code when collecting.
| if (!doc || doc.status !== 'ready') { | ||
| return prev | ||
| } | ||
| return new Map(prev).set(tabId, { ...doc, imageSources }) |
There was a problem hiding this comment.
The patch only checks that the tab is ready, not that the doc still belongs to the content this read started from. A refresh or re-read can begin more image reads while an earlier read is pending, and the older map then lands on the newer doc — stale bytes for a src whose file changed. Guard on doc.content === content (or a per-read generation) before patching.
…eview The file preview rendered every image as tappable link text; the editor's data-URL resolution never reached it. The preview screen now resolves the same authored srcs over files.readPreview and renders real images: full width for standalone tokens, thumbnails inline in prose and table cells. Also mock the fork-only media handoff in the retry test, whose unconditional screen import broke the suite at collect time.
Tapping an image in the markdown file preview now pushes that image's own file-preview route, with the src resolved against the document the way the data-URL reads already resolve, so it lands in the existing pinch-zoom image viewer (1x-4x). MobileMarkdown gains an optional onOpenImage so image taps route through the document owner instead of the generic file-href opener; callers that do not pass it keep exactly the old behavior.
…editor The relative-image fix landed in MobileMarkdownReader, a component with no production consumer; the session's live file-tab editor (MobileSessionMarkdownReader) never received the resolved imageSources, so repository-relative images stayed broken in the surface users actually edit in, and tapping one did nothing. The live editor now receives the doc's imageSources, and a tap on an image reports openImage with its authored src through the WebView bridge. The session resolves the src against the markdown tab's directory — the same markdownImageTapPreviewHref the file preview uses — and pushes the image's own preview route, the existing pinch-zoom viewer. External image srcs (schemed or protocol-relative URLs) have no worktree file behind them: they route as web hrefs like before, on both the editor and the file preview, instead of pushing a bogus worktree route.
markdown-href-routing had started importing the image-srcs module for the external-src predicate, dragging the image-read RPC graph into every route that renders prose and regrouping esbuild chunks: the mobile web bundle read 74 scripts against the swept 69 + 4 margin and failed packaging on linux/mac. The predicate is one regex and stays local to each light consumer — markdown-href-routing here, editor-listeners in the WebView document — and the tapped-image href builder folds into markdown-relative-image-srcs, whose importer set already covers both routes that call it, so no new shared chunk is emitted. The sweep table is re-derived, never bumped: the bundle reads 73 scripts / 122 assets again with the fence untouched.
…form The image viewer leaned on ScrollView maximumZoomScale/centerContent, which React Native only honors on iOS — on Android the pinch did nothing at all, so a tapped markdown image opened a preview that could never zoom. Replace it with a GestureDetector pinch/pan/double-tap viewer (focal-anchored zoom, pan clamped to the grown image edge, double-tap toggling 1x/2.5x), with the transform math in a plain module the worklets bundle.
The rendered markdown and source views of a worktree file had no zoom at all, while the native chat scales its font with a pinch. Reuse the chat's pinch gesture hook here: the preview's MobileMarkdown gets the gesture's fontScale as textScale, and the source view scales its mono font from the same committed scale.
…s with the pinch The file preview's pinch gesture only reached paragraph and list text: table cells, headings, quotes, code blocks, and list markers kept their base size, and inline image thumbnails stayed fixed. textScale now covers every text block in MobileMarkdown and threads the same multiplier into MarkdownInlineImage, so a pinched document grows as one — including table text and images inside table cells. Tapping any image still opens the full-screen zoomable viewer.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
mobile/src/components/MobileRichMarkdownEditor.tsx (1)
74-77: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winPass the source map as an object, not as a JSON string literal.
escapeInjectedJavaScriptString(JSON.stringify(sources))produces a JavaScript string literal. The document'ssetImageSourcestherefore receives a string. Lookups on that string returnundefined, so no relative image resolves in the native WebView. The web transport passes the object directly, and the bundle test calls the handle directly, so neither path shows this failure.🐛 Proposed fix
- `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${escapeInjectedJavaScriptString(JSON.stringify(sources))});` + `window.__orcaRichMarkdown && window.__orcaRichMarkdown.setImageSources(${JSON.stringify(sources).replace(/</g, '\\u003c').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029')});`
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7b6170eb-f881-466b-b58b-50081226f1b7
📒 Files selected for processing (31)
mobile/src/components/MobileMarkdown.file-links.test.tsmobile/src/components/MobileMarkdown.text-scale.test.tsxmobile/src/components/MobileMarkdown.tsxmobile/src/components/MobileRichMarkdownEditor.tsxmobile/src/components/MobileRichMarkdownEditor.web.tsxmobile/src/components/markdown-href-routing.test.tsmobile/src/components/markdown-href-routing.tsmobile/src/components/markdown-image-view.tsxmobile/src/components/mobile-markdown-styles.tsmobile/src/components/mobile-rich-markdown-editor-contract.tsmobile/src/components/rich-markdown/editor-listeners.tsmobile/src/components/rich-markdown/native-document-bundle.test.tsmobile/src/components/use-mobile-rich-markdown-editor-controller.tsmobile/src/files/MobileFileMarkdownPreview.test.tsmobile/src/files/MobileFileMarkdownPreview.tsxmobile/src/files/MobileFilePreviewBody.tsxmobile/src/files/MobileFilePreviewScreen.tsxmobile/src/files/MobileFilePreviewSourceText.tsxmobile/src/files/MobileZoomableImage.test.tsxmobile/src/files/MobileZoomableImage.tsxmobile/src/files/mobile-file-preview-markdown-images.test.tsxmobile/src/files/mobile-file-preview-retry.test.tsxmobile/src/files/mobile-file-preview-styles.tsmobile/src/files/zoomable-image-transform.test.tsmobile/src/files/zoomable-image-transform.tsmobile/src/session/MobileSessionActiveContent.tsxmobile/src/session/MobileSessionMarkdownReader.test.tsxmobile/src/session/MobileSessionMarkdownReader.tsxmobile/src/session/markdown-relative-image-srcs.test.tsmobile/src/session/markdown-relative-image-srcs.tsmobile/src/session/use-mobile-session-file-actions.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
upstream main moved 615 commits past the PR's fork base; the one textual conflict (MobileMarkdown.tsx) keeps both upstream's android transcript long-press forwarding and this branch's pinch text scaling.
…kdown The upstream merge brought the android transcript long-press forwarding into the same file as the pinch text scaling, pushing MobileMarkdown.tsx past the 400-line oxlint cap. The cap is not disabled or bumped: the context-backed MarkdownText moves to markdown-text.tsx and the inline token renderer to markdown-inline-render.tsx, leaving the block renderer in MobileMarkdown.tsx. The text-scale test's react-native mock gains the Platform member the shared inline-text-selection import reads.
Keeps upstream's orca-visual directive blocks, useMobileMarkdownBlocks hook, and media preview kind alongside this branch's pinch text scaling, resolved image sources, and zoomable image viewer.
The upstream merge puts MobileFileMediaPreview in the preview body's import graph; without the mock its expo-file-system dependency breaks collection (__DEV__ is not defined). Replaces the phantom MobileFileMediaHandoff mock the cherry-pick carried over from the fork branch, which never resolved on this branch.
…-relative-images # Conflicts: # mobile/src/components/markdown-href-routing.test.ts
…-relative-images # Conflicts: # mobile/src/session/MobileSessionMarkdownReader.test.tsx
- session-markdown-source-copy probe renders MarkdownReader with the onOpenImage prop this PR adds as required - replace upstream's 'as never' type assertions and hoisted-seam casts with String(node.type) comparisons and return-type annotations so the changed-lines casting gate stays clean
…-relative-images # Conflicts: # mobile/src/files/MobileFilePreviewBody.tsx # mobile/src/session/MobileSessionMarkdownReader.test.tsx
…-relative-images # Conflicts: # mobile/src/components/MobileMarkdown.tsx
…-relative-images # Conflicts: # .github/scripts/check-required-pr-context.mjs
nwparker
left a comment
There was a problem hiding this comment.
Scope review and cross-reference for #24468: I compared this patch's paired-host files.readPreview reads, authored data-orca-src preservation, inline/block image rendering, file-preview wiring, and zoom changes with #31304. Thank you @dudupii for the report, diagnosis, implementation, and device evidence.
#31304 is the narrower standalone-image fix for the read-only file preview and reuses the existing full-screen viewer. It does not replace this PR's rich-editor serialization, inline-image, or pinch-zoom work. #25594 also preserves your authored editor implementation. Credit and these scope links have been added to #31304; #24468 will remain open for the broader editor scope. This is a code/scope comparison, not a claim that I ran this branch's device tests.
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 referenced by a Markdown file (like a screenshot next to the text it explains) showed up as broken placeholders on the phone. The phone now reads those picture files and shows them inside the document — in the file preview and in the editor. Tapping a picture opens it full-screen, where a pinch zooms it in and out. And pinching the document itself now grows its text — including table text and code, which used to stay tiny.
What Changed
1. Relative images render in the markdown file preview.
Before: every
in a worktree Markdown file rendered as tappable text with the path — no picture. After: once the document renders, the preview scans it for relative image srcs, resolves each against the document's directory, and reads the bytes over the samefiles.readPreviewa file tab's image doc already uses. Resolved images render in place — standalone images full width with their real aspect ratio, inline images as fixed thumbnails. The document publishes first and images attach as each read settles, so a slow image never delays text; a missing or unreadable image stays the tappable fallback it already was.2. Tapping a markdown image opens a full-screen zoomable viewer.
A tap on any image (block, inline, or in the fallback) pushes the image-viewer route the file tab already uses. That viewer gains
react-native-gesture-handlerpinch/pan, so zooming works identically on Android, iOS, and web instead of one platform's built-in gesture.3. A pinch scales the file preview's rendered text.
Before: the rendered markdown and source views of a worktree file had no zoom at all, while native chat scales its font with a pinch. After: the preview reuses the chat's pinch gesture hook — the rendered document grows as one (paragraphs, lists, headings, quotes, code, table cells, and inline image thumbnails share the same multiplier), and the source view scales its mono font from the same committed scale.
4. The editor (this PR's original commit) resolves relative images inside the WebView.
The editor document is a WebView served from a placeholder origin, so a relative src resolved against a host that cannot serve anything. When the document loads, the session scans it for relative image srcs, resolves each against the document's worktree-relative directory, reads the bytes over the same
files.readPreview, and delivers the resulting data URLs through a newsetImageSourceshost command. Display and storage stay apart: the rendered<img>carries the authored src indata-orca-src, the host swaps only the displaysrc, and serialization readsdata-orca-src— so a displayed image never round-trips its data URL into the saved file. Editor images open the same zoomable viewer on tap.One internal fix rides along:
markdown-href-routinghad started importing the image-srcs module, dragging the image-read RPC graph into every route that renders prose and regrouping esbuild chunks past the mobile web bundle's fenced asset count (packaging failed on linux/mac). The one-regex predicate stays local to each light consumer instead; the fence's sweep table is re-derived from the new layout, never widened, and the bundle is back inside it (73 scripts / 122 assets).Why
files.readPreview(already in the mobile allowlist for image file tabs), so no host-side or wire changes: an older paired desktop serves these reads today.data-orca-srcrather than rewriting the markdown: the editor serializes<img>back tofrom the live DOM, so swappingsrcin place would corrupt the file on save.<img>even though the shared file-tab classifier excludes it (RN<Image>cannot decode SVG; a WebView<img>can, and never scripts it as an image subresource).react-native-gesture-handleris already a dependency, so the cross-platform viewer zoom adds none.Linked Issue
Fixes #24468
Visual Proof
BEFORE: images in a Markdown document render as broken placeholders.
BEFORE (pinch, tables): the document is pinched — body text grows, but table text stays at its base size.
AFTER (pinch, tables): the same document pinched further — table text now scales with the prose (device acceptance on a fork build of this branch's commits).
Testing
AI Disclosure
Implemented by the fork maintainer (dupi).
Review
<img>display slot, andisSafeUrlstill gates what renders at allreact-native-gesture-handler(already shipped); paths are worktree-relative repo paths, no platform branchesAgent skill upstream boundary
Checklist