Skip to content

fix(core): store assets as raw bytes instead of File objects in Index… - #912

Closed
DoudouDoudouk wants to merge 3 commits into
pascalorg:mainfrom
DoudouDoudouk:fix/asset-storage-webkit
Closed

DoudouDoudouk wants to merge 3 commits into
pascalorg:mainfrom
DoudouDoudouk:fix/asset-storage-webkit

Conversation

@DoudouDoudouk

@DoudouDoudouk DoudouDoudouk commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

…edDB

saveAsset put the File itself into IndexedDB. Not every engine accepts File/Blob records (WebKit rejects the write), so every upload that goes through saveAsset failed there with no fallback.

Store { assetVersion: 1, bytes, type } instead, which uses the portable structured-clone path. loadAssetUrl rebuilds a Blob from that record, still reads File/Blob records written before this change, and returns null for an unreadable record instead of throwing inside createObjectURL.

What does this PR do?

How to test

Screenshots / screen recording

Checklist

  • I've tested this locally with bun dev
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch

Note

Medium Risk
Touches client-side asset upload/load used across the editor; behavior change is backward compatible but affects all paths that call saveAsset/loadAssetUrl.

Overview
IndexedDB asset persistence now writes a versioned { bytes, type } record instead of storing the File directly, fixing failures on engines (e.g. WebKit) that reject File/Blob values in IndexedDB.

loadAssetUrl rebuilds a Blob from that record via new helpers, keeps loading older File/Blob entries, and returns null with a warning when the stored value cannot be turned into a blob—avoiding throws from URL.createObjectURL. Tests cover the new on-disk shape, legacy records, and broken data.

Reviewed by Cursor Bugbot for commit e186799. Bugbot is set up for automated code reviews on this repo. Configure here.

…edDB

saveAsset put the File itself into IndexedDB. Not every engine accepts
File/Blob records (WebKit rejects the write), so every upload that goes
through saveAsset failed there with no fallback.

Store { assetVersion: 1, bytes, type } instead, which uses the portable
structured-clone path. loadAssetUrl rebuilds a Blob from that record,
still reads File/Blob records written before this change, and returns
null for an unreadable record instead of throwing inside createObjectURL.
@pascal

pascal Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

I hit an error while handling your request (Model unavailable on AI Gateway free tier: Free tier users do not have access to this model. Upgrade to paid credits at https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%3Fmodal%3Dtop-up for unrestricted…).

Please try again, rephrase, or reach out if it keeps failing.

Error id: 550823bd-bd72-4994-9e26-6cad61eb3629

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice fix, @DoudouDoudouk. The byte record plus the legacy Blob read path is the right approach, and the tests cover both. One small thing before merge: the old /** Save a file to IndexedDB and return a custom protocol URL */ JSDoc is now duplicated and orphaned above the StoredAssetRecord docblock. Please delete that copy and rebase onto current main. CI is also waiting on maintainer approval for this fork, and I'll merge once it's green.

Copy link
Copy Markdown
Member

Hi @DoudouDoudouk, sorry the earlier bot reply here errored out. Storing raw bytes instead of File objects in IndexedDB is the right fix. Two small things before it can land: there's a duplicated JSDoc block above the new asset record helper (one copy can go), and the branch needs a rebase onto current main. Heads-up: #854 touches the same asset-storage code, so whichever lands second will need to adapt to the other's record format. Thanks!

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[Maintainer] Re-reviewed at e186799. The duplicated/orphaned JSDoc from the earlier round is gone; saveAsset keeps one docblock and the new StoredAssetRecord has its own.

The design is right: a versioned plain-bytes record (assetVersion, bytes, type) instead of a File, with toBlob still reading legacy Blob/File records and an unreadable record returning null with a warning instead of throwing. All three paths are covered by tests.

One note, not blocking: file.arrayBuffer() holds a full copy in memory during save. For the sizes this store sees (user-uploaded models and textures) that is fine, but it is worth remembering if the limit is ever raised.

Code-only approval: the fork workflows have not run on this head (only Bugbot is green), so I will not merge until CI has run and passed.

@Aymericr Aymericr added the bot:bugs label Dec 2, 2026 — with Cursor

Aymericr commented Dec 3, 2026

Copy link
Copy Markdown
Member

Review at e1867991, run with Codex (gpt-6.2-astra) over two rounds: a full review, then each finding re-checked against the diff. Only findings that survived are listed.

  • P2 — packages/core/src/lib/asset-storage.ts:51 — Large files that Firefox could store as native File records can now fail to save. saveAsset puts the entire file.arrayBuffer() into one record. Firefox rejects records above MaxStructuredCloneSize() even when quota remains, but stores native Blob payloads separately. Fix: Try the native File write first; fall back to the byte record only when the engine rejects File/Blob storage.
  • P3 — packages/core/src/lib/asset-storage.test.ts:53 — The tests do not verify the loaded bytes or MIME type. The new-format test checks the stored record, while the load assertions check only startsWith('blob:'). An empty or mistyped Blob would pass. Fix: Fetch the URL returned by loadAssetUrl for each format and assert the exact response bytes and Content-Type: png-bytes / image/png for the byte record and old / text/plain for the legacy Blob.

P0/P1: 0. CI hasn't run on this fork PR yet because it needs a maintainer to approve the workflow run; it merges once that's green. The branch also has merge conflicts with main and needs a rebase.

Aymericr commented Dec 3, 2026

Copy link
Copy Markdown
Member

@DoudouDoudouk thanks again — this is already approved at e186799, and a rebase onto current main is the only thing blocking the merge.

I tried merging main locally just now. The only conflict is in packages/core/src/lib/asset-storage.ts, inside saveAsset: main now uses randomId() and still stores the File, while this branch uses nanoAssetId() and stores a { assetVersion, bytes, type } record. packages/core/src/lib/asset-storage.test.ts merges cleanly.

The conflict itself is a single short hunk. main gained randomId() in #1339, so the rebase should keep randomId() and keep your raw-bytes record. Once that's on main and CI is green, we'll squash-merge it.

Aymericr added a commit that referenced this pull request Dec 4, 2026
…912) (#1357)

Ports #1284 (Russian locale, wired through the lazy locale loader like #1200; 227 new strings as fuzzy / Review: required drafts) and #912 (store assets as raw bytes in IndexedDB; legacy File/Blob records still load).

Co-authored-by: Aleksandr Betra <69962782+betraalexandr@users.noreply.github.com>
Co-authored-by: Duhan K <157699651+DoudouDoudouk@users.noreply.github.com>

Aymericr commented Dec 4, 2026

Copy link
Copy Markdown
Member

Thank you @DoudouDoudouk! Your raw-byte asset storage fix has landed on main in #1357 (squash commit 730f00a), with you credited as co-author. The rebase conflict was resolved by keeping main's randomId() together with your { assetVersion: 1, bytes, type } record. Existing File/Blob records still load. Closing this as landed. Thanks again for the fix and your patience!

@Aymericr Aymericr closed this Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants