Repository navigation
fix: a Blob src shows on both renderers, with its object URLs revoked - #101
Merged
Merged
Conversation
`<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>
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.
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 srcpassed only strings tolng.srcand made the view transparent for anything else. A Blob never got to the DOM node or the WebGL node.clearBlobUrl()on destroy also clearedblobSrc. Any later write to the node (from an animation or effect that outlives it) then made a new object URL that nothing revoked.srcis a Blob passed the Blob along as the URL, andapplyPendingImageSrcthrew (pendingSrc.startsWith is not a function). This also happens onmaintoday.<img>keeps showing the old URL until it comes back into bounds.crossoriginonblob:URLs. It was set the same way as for network URLs. Old WebKit fails on that for inlinedata:sources, which is whydata:is already excluded.The change
ElementNode.srcacceptsstring | Bloband passes a Blob through. The WebGL renderer already loads a Blobsrcthe way ImageTexture does (sources.js), even thoughNode.srcis typedstring | null, hence the cast.imageUrlOf()resolves the image source (the node'ssrc, or a SubTexture's ImageTexturesrc) 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 afterapplyPendingImageSrcmoves the<img>, and on destroy it revokes all of them.blob:URLs load withoutcrossorigin, likedata:.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.main.<img>to move.vitest.browser.config.tsexcludes, 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 firesloaded. It fails without theElementNodechange.npm test: 780 passed.pnpm test:webgl: 69 passed.npm run lint: clean.mainand no new ones.Not covered
ImageDatasrcstill 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