atlassian / react-sweet-state

Shared state management solution for React
https://atlassian.github.io/react-sweet-state/
MIT License
871 stars 55 forks source link

Dates don't work in selectors #140

Closed mattcolman closed 2 years ago

mattcolman commented 3 years ago

Oh hi,

First time issue creator, long time fan of react-sweet-state.

I've noticed that if you return a Date from a selector then React components don't update. After some digging I've found that when "update" runs it does a "shallowEqual" against previous and current values. Two different Dates are returning true with the custom shallowEqual function and therefore components never update. See screenshot for a test I wrote.

Image 2021-08-03 at 3 49 17 pm

Workaround for now is to wrap the date in an object like selector: state => ({ date: state.myDate })

Perhaps we can just add another "if statement" for instanceof Date to shallowEqual?

Thanks!!

fkrafi commented 3 years ago

@albertogasparin , i have tried to fixed the bug, can you please verify, here is the PR https://github.com/atlassian/react-sweet-state/pull/147

albertogasparin commented 2 years ago

Fixed in #147