#519: Behavior of the "disabled" attribute for HTMLLinkElement

Visit on Github.

Opened May 29, 2020

Hello TAG!

I'm requesting a TAG review of the behavior of the "disabled" attribute for HTMLLinkElement.

This request is being made at the suggestion of @slightlyoff in this Intent to Ship thread. This change is an interop-improvement, as the "disabled" attribute was previously poorly specified, and implementations differed. There is a more general need to specify the "disabled" attribute for HTMLStyleElement and SVGStyleElement, and this is discussed here and here. Perhaps the TAG could weigh in on either the HTMLLinkElement specifically, or these issues generally?

Further details:

  • I have reviewed the TAG's API Design Principles
  • Relevant time constraints or deadlines: None
  • The group where the work on this specification is currently being done: WhatWG
  • The group where standardization of this work is intended to be done: WhatWG
  • Major unresolved issues with or opposition to this specification: Just compat
  • This work is being funded by: Google/Mozilla

We'd prefer the TAG provide feedback as (please delete all but the desired option):

💬 leave review feedback as a comment in this issue and @-notify @mfreed7, @emilio

Discussions

Comment by @annevk May 30, 2020 (See Github)

What kind of support exists for <style>? With

<style>body { background:lime</style>
<style disabled>body { background:red</style>

I get red in each browser.

Comment by @emilio May 30, 2020 (See Github)

Yes, the content attribute doesn't exist for <style>. The WebIDL attribute does though, and it forwards to the underlying .sheet (so style.disabled = true; is effectively if (style.sheet) style.sheet.disabled = true; and so on.

Discussed Jun 8, 2020 (See Github)

[discussing "disabled" attribute]

Comment by @alice Jun 9, 2020 (See Github)

I note from the linked intent to implement and ship thread that this is more of an FYI:

@slightlyoff:

If there's a larger project to do here regarding the disabled attribute behaving consistently across elements, that's something they can weigh in on and, if they support, can help drive.

So, for the purposes of the implementing and shipping, no need to block on us; we will discuss whether there is more work to explore here and comment here if we have any thoughts.

Discussed Jun 15, 2020 (See Github)

Tess: I haven't looked at this.

David: I haven't looked either; I should do so!

Rossen / Tess: A few comments so far that haven't been answered.

David: Emilio is an author.

Sangwhan: Looks like this is all landed at WHATWG HTML already.

David: I suspect this is general interop improvement, but we should take a look given that we were asked.

Alice: Should the 3 of us schedule 15-20 minutes to look closer?

(will do

Comment by @hober Jun 18, 2020 (See Github)

How does the integration with CSSOM's disabled attribute work?

Comment by @alice Jun 18, 2020 (See Github)

(Working notes)

There was mention in the original bug(s) about HTMLStyleElement and SVGStyleElement, but the PR on HTML only seems to address HTMLLinkElement. We should follow up what happened with the other two.

Comment by @dbaron Jun 18, 2020 (See Github)

So one thing I'm trying to understand is how dynamic changes of disabled are processed. It seems like the change to the "linked resource fetch setup steps" means that the stylesheet isn't even loaded -- and then I think the change to "The appropriate times to fetch and process this type of link" means that changing disabled would mean that it causes the style sheet`s CSSOM representation to be dropped? Is that correct? (And is it desirable?)

If it's not correct... then what causes setting the disabled attribute to disable the stylesheet?

Comment by @emilio Jun 18, 2020 (See Github)

So one thing I'm trying to understand is how dynamic changes of disabled are processed. It seems like the change to the "linked resource fetch setup steps" means that the stylesheet isn't even loaded -- and then I think the change to "The appropriate times to fetch and process this type of link" means that changing disabled would mean that it causes the style sheet`s CSSOM representation to be dropped? Is that correct? (And is it desirable?)

Yes, that's correct and intentional. <link rel=stylesheet disabled> has link.sheet == null;. It indeed doesn't even load the stylesheet if the attribute is present in the first place.

This matches WebKit / Blink's behavior when coming from the parser (they had a quirk where if you remove and add the attribute again after loaded, it'd behave differently in somewhat odd ways). See https://github.com/whatwg/html/issues/3840#issuecomment-481034206 for context.

When disabled is removed, then stuff is processed normally, except for the "explicitly enabled" bit, which also makes alternates to work.

Comment by @emilio Jun 18, 2020 (See Github)

How does the integration with CSSOM's disabled attribute work?

They're completely independent. HTMLLinkElement.disabled just reflects the disabled attribute on the link. This is, I'd note, different from HTMLStyleElement.disabled and SVGStyleElement.disabled, which just forward to their inner stylesheet.

Firefox used to make HTMLLinkElement.disabled (the WebIDL attribute) behave just like HTMLStyleElement.disabled and SVGStyleElement.disabled, but we had to change it for compat reasons because people were using the link attribute, and here we are now.

Note that I intentionally proposed to make them two completely separate mechanisms, because figuring out a sane interaction between the CSSOM disabled flag and the link element felt really weird (setting link.sheet.disabled = true should ideally then also reflect on the link's attribute?). That also didn't match any engine.

So I went with a compromise described in the comment above.

Comment by @emilio Jun 18, 2020 (See Github)

(Working notes)

There was mention in the original bug(s) about HTMLStyleElement and SVGStyleElement, but the PR on HTML only seems to address HTMLLinkElement. We should follow up what happened with the other two.

HTMLStyleElement and SVGStyleElement have a disabled WebIDL attribute, but not a disabled html attribute... This is all more messy than it should, I know.

Ideally either:

  • The <link disabled> attribute wouldn't do anything special and all the WebIDL attributes would do the same thing in all the relevant elements. This is what Gecko used to implement, but had to implement the attribute for compat.

  • Maybe we also implement <style disabled>, behaving the same as <link>? That may be nice, though on the other hand the "explicitly enabled" stuff is a bit hackish, so not a fan of making it apply to all LinkStyles... Still may be a better end state.

Discussed Jul 20, 2020 (See Github)

David: Much smaller feature in an existing, interoperable spec.

... I replied to Emilio's comment, the status quo after the change in question seems like a reasonable compromise given the constraints.

... We should look at the specific issues Mason called attention to?

... I'm inclined to think we should close this issue... the reason things are ugly is compat, and people have tried to make it better and done what they could get away with compat-wise.

Peter: Propose closing, close at plenary?

David: sure

Comment by @dbaron Jul 20, 2020 (See Github)
  • Maybe we also implement <style disabled>, behaving the same as <link>? That may be nice, though on the other hand the "explicitly enabled" stuff is a bit hackish, so not a fan of making it apply to all LinkStyles... Still may be a better end state.

That seems somewhat problematic given the existence of disabled on HTMLStyleElement, since it would be weird to add a disabled attribute to <style> without having it reflected to JS as disabled. So it seems like the solution of having disabled on <link> be a totally different thing from what it is on <style> is probably less horrible than the compatible alternatives.

Comment by @dbaron Jul 20, 2020 (See Github)

Also, to comment on the original question: it sounds like it would have been nice to have more consistent behavior across elements, but based on @emilio's comments and the need that we found the need to implement inconsistent behavior in Gecko for compatibility, it sounds like that's not an option, and it feels like this PR has resolved some real interop problems.

Comment by @plinss Jul 22, 2020 (See Github)

Closing this, the TAG is happy to see this moving forward.