pmndrs / suspend-react

🚥 Async/await for React components
MIT License
1.37k stars 25 forks source link

shallowEqualArrays falling short when using empty array as key #19

Open tom2strobl opened 1 year ago

tom2strobl commented 1 year ago

If a key is an empty array, suspend is called in an infinite loop, due to [] !== [] in js

// lets say this returns "[]"
const invoices = someCallFromDb()
// this is never settled, infinite looped
const paymentMoraleValues = suspend(
  async () => paymentMoraleFromInvoices(invoices),
  ['paymentMoraleValues', invoices]
)

Here's a sandbox for reproduction: https://codesandbox.io/s/suspend-react-infinite-rerender-mq391t

I know one can provide custom equality functions, but should such a basic case not be covered straight out of the box?

Would be a simple as making shallowEqualArrays account for it.