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

Consider changing task source for link "error"/"load" events #3610

Closed
domfarolino opened this issue Apr 4, 2018 · 5 comments
Closed

Consider changing task source for link "error"/"load" events #3610

domfarolino opened this issue Apr 4, 2018 · 5 comments
Assignees
Labels
interop Implementations are not interoperable with each other topic: event loop

Comments

@domfarolino
Copy link
Member

Right now the spec the spec mentions at the bottom of 4.2.4.3 Obtaining a resource from a link element that the task source for the "error"/"load" events is the DOM manipulation task source. Given the aforementioned events are primarily network-based, it might make sense to queue these from the networking task source instead.

Aside:

I created this gist to see if I could observe the "load" event of a link element that is blocking the pending parsing-blocking script of a Document, before the script's execution, and even further before the DOMContentLoaded event is observed. Given the gist, Chrome gives the following in the console:

async script start
async script end
Pending parsing-blocking script now executing
DOMContentLoaded
<link> load event fired

while Firefox yields:

async script start
async script end
<link> load event fired
Pending parsing-blocking script now executing
DOMContentLoaded

The latter makes more sense to me, since for the inline script to run, the link event has to be loaded, of course. The spec is written this way, and Chrome is currently non-compliant (there are actually two issues with Chrome, DOMContentLoaded is fired synchronously and the networking task source is actually used for the link element).

However, Anne makes a good point in that networking-driven events should come from the networking task source, which can of course be prioritized in an implementation-dependent manner relevant to the DOM manipulation task source. This example is a specific instance where it would be convenient otherwise, but his point overall makes sense.

@annevk
Copy link
Member

annevk commented Apr 5, 2018

This also came up in #3544 with @domenic.

@annevk annevk added the interop Implementations are not interoperable with each other label Apr 5, 2018
domenic added a commit that referenced this issue Apr 5, 2018
This will also fix #3610
@domenic
Copy link
Member

domenic commented Apr 5, 2018

It looks like I'm on track to fix it as part of that.

@domenic
Copy link
Member

domenic commented Sep 11, 2018

I am no longer on track to fix it as part of that, as #3544 descended into "oh gawd everything is broken we need to start over and write a ton of tests". So, a more targeted fix for just the task source issue would make more sense.

@domfarolino
Copy link
Member Author

domfarolino commented Sep 11, 2018

The issue regarding the ordering of <link> onload/onerror events being fired in relation to the pending parsing-blocking script being executed came up once more in #4020. This seems to be a Chrome bug, but I want to be sure, so I have a question: It's clear that pending parsing-blocking scripts cannot execute until style sheets that are marked as script-blocking are no longer categorized as script-blocking. This is clear from the usage of "spin the event loop" in the scriptEndTag parser algorithm. With this, I'm wondering after the event loop has spun to the point such that there are finally no more script-blocking style sheets, does this guarantee:

  • The style sheet is known to be obtained/failed, and the appropriate "load"/"error" event has been dispatched
  • ...or only that the resource is known to be obtained/failed (there is some resolve, though the corresponding event is not guaranteed to be dispatched yet)

If it's the former, the spec is fine and Chrome has a bug. If it's the latter, I think it would be nice to try and change the spec to make it the former, so we can guarantee, at least in this circumstance, well-ordered event dispatching.

/cc @domenic @emilio


Edit

Anne has answered this over IRC. The plan moving forward wrt the weird ordering is probably to:

  • Have style sheet link to css style sheet (is this viable?)
  • Rename the style sheet ready flag to something like "style sheet done"
  • Actually set the "style sheet done" flag probably as a part of the task that is queued once a resource has finally been obtained so that we can more explicitly remove a resolved resource from the set of style sheets that block scripts.
  • Write tests!

@bzbarsky
Copy link
Contributor

@domfarolino's plan sounds good to me, fwiw.

mustaqahmed pushed a commit to mustaqahmed/html that referenced this issue Feb 15, 2019
* Introduce new link loading infrastructure, specifically algorithms to
  fetch and process linked resources that are overridable by the
  individual link types. This replaces the previous "obtain the
  resource" algorithms with something more structured and rigorous.
* Specify the order in which style sheets are removed, created/added,
  their corresponding load/error events are fired, and scripting is
  unblocked from a loading style sheet.
* Replace "style sheet done" flag with Document's "script-blocking style
  sheet counter", which works in tandem with the "contributes a
  script-blocking style sheet" conditions, which replaces the definition
  of "a style sheet that is blocking scripts".
* Change <link> load/fire events to be fired from tasks queued on the
  networking task source, instead of the DOM manipulation task source.
* Handle much of what whatwg#3544 set out to do, minus defining and explicitly
  fetching a style sheet's critical subresources.

Fixes whatwg#3610.

Tests: web-platform-tests/wpt#14899
mustaqahmed pushed a commit to mustaqahmed/html that referenced this issue Feb 15, 2019
* Introduce new link loading infrastructure, specifically algorithms to
  fetch and process linked resources that are overridable by the
  individual link types. This replaces the previous "obtain the
  resource" algorithms with something more structured and rigorous.
* Specify the order in which style sheets are removed, created/added,
  their corresponding load/error events are fired, and scripting is
  unblocked from a loading style sheet.
* Replace "style sheet done" flag with Document's "script-blocking style
  sheet counter", which works in tandem with the "contributes a
  script-blocking style sheet" conditions, which replaces the definition
  of "a style sheet that is blocking scripts".
* Change <link> load/fire events to be fired from tasks queued on the
  networking task source, instead of the DOM manipulation task source.
* Handle much of what whatwg#3544 set out to do, minus defining and explicitly
  fetching a style sheet's critical subresources.

Fixes whatwg#3610.

Tests: web-platform-tests/wpt#14899
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interop Implementations are not interoperable with each other topic: event loop
Development

No branches or pull requests

4 participants