sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.56k stars 1.91k forks source link

on:load doesnt fire for <link> tags #11933

Closed sacrosanctic closed 1 month ago

sacrosanctic commented 7 months ago

Describe the bug

<svelte:head>
  <link
    as="image"
    href="https://upload.wikimedia.org/wikipedia/commons/4/47/American_Eskimo_Dog.jpg"
    rel="preload"
    on:load={() =>console.log('load success')}
  />
</svelte:head>

Specifically, on:load doesn't fire if asset is cached and it is an initial page load

Reproduction

https://www.sveltelab.dev/moq3nxlwmcxis9k?files=.%2Fsrc%2Froutes%2Flist%2F%2Bpage.svelte

download the repo from above and run it locally, sveltelab doesn't show the problem

navigate to /list append a random searchparam like ?a to the img URLs to clear cache press the browser refresh button it say success 2 failure 1 press the browser refresh button again it say success 0 failure 1

Logs

No response

System Info

.

Severity

annoyance

Additional Information

No response

dummdidumm commented 7 months ago

Related to https://github.com/sveltejs/svelte/issues/8301 - if we want to support this there needs to a replay mechanism for these events. I'm not sure yet if it's enough to have these in Svelte itself, or they need to be part of SvelteKit in a blocking script tag (to ensure they run), or both (Svelte providing the mechanism APIs, and SvelteKit wiring it up correctly).

sacrosanctic commented 1 month ago

@dummdidumm should this be closed since it looks like this is fixed in svelte 5