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 && ( <> )}