-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Should module scripts always fire load events? #6421
Comments
This makes sense to me. It sounds like from the bug you linked browsers are not interoperable here. @hiroshige-g do you have any interest in writing web platform tests for this case as the next step? |
cc @codehag |
I guess this has never been an issue with classic script because inline classic script can be deferred? |
Can't you just check An event might be the right API. Or maybe we just need to expose a boolean indicating whether the script has already executed or not. If the use case involves doing something in the case the script hadn't run yet or never runs, it's not useful to have a load event since load event will never fire in that case so you'd have to check the above condition anyway. |
Only parsed scripts can end up in the deferred queue, appended scripts like above are just async. Besides, an inline module script could run much later than
I think we should use a We should be putting promises on everything with |
(See #127 for the ready promise, though maybe it's easier for things that fetch things.) |
What are use cases / concrete scenarios in which checking whether such a script has ran is useful?
I don't find that argument compelling without knowing other places in the platform where we'd fire load event on things that don't involve resource loading. |
(SVG and initial about:blank in |
In the Chromium report, it seems like the script is being slowly ported from classic to module. The developer is expecting particular global state & side effects to have been applied once the script has ran. There are other more 'ideal' ways to do this in a purely module world, but that isn't always how it goes in the real world 😄
But that's the point, it might involve resource loading. An inline module script can include imports, and top-level await. const script = document.createElement('script');
script.textContent = `
import { someURL } from './foo';
const response = await fetch(someURL);
`;
script.type = 'module';
document.head.append(script); We could consider other types of resource that have
* You could say an inline module without imports (or equivalent top-level-awaits) doesn't fetch script, but do we really want to toggle behaviour on the script's source like that? It seems like, when the spec was written, the author thought they were being consistent by making inline module scripts behave like inline classic scripts in terms of the |
Actually, |
How would I know when the above script has executed?
src
, as there's a"load"
event.src
, as it's synchronous.However, module scripts without a src still execute asynchronously, but there's no
"load"
event.It feels like we should dispatch a
"load"
event for all module scripts, not just those from an external file. WDYT @domenic?This was raised in https://bugs.chromium.org/p/chromium/issues/detail?id=1180532#c8.
The text was updated successfully, but these errors were encountered: