Closed blakeembrey closed 8 years ago
Unfortunately, this change doesn't cover all possible collisions :( Styles with nesting and keyframes are not always catched, because of collision in accumulated hash string.
Gist with failing test cases for the default hash function: https://gist.github.com/dmitrage/1daa3bc5306b176d0df300096441abfb
Keyframes:
Identifier for rules is computed from accumulated hash strings, in my case "fromcolor:#0008datocolor:red" and "fromcolor:#000f8ctocolor:red". Default hash function produces same hash value for both: "uybv9". So rules are constructed with rule
= "@keyframes huybv9"
and styles
= ""
. getIdentifier
returns same value, collision not detected.
Great catch, I'm not handling any accumulated hash strings in the detection. Not sure of the best way to do that right now, but I'll think on it.
The simplest thing I've found is to add hashString
property to Selector
and Rule
and use it in getIdentifier
. Not sure if it is 100% correct but at least all tests are passing. I've forked this branch and created a commit on top to show the idea.
Thanks for the idea, I was hoping not to have to keep around the extra data but it makes sense that I may have to (though the identifier diff is probably going to be a lot more confusing). I'll review and try to get that into the PR for the next release 👍
Closes #21.
Edit: If you're implementing your own hash, you'll need to remember to escape (https://github.com/mathiasbynens/cssesc). Don't really feel the need to take on a 150 line dependency for this feature.