Skip to content
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

window onload does not fire up in chrome #14873

Open
zilberlex opened this issue Jan 2, 2025 · 0 comments
Open

window onload does not fire up in chrome #14873

zilberlex opened this issue Jan 2, 2025 · 0 comments

Comments

@zilberlex
Copy link

zilberlex commented Jan 2, 2025

Describe the bug

When i use <svelte:window onload={onLoad}> it does not work in chrome (And also not in svelte.dev environments), but it does work in Firefox.

After talking with chatgpt the fix was:


onMount(() => {
    if (document.readyState === 'complete') {
        onLoad();
    } else {
        // Otherwise, wait for the load event
        window.addEventListener('load', onLoad, { once: true });
    }
});

function onLoad(_event) {
    console.debug('loaded window.');
    isAppLoaded = true;
}


According to chatgpt onload event my fire before the sveltecode which attaches the eventhandler executes.

I am not a big expert in WebDev, but if I understand this correctly, it is not only a svelt issue. It would be nice if the had already the fix above implmeneted, if that is even the correct way to handle that.

Reproduction

https://svelte.dev/playground/0f493cd43f36479fb6c907fa08d16ed3?version=5.16.0

Currently, it is successfully reproduces in the online environemnt of svelte.dev, but due to the nature of the issue (race condition), there might be a chance it won't reproduce.

Logs

No response

System Info

Independant Scripts:
  Chromium (131.0.2903.99)    

Internet Explorer: 11.0.26100.1882
  npmPackages:
    svelte: ^5.0.0 => 5.16.0

Severity

annoyance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant