Skip to content

fix(mobile): show workspace images in session Markdown tabs - #36970

Merged
AmoabaKelvin merged 6 commits into
mainfrom
mobile-markdown-tab-images-36332
Nov 1, 2026
Merged

AmoabaKelvin merged 6 commits into
mainfrom
mobile-markdown-tab-images-36332

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​44 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​106 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​94

ELI5

When you open a Markdown file as a tab on the phone, pictures saved next to it in the project now show up. Before, each one was a broken-image icon.

What Changed

Before: in the phone's session view, a Markdown tab with ![Diagram](images/diagram.png) showed a broken image. The same file opened from the file explorer showed the picture.

After: the session tab shows the picture too.

How it works: the rich Markdown editor runs inside the mobile web page, and it wrote the Markdown path straight into <img src>. The page then looked for images/diagram.png on its own origin and got a 404. Now an image whose path is a workspace file (as the shared routeMarkdownHref router decides) is rendered with the path in data-workspace-path and no src. The editor then asks the page for a source through a new loadImageSource seam. The session tab answers with loadMarkdownPreviewImage, the files.readPreview loader the file-explorer preview already uses, resolved against the tab's relativePath. Saving reads data-workspace-path before src, so the file keeps images/diagram.png and never gets a data URI.

Loads are cached per render. An image that comes back through undo or paste gets its source from the cache with no new request. Remote, data: and blob: images still use src directly, as before.

Why

The file-explorer preview already loads workspace images safely: paths stay inside the workspace, only image types are read, and it works with SSH and folder workspaces. Reusing that loader gives the session tab the same rules with no second copy. Showing the tab through the read-only preview instead would have taken away in-place editing, which is what this tab is for.

Linked Issue

Fixes #36332

Visual Proof

Mobile web bundle on the session route (390×844). A shell double answers session.tabs.list, markdown.readTab and files.readPreview for docs/NOTES.md, which contains ![Diagram](images/diagram.png).

Before (main) After
before.png after.png

On main, the page fetched images/diagram.png from its own origin (404) and sent no files.readPreview. With the fix, it sends one files.readPreview for docs/images/diagram.png and draws the image. An inline data: image in the same file still renders directly.

Testing

  • Reproduced on main and verified the fix with the mobile web render harness in headless Chromium (macOS). Results above.

  • New document-level tests: a workspace image loads through the host and saves back as its Markdown path, while a remote image keeps src. An image brought back by an edit reuses the load. Both fail without the fix.

  • New loader test: a document outside the workspace (an external-file tab with an absolute path) reads no workspace images.

  • Ran the focused mobile suites (rich-markdown, files, session Markdown reader, RPC recordings), mobile typecheck, tests typecheck, oxlint/oxfmt on changed files, and the changed-code quality and React Doctor gates.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Codex and a Claude reviewer reviewed it over three rounds. Fixed from review: images restored by undo or paste stayed blank, a whitespace-padded or entity-encoded scheme URL was treated as a workspace path, a required prop broke the tests typecheck, the loader ref is now updated in a layout effect, and external-file tabs could resolve images to a wrong in-workspace path.

Declined:

  • Retrying failed loads on every edit, because a missing image would then send an RPC on every keystroke. A failed path retries on the next render (content change, discard, reopening the tab). An in-editor retry control is a possible follow-up.
  • Toolbar Image insert with a relative path, and image destinations with a "title" or <angle brackets>, behave as they did before. These are existing limits of the parser and the command, and links have them too.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: image reads go through the existing loader. It rejects absolute paths, Windows drive paths, NUL bytes, .. escapes and absolute document paths, and reads only image or SVG types. The result goes into <img> as a data URI, which the shell CSP already allows (img-src data:).
  • SSH/remote and folder workspaces: same client and worktreeId as markdown.readTab, so the host routes the read like the file preview.
  • Mixed versions: no new RPC or wire field. Hosts without files.readPreview leave the image unloaded, as the file preview does.
  • Cross-platform: page-side only. Windows-style paths are handled by the shared path helpers.
  • Performance: an image is loaded once per render. Edits only check for images that have no source yet.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2ca9b614-967d-4b08-a6d0-75155f2bc9c5
Commits

Reviewing files that changed from the base of the PR and between 0c98371 and 2c7345c.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0589b504-7612-4a30-a575-30628cd9b185
Commits

Reviewing files that changed from the base of the PR and between 77e287a and 0c98371.

Files selected for processing: 1
  • config/scripts/mobile-web-app/mobile-web-app-code-block-selection.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Walkthrough

The mobile Markdown editor now loads workspace-relative images through an optional image-source callback. Markdown rendering preserves workspace paths, and the editor caches image-load promises by path. The active session provides the callback through the preview-image loader. That loader rejects absolute-like or NUL-containing image and document paths.

Severity of issue fixed: Medium

Merge Risk: Low · previous review 0c983

Images inserted through the toolbar may remain broken during mobile editing, leaving a narrow gap in the intended workspace-image behavior.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: displaying workspace images in mobile session Markdown tabs.
Description check Passed The description is complete and covers the user impact, implementation, rationale, linked issue, visual proof, testing, security, compatibility, performance, and checklist items. The full repository-w…
Linked Issues check Passed Issue #36332 requires workspace-relative images to render in mobile session Markdown tabs. The PR routes workspace image paths through data-workspace-path, loads them with loadMarkdownPreviewImage…
Out of Scope Changes check Passed The changes remain within the image-rendering fix for session Markdown tabs. The editor seam, source cache, serialization update, workspace path checks, session wiring, test updates, and selection fix…
Full details: Description check

Explanation

The description is complete and covers the user impact, implementation, rationale, linked issue, visual proof, testing, security, compatibility, performance, and checklist items. The full repository-wide command checklist is not marked complete, but focused validation and automated coverage are documented, so this is acceptable.

Full details: Linked Issues check

Explanation

Issue #36332 requires workspace-relative images to render in mobile session Markdown tabs. The PR routes workspace image paths through data-workspace-path, loads them with loadMarkdownPreviewImage relative to the active tab, and preserves the Markdown path when saving. Tests cover workspace-image loading, path preservation, edit restoration, and external-file rejection. Remote images retain direct src handling.

Full details: Out of Scope Changes check

Explanation

The changes remain within the image-rendering fix for session Markdown tabs. The editor seam, source cache, serialization update, workspace path checks, session wiring, test updates, and selection fixture support the linked issue or protect existing behavior. No unrelated product change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 13 functions across 13 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e0a806ff-327a-49a9-9cc4-03f26d0b5346
Commits

Reviewing files that changed from the base of the PR and between 4ee788a and 77e287a.

Files selected for processing: 12
  • mobile/src/components/MobileRichMarkdownEditor.tsx
  • mobile/src/components/rich-markdown/document-host-seams.ts
  • mobile/src/components/rich-markdown/document-scope.ts
  • mobile/src/components/rich-markdown/editor-content.test.ts
  • mobile/src/components/rich-markdown/editor-content.ts
  • mobile/src/components/rich-markdown/html-inline-markdown.ts
  • mobile/src/components/rich-markdown/markdown-inline-render.ts
  • mobile/src/components/rich-markdown/rich-markdown-web-document-mount.ts
  • mobile/src/files/mobile-markdown-image-source.test.ts
  • mobile/src/files/mobile-markdown-image-source.ts
  • mobile/src/session/MobileSessionActiveContent.tsx
  • mobile/src/session/MobileSessionMarkdownReader.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

Comment on lines +76 to +77
editorElement(scope)
.querySelectorAll<HTMLImageElement>(`img[${WORKSPACE_IMAGE_PATH_ATTRIBUTE}]:not([src])`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Load workspace paths inserted through the Image toolbar.

When a user enters images/diagram.png in the Image toolbar, insertImage creates an <img> with src. This selector skips that image, so the workspace loader does not run. The controller accepts the emitted Markdown without an immediate re-render; the image remains broken during editing. Classify relative src values and move them to data-workspace-path before loading. Add a test that inserts an image through the toolbar, rather than constructing an image that already has data-workspace-path. (raw.githubusercontent.com)

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]: Mobile session Markdown tabs show broken images for workspace-relative paths

1 participant