RE: objection re: RESOLVED: setProperty's handling of importance logically behaves same as appending a declaraiton (like IE/WebKit)

>> var backup = { value: style.getPropertyValue(prop), priority:
>> style.getPropertyPriority(prop) }
>> style.setProperty(prop, tempValue, 'important');
>> doSomeStuff();
>> style.setProperty(prop, backup.value ? backup.value : '',
>> backup.priority);
>> I'm using this in existing code already,
> Then it doesn't do what you expect in IE/Blink/WebKit. That's either an
> argument for you to fix your code, or an argument that the spec doesn't
> match your expectations and we should change the spec and IE/Blink/WebKit
> to do what you expect.

More precisely, it's either both or just the first one. I cannot really leave my code as is even if I consider it a bug in the browsers, technically.

>> and never noticed any issue with it (most probably because in fact no
>> one use inline style and therefore the latest declaration usually reset
>> the property to its undeclared state, and the inline style wins over any
>> stylesheet in all the remaining cases)
> Inline style without !important doesn't win over !important in a
> stylesheet.

Sure. But !important is not very common, which is why I said that.

>> I'm at least able to confirm that
>> style.setProperty('color', 'blue', 'important')
>> style.setProperty('color', '', '')
>> resets the property in IE which seem to be the reference that has been
>> chosen as the way to go.
> The empty string as value has the semantic to call removeProperty(), so
> that's not a good test.

The function description doesn't talk about it anywhere. The algorithm may, but we don't expect web authors to read algorithms, right? To me, this behavior is simply described as "{ color: blue !important }" becoming "{ color:; }" and therefore "{}" which is what the function description says the function does.

However, I would consider looking at real-life usage and see what behavior is usually expected there, because this is exactly what the API should do. I'm not an absolute reference but my expectations may be shared by more developers. And the only way to tell is to look for it on actual web source code. So this is what I did. And I'm somewhat glad to see I'm not the only one that had this expectation:

    var style =;
    var value = style[] || '';
    var important = style.getPropertyPriority(aTarget.CSSName);
    style.setProperty(aTarget.CSSName, aTarget.default, 'important');
    return {
        value : value,
        important : important
        aValue.important ? 'important' : ''

The whole thing works, as I said, because it's pretty rare in practice to have anything specified in the style so the backup ends up setting '' and properly reset the property.

You can see this as some codes just do not take care of restoring the original value, supposing that there was no:

As a result of this, and because of the name and description of the function, people like me end up using setProperty as a backup-restoring function and we never noticed it didn't work as expected in all browsers. Making this actually working would be something to take in consideration. 

More generally, concerns about stuff that previously had no impact in CSS should not enter in consideration when deciding on the final algorithm of a function defined prior the introduction of the concept because people using the function could not care about the ordering issue before and could not possibly forsee it would impact the function's algorithm given it simply didn't exist at the time. 

If the behavior implied by the function name - SET - is an issue, it's always possible to define a new function - like appendDeclaration - that would cover the new use case. 		 	   		  

Received on Thursday, 12 September 2013 20:28:17 UTC