From a0adafb07e80db7bdc3e4c14088873024955c6ff Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 29 Sep 2026 13:08:34 +0000 Subject: [PATCH] Show document images from the local blob store An image uploaded into a document keeps only its `downloadURL` (`/download/files/`) in the node's `src`. In a browser-only drive (the default for the hosted distribution and for drives created there), neither the File's commit nor its bytes ever reach a server, so that URL answers 404 and the editor's node view showed "Failed to load image". File previews did not have this problem because they resolve the bytes locally through `useFileObjectUrl`; the editor image never did. - `@tomic/lib`: `blobSubjectFromDownloadUrl` maps a content-addressed download URL back to its `atomic:blob:`. - `@tomic/react`: `useBlobObjectUrl`, the blob-reference half of `useFileObjectUrl`, for callers without a File resource. - `ImagePicker`: render the local copy when there is one, fall back to the URL otherwise, wait for the lookup instead of racing it, and key the error state by src so a new src gets a fresh attempt. The document still stores the portable URL. - Wrap two label texts in spans: the i18n transform turned them into keyless arrays, which logged a React key warning whenever the picker opened. Adds `document-image.spec.ts`, which fails with "Failed to load image." before this change and passes after, including across a reload. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01P648McUYrscNsheXY5Ya81 --- TESTING_COVERAGE.md | 2 + browser/CHANGELOG.md | 7 ++ .../src/chunks/RTE/ImagePicker.tsx | 41 ++++-- browser/data-browser/src/locales/de.po | 18 ++- browser/data-browser/src/locales/en.po | 18 ++- browser/data-browser/src/locales/es.po | 18 ++- browser/data-browser/src/locales/fr.po | 18 ++- browser/e2e/tests/document-image.spec.ts | 118 ++++++++++++++++++ browser/lib/src/subject.test.ts | 37 ++++++ browser/lib/src/subject.ts | 25 ++++ browser/react/src/useFileObjectUrl.ts | 20 ++- 11 files changed, 285 insertions(+), 37 deletions(-) create mode 100644 browser/e2e/tests/document-image.spec.ts diff --git a/TESTING_COVERAGE.md b/TESTING_COVERAGE.md index ff908e8b3f..1f434889bf 100644 --- a/TESTING_COVERAGE.md +++ b/TESTING_COVERAGE.md @@ -22,6 +22,8 @@ Collection alias indexing: `sorted_parent_query_deduplicates_legacy_and_canonica New-drive sync: WebSocket unit coverage verifies SUB and SYNC wait for a pending genesis acknowledgement, then resume on ResourceSaved. The Local DB-off rendering E2E exercises this ordering with real server persistence. +Document images: `document-image.spec.ts` uploads a freshly generated PNG through the editor's image picker in a browser-only drive, whose bytes never reach a server, and verifies the image renders from the local blob store before and after a reload instead of showing "Failed to load image". `subject.test.ts` covers mapping a content-addressed `/download/files/` URL back to its blob. An image in a server-synced drive on a device that has not got the bytes still loads from the server URL; that path is not separately covered. + Cover repositioning: `cover-reposition.spec.ts` uploads a real image and verifies multiple pointer movements update its framing before release (native image dragging previously interrupted the gesture). Template visibility: `settings-templates.spec.ts` toggles Hide templates through Settings, verifies the loaded New page hides templates across reload, and restores them when unchecked. diff --git a/browser/CHANGELOG.md b/browser/CHANGELOG.md index 7325938fd2..f7bedf6739 100644 --- a/browser/CHANGELOG.md +++ b/browser/CHANGELOG.md @@ -4,6 +4,13 @@ This changelog covers all five packages, as they are (for now) updated as a whol ## UNRELEASED +- Images in documents show again instead of "Failed to load image". An uploaded + image's address points at the server, but a browser-only workspace never + sends its files there, so the server could not answer it. The editor now shows + the copy this browser already holds, as file previews already did, and falls + back to the server when there is none. New `useBlobObjectUrl` hook in + `@tomic/react` and `blobSubjectFromDownloadUrl` in `@tomic/lib`. + - Pasting an agent secret that opens a different agent than the signed-in account no longer signs that account out on its own. The app now says which account is signed in, shows both agents, and lets the user stay signed in or diff --git a/browser/data-browser/src/chunks/RTE/ImagePicker.tsx b/browser/data-browser/src/chunks/RTE/ImagePicker.tsx index 06fbabaeb0..69a4eeae90 100644 --- a/browser/data-browser/src/chunks/RTE/ImagePicker.tsx +++ b/browser/data-browser/src/chunks/RTE/ImagePicker.tsx @@ -10,7 +10,12 @@ import { Button } from '../../components/Button'; import { InputStyled, InputWrapper } from '../../components/forms/InputStyles'; import { Column, Row } from '../../components/Row'; import { FilePickerDialog } from '../../components/forms/FilePicker/FilePickerDialog'; -import { useStore, type Server } from '@tomic/react'; +import { + blobSubjectFromDownloadUrl, + useBlobObjectUrl, + useStore, + type Server, +} from '@tomic/react'; import { ClearType, FilePickerButton, @@ -72,8 +77,18 @@ const MarkdownEditorImage = ({ const [altText, setAltText] = useState(); const [caption, setCaption] = useState(); const [float, setFloat] = useState('none'); - const [imageError, setImageError] = useState(false); const [urlValid, urlRef] = useHTMLFormFieldValidation(); + const src: string | undefined = node.attrs.src || undefined; + // An uploaded image's `src` is its content-addressed download URL. Show the + // local copy of those bytes when there is one: in a browser-only drive it + // is the only copy, and no server can answer that URL. + const displaySrc = useBlobObjectUrl( + src ? blobSubjectFromDownloadUrl(src) : undefined, + src, + ); + // Keyed by the src that failed, so a new src gets its own attempt. + const [failedSrc, setFailedSrc] = useState(); + const imageError = !!displaySrc && failedSrc === displaySrc; const floatOptions: ButtonGroupOption[] = [ { @@ -132,9 +147,15 @@ const MarkdownEditorImage = ({ ); } + if (src && !displaySrc) { + // Still looking for a local copy. Rendering the URL meanwhile would ask a + // server that may never have had the bytes, and flash the error state. + return ; + } + if ( !extension.options.markdownCompatible && - node.attrs.src && + displaySrc && node.attrs.caption ) { return ( @@ -142,11 +163,11 @@ const MarkdownEditorImage = ({ } - src={node.attrs.src} + src={displaySrc} alt={node.attrs.alt} selected={selected} float={node.attrs.float} - onError={() => setImageError(true)} + onError={() => setFailedSrc(displaySrc)} />
{node.attrs.caption}
@@ -154,16 +175,16 @@ const MarkdownEditorImage = ({ ); } - if (node.attrs.src) { + if (displaySrc) { return ( } - src={node.attrs.src} + src={displaySrc} alt={node.attrs.alt} selected={selected} float={node.attrs.float} - onError={() => setImageError(true)} + onError={() => setFailedSrc(displaySrc)} />

{node.attrs.caption}

@@ -179,7 +200,7 @@ const MarkdownEditorImage = ({ {!selectedSubject && ( <> )}