Repository: servo/servo
File: components/script/dom/html/htmlstyleelement.rs (Rust)

Code before:
        //      `@import` rules. In that case, we do start to load urls.
        //
        // For situation 1 and 2a, we can immediately fire the load event
        // since we are done.
        if self.pending_loads.get() == 0 {
            // Step 4 of https://html.spec.whatwg.org/multipage/#the-style-element:critical-subresources
            //
            // Step 4. Queue an element task on the networking task source given element and the following steps:
            // Step 4.1. If success is true, fire an event named load at element.
            self.owner_global()
                .task_manager()
                .networking_task_source()
                .queue_simple_event(self.upcast(), atom!("load"));
        }

        // For situation 2b, we need to do more work.
        // Therefore, the following steps are actually implemented in
        // `ElementStylesheetLoader::load_with_element`.
        //
        //     Step 7. If element contributes a script-blocking style sheet,
        //     append element to its node document's script-blocking style sheet set.
        //
        //     Step 8. If element's media attribute's value matches the environment
        //     and element is potentially render-blocking, then block rendering on element.

        // Finally, update our stylesheet, regardless which scenario we ran into
        self.clean_stylesheet_ownership();
        self.set_stylesheet(sheet, cache_key);
    }

    // FIXME(emilio): This is duplicated with HTMLLinkElement::set_stylesheet.
    //
    // With the reuse of `StylesheetContent` for same stylesheet string content,
    // this function has a bit difference with `HTMLLinkElement::set_stylesheet` now.
    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
    pub(crate) fn set_stylesheet(
        &self,
        s: Arc<Stylesheet>,
        cache_key: Option<StylesheetContentsCacheKey>,
    ) {
        *self.stylesheet.borrow_mut() = Some(s.clone());
        *self.stylesheetcontents_cache_key.borrow_mut() = cache_key;
        self.stylesheet_list_owner()
            .add_owned_stylesheet(self.upcast(), s);
    }

    pub(crate) fn will_modify_stylesheet(&self) {
        if let Some(stylesheet_with_owned_contents) = self.create_owned_contents_stylesheet() {
            self.remove_stylesheet();
            if let Some(cssom_stylesheet) = self.cssom_stylesheet.get() {
                let guard = stylesheet_with_owned_contents.shared_lock.read();

Review comment (suggestion):
Nit:

```suggestion
        // Finally, update our stylesheet, regardless of which scenario we ran into
```

Code after:
        //      `@import` rules. In that case, we do start to load urls.
        //
        // For situation 1 and 2a, we can immediately fire the load event
        // since we are done.
        if self.pending_loads.get() == 0 {
            // Step 4 of https://html.spec.whatwg.org/multipage/#the-style-element:critical-subresources
            //
            // Step 4. Queue an element task on the networking task source given element and the following steps:
            // Step 4.1. If success is true, fire an event named load at element.
            self.owner_global()
                .task_manager()
                .networking_task_source()
                .queue_simple_event(self.upcast(), atom!("load"));
        }

        // For situation 2b, we need to do more work.
        // Therefore, the following steps are actually implemented in
        // `ElementStylesheetLoader::load_with_element`.
        //
        //     Step 7. If element contributes a script-blocking style sheet,
        //     append element to its node document's script-blocking style sheet set.
        //
        //     Step 8. If element's media attribute's value matches the environment
        //     and element is potentially render-blocking, then block rendering on element.

        // Finally, update our stylesheet, regardless of which scenario we ran into
        self.clean_stylesheet_ownership();
        self.set_stylesheet(sheet, cache_key);
    }

    // FIXME(emilio): This is duplicated with HTMLLinkElement::set_stylesheet.
    //
    // With the reuse of `StylesheetContent` for same stylesheet string content,
    // this function has a bit difference with `HTMLLinkElement::set_stylesheet` now.
    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
    pub(crate) fn set_stylesheet(
        &self,
        s: Arc<Stylesheet>,
        cache_key: Option<StylesheetContentsCacheKey>,
    ) {
        *self.stylesheet.borrow_mut() = Some(s.clone());
        *self.stylesheetcontents_cache_key.borrow_mut() = cache_key;
        self.stylesheet_list_owner()
            .add_owned_stylesheet(self.upcast(), s);
    }

    pub(crate) fn will_modify_stylesheet(&self) {
        if let Some(stylesheet_with_owned_contents) = self.create_owned_contents_stylesheet() {
            self.remove_stylesheet();
            if let Some(cssom_stylesheet) = self.cssom_stylesheet.get() {
                let guard = stylesheet_with_owned_contents.shared_lock.read();