Repository: servo/servo
File: components/script/stylesheet_loader.rs (Rust)

Code before:
            .is_none_or(|generation| generation == link.get_request_generation_id())
    }

    /// <https://html.spec.whatwg.org/multipage/#contributes-a-script-blocking-style-sheet>
    fn contributes_a_script_blocking_style_sheet(
        &self,
        element: &HTMLElement,
        owner: &dyn StylesheetOwner,
        document: &Document,
    ) -> bool {
        // el was created by that Document's parser.
        owner.parser_inserted()
        // el is either a style element or a link element that was an external resource link that
        // contributes to the styling processing model when the el was created by the parser.
        && element.downcast::<HTMLLinkElement>().is_none_or(|_| self.contributes_to_the_styling_processing_model(element))
        // el's media attribute's value matches the environment.
        && element.matches_media_environment()
        // el's style sheet was enabled when the element was created by the parser.
        // TODO

        // The last time the event loop reached step 1, el's root was that Document.
        && *element.owner_document() == *document
        // The user agent hasn't given up on loading that particular style sheet yet.
        // A user agent may give up on loading a style sheet at any time.
        //
        // N/A we don't have a reason to do so yet
    }

    fn decrement_load_and_render_blockers(&self, document: &Document) {
        if self.is_blocking_stylesheet {
            document.decrement_script_blocking_stylesheet_count();
        }

        if self.is_render_blocking {
            document.decrement_render_blocking_element_count();
        }
    }

    fn finish_load(
        self,
        successful: bool,
        owner: &dyn StylesheetOwner,
        element: &HTMLElement,
        document: &Document,
    ) {
        self.decrement_load_and_render_blockers(document);
        document.finish_load(LoadType::Stylesheet(self.url), CanGc::note());

        let Some(any_failed) = owner.load_finished(successful) else {
            return;
        };

Review comment (suggestion):
Hrm. I guess this would be if the connection timed out, right? So we do actually handle, but elsewhere. Might be worth clarifying here.

Code after:
        let link = element.downcast::<HTMLLinkElement>().unwrap();
        self.request_generation_id
            .is_none_or(|generation| generation == link.get_request_generation_id())
    }

    /// <https://html.spec.whatwg.org/multipage/#contributes-a-script-blocking-style-sheet>
    fn contributes_a_script_blocking_style_sheet(
        &self,
        element: &HTMLElement,
        owner: &dyn StylesheetOwner,
        document: &Document,
    ) -> bool {
        // el was created by that Document's parser.
        owner.parser_inserted()
        // el is either a style element or a link element that was an external resource link that
        // contributes to the styling processing model when the el was created by the parser.
        && element.downcast::<HTMLLinkElement>().is_none_or(|_| self.contributes_to_the_styling_processing_model(element))
        // el's media attribute's value matches the environment.
        && element.media_attribute_matches_media_environment()
        // el's style sheet was enabled when the element was created by the parser.
        // TODO

        // The last time the event loop reached step 1, el's root was that Document.
        && *element.owner_document() == *document
        // The user agent hasn't given up on loading that particular style sheet yet.
        // A user agent may give up on loading a style sheet at any time.
        //
        // This might happen when we time out a resource, but that happens in `fetch` instead
    }

    fn decrement_load_and_render_blockers(&self, document: &Document) {
        if self.is_script_blocking {
            document.decrement_script_blocking_stylesheet_count();
        }

        if self.is_render_blocking {
            document.decrement_render_blocking_element_count();
        }
    }

    fn finish_load(
        self,
        successful: bool,
        owner: &dyn StylesheetOwner,
        element: &HTMLElement,
        document: &Document,
    ) {
        self.decrement_load_and_render_blockers(document);
        document.finish_load(LoadType::Stylesheet(self.url), CanGc::note());

        let Some(any_failed) = owner.load_finished(successful) else {