-
Notifications
You must be signed in to change notification settings - Fork 114
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
Fix script loading issue in Firefox fixes #601 #605
Conversation
In Firefox the onload attribute is not always triggered on script element so we instead use script.addEventListener('load')
|
This loses us the ability to use |
I'm not sure I fully understand what you suggest with My understanding is that But neither in this PR or in my user land code, do I have JSX involved. My user land code: createScriptLoader({
src: "/assets/glide.min.js",
async: true,
onLoad() {
setHasGlideLoaded!(true);
},
}); What do you suggest exactly? |
Use |
I just checked and 'on:load' seems to work flawlessly, so we can pull off the following trick: const OMITTED_PROPS = ["src", "onLoad", "onload"] as const;
//...
const script = document.createElement("script");
const [local, scriptProps] = splitProps(props, OMITTED_PROPS);
const onload = local.onload || local.onLoad ? { 'on:load': local.onload || local.onLoad } : {};
setTimeout(() => spread(script, mergeProps(scriptProps, onload), false, true)); |
But I'm afraid onError might have the same issue? |
I hope to have time to test this today. |
Hi @atk sorry for the delay, couldn't find a time slot to check this before. I just tried what you suggested, but this doesn't seem to solve the issue. In the repro I created, I changed the scriptLoader to: createScriptLoader({
src: "https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js",
'on:load': () => {
console.log("jQuery loaded");
setJqueryLoaded(true);
},
}); But when running tests, it fails the same way as before. |
I just checked, on:load is transpiled by JSX expressions, so that does not help, we need to set the events ourselves. Let's use the actual events, but for all events. I'll create a PR. |
Closed; being fixed in #637 |
In Firefox the onload attribute is not always triggered on script element so we instead use script.addEventListener('load')