sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
7.02k stars 437 forks source link

replace onload with addEventListener in inject_styles #1790

Closed ankitstarski closed 2 years ago

ankitstarski commented 2 years ago

When multiple dynamically imported components are loaded, only one of them resolves the promise. Upon further investigation, I found out that those components were loading .css files and inject_styles function was using onload in order to resolve inject_styles promise.

If two components use the same css file, the first onload will be overridden by the second one.

The solution is to replace onload with addEventListener("load", ....

@Rich-Harris pushed a fix for this in svelte kit (kit#347)

benmccann commented 2 years ago

Although that code change was from before SvelteKit switched to Vite. That code no longer exists in SvelteKit as Vite is now responsible for it. That being said I'll go ahead and merge this since it looks like Rich approves of the change