fix: wait for images to load and decode before rendering - #592
Open
eoftedal wants to merge 1 commit into
Open
Conversation
Contributor
|
💖 Thanks for opening this pull request! 💖 Please follow the contributing guidelines. And we use semantic commit messages to streamline the release process. Examples of commit messages with semantic prefixes:
Things that will help get your PR across the finish line:
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #592 +/- ##
=======================================
Coverage 66.50% 66.50%
=======================================
Files 10 10
Lines 612 612
Branches 150 150
=======================================
Hits 407 407
Misses 144 144
Partials 61 61 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Images with a data url src were serialised into the foreignObject without ever being loaded, so the browser could rasterise the svg before it had them and silently leave them out of the capture. - add decodeImage(), which waits until an image can be painted and never rejects - await it for data urls instead of returning early, and after inlining a fetched resource, since load only says the data arrived - drop `image.decode = resolve`, which overwrote the clone's decode() method instead of awaiting it (bubkoo#325) - await it in createImage() too: decode() may reject for an image the browser can still paint, and the unhandled rejection left the promise from toPng() pending forever
eoftedal
force-pushed
the
fix/wait-for-image-decode
branch
from
August 30, 2026 20:06
bd1db7c to
9ccde2c
Compare
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.
Description
Images with a data url src were serialised into the foreignObject without ever being loaded, so the browser could rasterise the svg before it had them and silently leave them out of the capture.
image.decode = resolve, which overwrote the clone's decode() method instead of awaiting it (Fix Safari images #325)Tests are in
test/spec/image.spec.ts. Three of the four fail against unpatchedsrc: the data url wait (Expected true to be false), decode() still being usable on an inlined image (Expected toBeResolved to be called on a promise), and createImage (unhandled rejection, then a 20s jasmine timeout that takes the browser down with it). The fourth covers the fallback when decode() rejects. With the fix the suite is 55 of 59, the 4 skips being the pre-existingxits.Motivation and Context
I had issues where images would not show up in the final image. I tried redoing it and it would sometimes work and sometimes not.
Two parts of this overlap with PRs that are already open: #589 fixes the same createImage hang when decode() rejects, and #401 fixes the same
image.decode = resolvemisuse. This consolidates both with the data url wait, which is the part that explains images going missing. Happy to rebase on either if you would rather take them separately.Types of changes
Self Check before Merge