-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
canvas.Image lacks onload #2264
Comments
It's defined in C++: Lines 92 to 93 in adf73ee
node-canvas's |
That's not really in keeping with how it works in the browser though, so updating the JS side to make sure onload also gets called if it gets assigned after src has been assigned would be a good code update. |
It's not ideal, but I don't think we can change anything in the current version without that being a breaking change. Having |
why would that be a breaking change? existing code will keep working the same way, and "the browsery way" currently doesn't work, so isn't being used. |
should being key here, e.g. this code snippet would have changed behaviour? const img = new Image()
img.src = 'a.png'
img.onload = () => console.log('test')
img.src = 'b.png' Before this logged |
That'd be odd code to have anywhere, but yes, that would break. Then again, that's why semver exists of course: just bump the major version so that npm and friends don't auto-uplift to a breaking change. There's nothing sacred about version numbers, they're just a versioning utility, the "it'd be a breaking change" argument is literally why semver exists. Unless #2232 is planned for soon, of course, but from the looks of it, it doesn't have a timeline and none of the tasks have been completed yet? (Breaking changes should be fine, no matter how frequent, just bump the major version number each time you add one. Because the major version does not mean "a completely reworked release" when you're using semver. It just means "this is not backward compatible in one or more ways") |
Issue or Feature
The
Image
implementation lacks anonload
call (at least based on https://github.com/Automattic/node-canvas/blob/master/lib/image.js), making it impossible to use it "the normal way" where the onload is our signal that image data is available and now we can do something with that data.(
onload
on the HTML side = incredibly bad, do not use.onload
on the JS side: unfortunately still extremely necessary forImage
,WebSocket
, etc. etc. it never went away in JS land and we kept reinforcing it by introducing new object types that kept theonload
andonerror
pattern firmly alive right up to today =S)Steps to Reproduce
The above code won't actually do anything for
node-canvas
(but will run perfectly fine in the browser) because the shimmedImage
has no code to trigger theonload
"callback".Suggested fix
Add an
onload
property with getter/setter:And update
setSource
to something likeThe text was updated successfully, but these errors were encountered: