In Svelte5, why is the onload event not triggering the function foo()
in src/routers/+layout.svelte
?
<script>
const foo = () => console.log('foo triggered')
</script>
<svelte:window onload={foo} />
I'm guessing here, but most likely the load
event on the document has already fired before your own JS code runs that adds the listener for that event. In a +layout.svelte
, you should use onMount() instead.