blakeembrey / free-style

Make CSS easier and more maintainable by using JavaScript
MIT License
707 stars 29 forks source link

Possible regression in v1? #14

Closed apalm closed 8 years ago

apalm commented 8 years ago

v0.5.6: http://requirebin.com/?gist=cb4df599fb69934baea9

v1.0.1: http://requirebin.com/?gist=ff31e7c6c16f720fbae2

Hopefully, the requirebins make it clear enough, but in the latter version, class y within the media query is overridden by the later class y, so the div's background is always palegreen. I'm guessing this is related to the de-duping of @-rules introduced in v1.

blakeembrey commented 8 years ago

@apalm Awesome catch! Definitely a regression, and partially related to the new de-deduping - the cause is actually a tiny bit more complex, but interesting, so I'll write it out (for fun).

So when a style is added to the cache, it's stored in an object. Object keys are ordered based on addition time (E.g. the first key added is before the second key). So the issue here is that it's correctly deduped, but the key order isn't updated - this results in output style being in the wrong order whenever there's a deduped style like this.

I'll release a patch ASAP, but thanks for the catch :+1:

blakeembrey commented 8 years ago

Released with 1.0.2 - http://requirebin.com/?gist=f6ea45caf71dd78caa15

apalm commented 8 years ago

Wow, that was quick :thumbsup:

Thanks for the explanation and patch.