recharts / react-smooth

react animation
MIT License
277 stars 38 forks source link

New object comparison using the "!==" operator is always true #88

Closed ngraef closed 5 months ago

ngraef commented 6 months ago

Using esbuild to build a project that includes recharts gives the following warning:

▲ [WARNING] Comparison using the "!==" operator here is always true [equals-new-object]

    .wrangler/tmp/pages-LvycvA/functionsWorker-0.3826531471696346.mjs:42421:46:
      42421 │ ...ibuteName && [attributeName] !== from || !attributeName && s...
            ╵                                 ~~~

  Equality with a new object is always false in JavaScript because the equality operator tests object identity. You need to write code to compare the contents of the object instead. For example, use "Array.isArray(x) && x.length === 0" instead of "x === []" to test for an empty array.

I traced that code back to react-smooth's Animate component:

https://github.com/recharts/react-smooth/blob/3ad17a73f12171ebe10cb1ad48c3f234f696f94f/src/Animate.js#L100-L103

Based on the git history, it looks like the intended code is this:

- if ((attributeName && [attributeName] !== from) || (!attributeName && style !== from)) {
+ if ((attributeName && style[attributeName] !== from) || (!attributeName && style !== from)) {

I don't know enough about this library to determine whether this logic bug has any practical impact.