Bug: Images are not displayed in md pages #69
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_os#69
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Images referenced with absolute paths (e.g. /img/vdc.png) in markdown content don't render when the Books UI is embedded inside hero_os via iframe.
They display correctly when hero_books runs standalone, and PDF rendering works in both modes.
Environment
Reproduction
Root cause
Absolute image URLs like /img/vdc.png are resolved against the iframe's host origin (hero_os at :8080), not the hero_books origin.
Bug: Images are not displayed in md displayto Bug: Images are not displayed in md pagesImplementation Spec
Objective
Fix broken image rendering for absolute URLs (e.g.
/img/foo.png) in markdown pages when hero_books is embedded inside hero_os via the/hero_books/ui/proxy. Standalone mode must remain unaffected.Root cause confirmation
Absolute image URLs are resolved against the iframe's host origin (hero_os), where no
/img/...route exists. They must be rewritten to include the proxy prefix (/hero_books/img/...) so the hero_os router forwards them to the hero_books backend.Approach
Rewrite image URLs at two layers — server-side (for SSR HTML) and client-side (for content rendered by the Dioxus WASM app via RPC).
Files to Modify (in
lhumina_code/hero_books)crates/hero_books_ui/src/handlers.rs— server-side image URL rewritercrates/hero_books_app/src/components/library.rs— client-side asset URL rewriter helper + apply to markdown outputcrates/hero_books_app/src/components/page.rs— apply rewriter to server-renderedcontent_htmlImplementation Plan
Step 1: Server-side rewrite (
handlers.rs)rewrite_image_urls(html)→rewrite_image_urls(html, base).http://,https://, anddata:URIs./: prefix withbasewhen non-empty and not already prefixed → e.g./img/foo.png→/hero_books/img/foo.png.{base}/img/{filename}instead of hard-coded/img/{filename}.markdown_to_html(md)→markdown_to_html(md, base)to threadbasethrough.handler_pageto pass&baseinto both branches (pre-renderedcontentHtmland freshly rendered markdown).Step 2: Client-side helper (
library.rs)pub fn rewrite_asset_urls(html: &str) -> Stringthat:rpc::base_path()(e.g./hero_books/uiwhen embedded;""standalone)./uito derive the asset base (e.g./hero_books).src="/img/→src="{asset_base}/img/.markdown_to_htmlso client-rendered markdown also benefits.Step 3: Page view (
page.rs)PageView, when renderingcontent_html(server-rendered HTML received via RPC), pass it throughsuper::library::rewrite_asset_urls(...)so absolute image URLs get the proxy prefix client-side too.Acceptance Criteria
/img/foo.png) render correctly when hero_books is embedded in hero_os at/hero_books/ui/.{base}/img/{filename}.http://,https://) anddata:image URIs are not modified.cargo build --release --workspacesucceeds.Notes
lhumina_code/hero_books(the actual code change is in the books repo, not hero_os).X-Forwarded-Prefixrequest header (set by the hero_os proxy).rpc::set_rpc_base("/hero_books/ui")fromapp.rswhen anIslandContextis present.Build & Test Results
Build
cargo build --release -p hero_books_ui -p hero_books_app— succeeded (Finished release profile in 2m 07s).Tests
cargo test --release -p hero_books_ui -p hero_books_app— passedNotes
crates/hero_books_app/src/components/pdf_viewer.rs:4— unrelated to this change.Implementation Summary
The fix is implemented in the
lhumina_code/hero_booksrepository on branchdevelopment_fix_image_urls_proxy. PR will be opened againstlhumina_code/hero_books:development.Files changed (3)
crates/hero_books_ui/src/handlers.rs— server-side:rewrite_image_urls(html, base)now prefixes absolute paths with the proxy base derived fromX-Forwarded-Prefix;markdown_to_html(md, base)threads the base through;handler_pagepasses&baseinto both branches.crates/hero_books_app/src/components/library.rs— client-side: newrewrite_asset_urls(html)helper readsrpc::base_path(), strips trailing/uito get the asset base, rewritessrc="/img/...→src="{asset_base}/img/.... Returns input unchanged in standalone mode. Applied tomarkdown_to_htmloutput.crates/hero_books_app/src/components/page.rs— client-side:PageViewnow passes server-renderedcontent_htmlthroughrewrite_asset_urls()so absolute image URLs in pre-rendered HTML are also corrected.Behavioural matrix
/img/foo.pngworks/img/foo.pngstill works (no rewrite)/hero_books/ui//img/foo.png404s against hero_os origin/img/foo.png→/hero_books/img/foo.png→ proxied to books backendhttp://,https://)data:URIs/hero_books/img/x)Verification
cargo build --release -p hero_books_ui -p hero_books_app— passes.cargo test --release -p hero_books_ui -p hero_books_app— passes (no failures).Caveats
/hero_books/uiincrates/hero_books_app/src/app.rs:94(when anIslandContextis present). If hero_os ever mounts the books app under a different prefix, that constant would need to be updated. The server-side path is dynamic viaX-Forwarded-Prefixand is robust.PR opened in
lhumina_code/hero_books: lhumina_code/hero_books#90This PR implements the image URL rewriting fix discussed in this issue. It is targeted at
lhumina_code/hero_books:developmentsince the actual code changes live in the books repository — hero_os only needs to keep proxying/hero_books/*to the books backend, which it already does.