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

Link rel=modulepreload synchronously fires load event if script exists in module map #10166

Closed
domfarolino opened this issue Feb 27, 2024 · 1 comment

Comments

@domfarolino
Copy link
Member

What is the issue with the HTML Standard?

Per spec, if a <link rel=modulepreload as=script> becomes browsing-context connected, its special fetch and process the linked resource steps are run, which synchronously invoke fetch a modulepreload module script graph with a set of onComplete steps that simply fire a load or error event. This algorithm delegates to fetch a single module script, whose step 6 is:

If moduleMap[(url, moduleType)] exists, run onComplete given moduleMap[(url, moduleType)], and return.

This appears to be able to synchronously invoke script during insertion, which we generally see as a bad thing (i.e., mutation events). Rather, the firing of the load event should probably be done behind a queued task, as we do for error events in the error case.

@whatwg whatwg deleted a comment Feb 28, 2024
@domfarolino
Copy link
Member Author

Ugh, OK I've been bested by another usage of inline task queueing without nested steps. Turns out https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script:~:text=If%20moduleMap%5B(url%2C%20moduleType)%5D%20is%20%22fetching%22%2C%20wait%20in%20parallel%20until%20that%20entry%27s%20value%20changes%2C%20then%20queue%20a%20task%20on%20the%20networking%20task%20source%20to%20proceed%20with%20running%20the%20following%20steps already queues a task to "proceed with running the following steps", and the step I point out in the OP above is in that set of queued steps. So I don't think any action needs to be taken here.

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

No branches or pull requests

1 participant