Store user images as IndexedDB assets by content hash#65
Open
Mr-Macharia wants to merge 2 commits into
Open
Conversation
Store uploaded images/icons in IndexedDB by content hash and reference them from nodes via imageAssetId/iconAssetId. Gate with assetStoreV1 and lazy-migrate legacy data URLs on save.
There was a problem hiding this comment.
Pull request overview
This PR moves user-uploaded images and custom icons from inline data: URLs stored on nodes to content-addressed assets stored once in IndexedDB (referenced by sha256:… ids), reducing document/undo/snapshot bloat while keeping the app local-first.
Changes:
- Added an IndexedDB-backed asset store (encode/resize/hash, cached
blob:resolution, best-effort GC helpers) gated byassetStoreV1. - Updated node model + render/UI flows to prefer
imageAssetId/iconAssetIdand resolve display URLs at render time. - Added lazy migration that rewrites legacy inline
data:URLs to asset references during local-first persistence, plus unit tests for key helpers.
Reviewed changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/services/storage/localFirstRuntime.ts | Migrates legacy inline media to asset refs before saving local-first snapshots. |
| src/services/storage/assetTypes.ts | Defines asset/store ingest types and encode defaults. |
| src/services/storage/assetStore.ts | Implements asset store CRUD, ingest, display URL resolution, and GC helper. |
| src/services/storage/assetMigration.ts | Implements node-level and batch migration from data: URLs to asset ids. |
| src/services/storage/assetMigration.test.ts | Tests migration behavior with mocked asset store. |
| src/services/storage/assetHash.ts | Adds content-hash asset id generation + validation helpers. |
| src/services/storage/assetHash.test.ts | Tests asset id stability/validation. |
| src/services/storage/assetEncode.ts | Adds encode/resize logic + data:/blob helpers and error type. |
| src/services/storage/assetEncode.test.ts | Tests encode helper utilities and error typing. |
| src/lib/types.ts | Extends node data with imageAssetId / iconAssetId. |
| src/lib/nodeStyleData.ts | Adds iconAssetId to style field list for persistence/editing. |
| src/lib/nodeMediaState.ts | Centralizes “prefer asset id, else URL” media reference logic. |
| src/lib/nodeMediaState.test.ts | Tests media ref preference, collection, and inline detection. |
| src/lib/nodeIconState.ts | Updates icon normalization/creation to support iconAssetId. |
| src/lib/nodeIconState.test.ts | Tests icon state helpers with asset id support. |
| src/lib/nodeBulkEditing.ts | Adds iconAssetId to bulk-editable icon capabilities. |
| src/hooks/useResolvedMediaUrl.ts | Adds async resolution hook for asset ids to cached blob: URLs. |
| src/hooks/node-operations/useNodeOperationAdders.ts | Extends add-image operation to pass optional imageAssetId. |
| src/hooks/node-operations/nodeFactories.ts | Stores image nodes by imageAssetId when available. |
| src/config/rolloutFlags.ts | Adds assetStoreV1 rollout flag (default enabled). |
| src/components/properties/NodeProperties.tsx | Uses resolved URLs for display and writes asset ids on image upload. |
| src/components/properties/ImageUpload.tsx | Switches upload path to asset ingest + encode error UI. |
| src/components/properties/IconPicker.tsx | Adds icon asset ingest + resolved display support. |
| src/components/properties/families/ArchitectureNodeSection.tsx | Adds custom icon ingest + resolved display support. |
| src/components/properties/bulkNodePropertiesModel.ts | Tracks iconAssetId in bulk edit form state. |
| src/components/properties/BulkNodeProperties.tsx | Wires iconAssetId through bulk icon upload flow. |
| src/components/ImageNode.tsx | Resolves image display via useResolvedMediaUrl. |
| src/components/FlowEditorPanels.tsx | Updates onAddImage signature to carry optional asset id/position. |
| src/components/flow-editor/useFlowEditorController.ts | Propagates updated add-image signature. |
| src/components/flow-editor/panelProps.ts | Updates command bar panel builder types for new add-image signature. |
| src/components/flow-editor/buildFlowEditorControllerParams.ts | Updates controller param types for new add-image signature. |
| src/components/flow-canvas/useFlowCanvasDragDrop.ts | Ingests dropped images into asset store before adding nodes. |
| src/components/CustomNode.tsx | Resolves uploaded icon/image URLs for rendering without inline payloads. |
| src/components/custom-nodes/MobileNode.tsx | Resolves image media for mobile wireframe rendering. |
| src/components/custom-nodes/BrowserNode.tsx | Resolves image media for browser wireframe rendering. |
| src/components/custom-nodes/ArchitectureNode.tsx | Resolves custom/provider icons via resolved media URLs. |
| src/components/command-bar/types.ts | Updates command bar prop type for new add-image signature. |
| ARCHITECTURE.md | Documents asset-by-reference persistence behavior and rollout flag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+186
to
+188
| } catch { | ||
| // Migration is best-effort; always fall through to save. | ||
| } |
Comment on lines
+171
to
+173
| } catch { | ||
| // Keep picker usable if encode/store fails; user can retry. | ||
| } |
Comment on lines
+116
to
+118
| } catch { | ||
| // Keep inspector usable if encode/store fails. | ||
| } |
Comment on lines
68
to
70
| .catch(() => { | ||
| // Ignore failed drops; user can retry via the add-image control. | ||
| }); |
Log storage telemetry when save-time migration or image drops fail, and show inline errors for custom icon uploads instead of swallowing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
User-uploaded images and custom icons were stored as inline
data:URLs on nodes. That payload was then duplicated across the live document, undo history, and snapshots, which bloated browser storage and made media-heavy diagrams expensive to save and undo.This PR introduces asset-by-reference storage using the existing IndexedDB
assetsobject store:sha256:…)imageAssetId/iconAssetIdinstead of multi-MB data URLsblob:URLsdata:URLs into the asset store on document saveLocal-first is unchanged — media stays in the user’s browser (IndexedDB). No new runtime dependencies.
Motivation / problem
assetsstore was already declared in the IndexedDB schema but unusedSolution
assetStoreV1/VITE_ASSET_STORE_V1(default on; set=0for legacy behavior)src/services/storage/assetStore.ts(+ encode/hash/migration helpers)imageAssetId/iconAssetIdon node datauseResolvedMediaUrlon image/icon/wireframe/custom/architecture nodesARCHITECTURE.mdPersistence sectionGuidelines checklist
src/services/storage/; UI stays thinsrc/config/rolloutFlags.ts)flowmind_*etc.)data:URLsHow to test
Manual:
VITE_ASSET_STORE_V1=0and confirm legacy data-URL path still works.Out of scope / follow-ups
Notes for reviewers