-
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
Something needs to define the actual behavior of load/error events on <link>
#3532
Comments
@zcorpan you might be interested in this too. Note that sheets can get applied even if they report "error" in terms of the event, as far as I can tell. |
I will probably fix that in https://bugzilla.mozilla.org/show_bug.cgi?id=1443344 |
https://html.spec.whatwg.org/multipage/semantics.html#obtaining-a-resource-from-a-link-element tries to do this for most links, and I guess https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet is supposed to reuse that, although we have #968 implying that's not quite right. I guess the rather-vague part is
which is coupled with some fun stuff about the Content-Type in https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet This should ideally be defined in terms of network errors and non-ok statuses and more, and I guess we should find some more rigorous way to define "critical subresources". But by my reading of the current spec, assuming
So here is my proposed short-term fix:
How does this sound? |
That sounds lovely, and I agree that all the alerts should be "fail". I will probably write tests separately from those bugs I'm fixing, because I need to get those fixed ASAP and it's simpler to modify exisiting non-wpt tests we have for them. But I will make sure the tests get written. |
So writing tests now... Chrome will fire "error" for a sheet that imports a failing load, but fire "load" for a sheet that imports a sheet that imports a failing load.... |
@domenic https://bug1443652.bmoattachments.org/attachment.cgi?id=8956628 has some tests if you wanted to take a look and see whether they cover the cases you can think of. I didn't write anything for |
@TakayoshiKochi and @ericwilligers probably want to study/help with this as it will affect https://github.com/WICG/construct-stylesheets. |
* Defines the critical subresources for CSS as @imported style sheets, including indirectly imported ones. This was previously defined nowhere; probably it should live in CSS, but for now it lives here. * Makes it clearer that the steps to obtain the resource are the default steps, which some link types override. * Adds explicit steps for fetching critical subresources, and ties those to the load/error events. * Uses fetch primitives like network error and ok status instead of vague language. * Makes it clearer how incorrect Content-Types for CSS generate error events, by defining the new "resource-specific fetch error" concept. * Makes it clearer that resources apply if and only if their main fetch succeeds. (Critical subresource fetches generate error events, but do not impact the "obtained successfully" or "apply" concepts.) Fixes #3532.
@bzbarsky tests look good; I'm glad you got the nested import case. One thing that you might consider orthogonal, but I found a bit surprising and made sure to note when writing #3544, was that style sheets do apply even if they import something that fails. See http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=5812. |
* Defines the critical subresources for CSS as @imported style sheets, including indirectly imported ones. This was previously defined nowhere; probably it should live in CSS, but for now it lives here. * Makes it clearer that the steps to obtain the resource are the default steps, which some link types override. * Adds explicit steps for fetching critical subresources, and ties those to the load/error events. * Uses fetch primitives like network error and ok status instead of vague language. * Makes it clearer how incorrect Content-Types for CSS generate error events, by defining the new "resource-specific fetch error" concept. * Makes it clearer that resources apply if and only if their main fetch succeeds. (Critical subresource fetches generate error events, but do not impact the "obtained successfully" or "apply" concepts.) Fixes #3532.
@domfarolino, I think the OP in this issue is now covered by some nice rigorous spec text. Do you agree? However, I'm not as sure about web platform tests... |
Yes I agree. In terms of tests, my work added tests about the ordering between style sheet load/error event & scripting and removing / loading style sheets. I think there are still two kinds of tests needed:
Also regarding the first comment's test case, I think we can write tests for the HTTP case, since Fetch returns a network error for requests blocked by mixed content. For the HTTPs case, I guess that'd be covered by the tests in the second bullet above? |
I agree with your assessment of the missing tests for previous work. Any help pushing them over the finish line would be much appreciated, e.g. reviewing web-platform-tests/wpt#10350. For the first comment test cases, can't we just basically transcribe those tests into web platform test files? |
Consider this testcase:
In this case, the sheet is never applied, since this is a cross-site load and the returned type is not text/css. Browser behavior is as follows (the "loaded over" refers to the original page; the sheet is always being loaded over http):
Now consider a similar testcase:
Now the behavior is:
This is clearly broken... ;)
The text was updated successfully, but these errors were encountered: