plentico / plenti

Static Site Generator with Go backend and Svelte frontend
https://plenti.co
Apache License 2.0
985 stars 50 forks source link

`on:load` doesn't fire the event on images #238

Open notramo opened 1 year ago

notramo commented 1 year ago

on:load handlers doesn't work with images (haven't tested other tags). Probably because the browser starts loading the file from the pre-rendered markup, which doesn't have JS support, and when the components are loaded, they are just swapped, without firing the event.

notramo commented 1 year ago

I have looked into it. It seems that the event handler registration is done on the pre-rendered document. It probably fires on the non-interactive pre-rendered document, before hydration. If the <img> tag is only rendered in the hydrated version, then it fires correctly:

<img src={ typeof window === 'undefined' ? '' : source_url } on:load={ animate_loaded() }/>

Please leave this issue open as a reminder to mention it in the documentation.