andreiduca / use-async-resource

A custom React hook for simple data fetching with React Suspense
https://dev.to/andreiduca/practical-implementation-of-data-fetching-with-react-suspense-that-you-can-use-today-273m
ISC License
94 stars 9 forks source link

replace object-hash with JSON.stringify #49

Open gajus opened 3 years ago

gajus commented 3 years ago

There is no obvious reason for using object-hash here and it adds 32kb to the bundle size.

https://bundlephobia.com/result?p=use-async-resource@2.2.1

andreiduca commented 3 years ago

Agreed, object-hash is large enough, but JSON.stringify doesn't preserve object equivalence: for identical objects with different order of their keys, it results in different values.

Another thing to keep note of: very large objects will result in very large keys, whereas a hash function will have the same length regardless of the object sizes.

There are alternatives, smaller and (maybe) faster. Too many actually. But I have not done much research:

But again, they are stringifiers, not hashers.

miguelski commented 3 years ago

also scope hoist in parcel (not sure about webpack) doesn't work because of object-hash

andreiduca commented 3 years ago

I will look into alternatives. Thank you for bringing it up. 🙏🏻

gajus commented 2 years ago

Any chance of this getting addressed? It is currently being flagged as the biggest dead weight in our app.