Skip to content

fix: a Blob src shows on both renderers, with its object URLs revoked - #101

Merged
chiefcll merged 1 commit into
mainfrom
fix/dom-blob-src
Dec 1, 2026
Merged

chiefcll merged 1 commit into
mainfrom
fix/dom-blob-src

Conversation

@chiefcll

@chiefcll chiefcll commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Supersedes #88. That PR adds Blob handling to the DOM renderer, but a review turned up some gaps; this one fixes them.

The problems

  • <view src={blob}> never reached the renderer. ElementNode.set src passed only strings to lng.src and made the view transparent for anything else. A Blob never got to the DOM node or the WebGL node.
  • URL leak after destroy. In Fix: Handling Blob image in updateNodeStyles #88, clearBlobUrl() on destroy also cleared blobSrc. Any later write to the node (from an animation or effect that outlives it) then made a new object URL that nothing revoked.
  • SubTexture crash. A SubTexture whose ImageTexture src is a Blob passed the Blob along as the URL, and applyPendingImageSrc threw (pendingSrc.startsWith is not a function). This also happens on main today.
  • Revoked too early. Fix: Handling Blob image in updateNodeStyles #88 revoked the old URL as soon as the source changed. Out of bounds, the <img> keeps showing the old URL until it comes back into bounds.
  • crossorigin on blob: URLs. It was set the same way as for network URLs. Old WebKit fails on that for inline data: sources, which is why data: is already excluded.

The change

  • ElementNode.src accepts string | Blob and passes a Blob through. The WebGL renderer already loads a Blob src the way ImageTexture does (sources.js), even though Node.src is typed string | null, hence the cast.
  • In the DOM renderer, imageUrlOf() resolves the image source (the node's src, or a SubTexture's ImageTexture src) into a URL. A Blob gets one object URL, which is reused while that Blob stays the source.
  • releaseBlobUrls() revokes every URL the node made except its current one and the one its <img> still shows. It runs after each restyle and after applyPendingImageSrc moves the <img>, and on destroy it revokes all of them.
  • A destroyed node makes no new URL.
  • blob: URLs load without crossorigin, like data:.

Tests

  • tests/blobSrc.test.tsx (jsdom, DOM renderer, with object URLs stubbed) covers: rendering, URL reuse, revoking on source change, the out-of-bounds hold, no URL after destroy, and the SubTexture case.
    • All 5 fail on main.
    • Taking out the destroyed guard breaks its test, and so does revoking right away instead of waiting for the <img> to move.
    • It's added to the vitest.browser.config.ts excludes, next to the other DOM-renderer contract tests, because that suite renders through WebGL.
  • tests/webgl/blobSrc.test.tsx (real renderer) checks that <view src={blob}> loads and fires loaded. It fails without the ElementNode change.
  • Results:
    • npm test: 780 passed.
    • pnpm test:webgl: 69 passed.
    • npm run lint: clean.
    • Browser suite: the same 43 failures as on main and no new ones.

Not covered

  • An ImageData src still shows nothing on the DOM renderer.
  • src={null} still doesn't clear the image; it only sets the color to transparent. That's existing behavior for string sources too.

🤖 Generated with Claude Code

`<view src={blob}>` did nothing: ElementNode's src setter only passed
strings to the renderer node (and turned the view transparent otherwise).
It now passes a Blob too; the WebGL renderer already loads one as
ImageTexture does.

The DOM renderer shows a Blob through an object URL the node owns:
- one URL per Blob, reused while that Blob stays the source
- a URL is revoked once nothing uses it: when the source changes, after
  the <img> has moved off it (out of bounds it keeps the old one until it
  is back in bounds), and when the node is destroyed
- a destroyed node makes no new URL, so a late write cannot leak one
- a SubTexture whose ImageTexture src is a Blob shows it, instead of
  throwing in applyPendingImageSrc (pendingSrc.startsWith on a Blob)
- blob: URLs load without crossorigin, as data: URIs do (old WebKit)

Supersedes #88.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chiefcll
chiefcll merged commit 07f03df into main Dec 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant