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

Code before:
        let is_removal = mutation.is_removal();
        if *local_name == local_name!("disabled") {
            self.handle_disabled_attribute_change(is_removal);
            return;
        }

        if !self.upcast::<Node>().is_connected() {
            return;
        }
        match *local_name {
            local_name!("rel") | local_name!("rev") => {
                let previous_relations = self.relations.get();
                self.relations
                    .set(LinkRelations::for_element(self.upcast()));

                // If relations haven't changed, we shouldn't do anything
                if previous_relations == self.relations.get() {
                    return;
                }

                // https://html.spec.whatwg.org/multipage/#link-type-stylesheet:fetch-and-process-the-linked-resource
                // > When the external resource link is created on a link element that is already browsing-context connected.
                if self.relations.get().contains(LinkRelations::STYLESHEET) {
                    self.handle_stylesheet_url();
                } else {
                    self.remove_stylesheet();
                }
            },
            local_name!("href") => {
                // https://html.spec.whatwg.org/multipage/#attr-link-href
                // > If both the href and imagesrcset attributes are absent, then the element does not define a link.
                if is_removal {
                    if self.relations.get().contains(LinkRelations::STYLESHEET) {
                        self.remove_stylesheet();
                    }
                    return;
                }
                // https://html.spec.whatwg.org/multipage/#link-type-stylesheet:fetch-and-process-the-linked-resource
                // > When the href attribute of the link element of an external resource link
                // > that is already browsing-context connected is changed.
                if self.relations.get().contains(LinkRelations::STYLESHEET) {
                    self.handle_stylesheet_url();
                }

                if self.relations.get().contains(LinkRelations::ICON) {
                    self.handle_favicon_url(&attr.value());
                }

                // https://html.spec.whatwg.org/multipage/#link-type-prefetch
                // When the href attribute of the link element of an external resource link
                // that is already browsing-context connected is changed.

Review comment (suggestion):
Nit: This might be a bit more readable with the header text to this list:

```suggestion
                // https://html.spec.whatwg.org/multipage/#link-type-stylesheet:fetch-and-process-the-linked-resource
                // >The appropriate times to fetch and process this type of link are:
                // > ...
                // > When the external resource link is created on a link element that is already browsing-context connected.
                // > ...
```

Code after:
            .unwrap()
            .attribute_mutated(attr, mutation, can_gc);

        let local_name = attr.local_name();
        let is_removal = mutation.is_removal();
        if *local_name == local_name!("disabled") {
            self.handle_disabled_attribute_change(is_removal);
            return;
        }

        if !self.upcast::<Node>().is_connected() {
            return;
        }
        match *local_name {
            local_name!("rel") | local_name!("rev") => {
                let previous_relations = self.relations.get();
                self.relations
                    .set(LinkRelations::for_element(self.upcast()));

                // If relations haven't changed, we shouldn't do anything
                if previous_relations == self.relations.get() {
                    return;
                }

                // https://html.spec.whatwg.org/multipage/#link-type-stylesheet:fetch-and-process-the-linked-resource
                // > When the external resource link is created on a link element that is already browsing-context connected.
                if self.relations.get().contains(LinkRelations::STYLESHEET) {
                    self.handle_stylesheet_url();
                } else {
                    self.remove_stylesheet();
                }
            },
            local_name!("href") => {
                // https://html.spec.whatwg.org/multipage/#attr-link-href
                // > If both the href and imagesrcset attributes are absent, then the element does not define a link.
                if is_removal {
                    if self.relations.get().contains(LinkRelations::STYLESHEET) {
                        self.remove_stylesheet();
                    }
                    return;
                }
                // https://html.spec.whatwg.org/multipage/#link-type-stylesheet:fetch-and-process-the-linked-resource
                // > When the href attribute of the link element of an external resource link
                // > that is already browsing-context connected is changed.
                if self.relations.get().contains(LinkRelations::STYLESHEET) {
                    self.handle_stylesheet_url();
                }

                if self.relations.get().contains(LinkRelations::ICON) {
                    self.handle_favicon_url(&attr.value());
                }