New atom invalidation logic is incorrect
See original GitHub issueHi, we recently upgraded Jotai in our app from 1.7.0 to 1.8.2. This was a great performance improvement for our app, but we’ve found a subtle bug that sometimes causes useAtomValue
to return old/stale values. We’re using React 17.0.2 without Suspense and can reproduce it on both our web app and React Native app.
In particular, we have many usages of useAtomValue
for the same derived atom, and some instances return the correct, current value while other instances are “stuck” returning the old, stale value.
Unfortunately I don’t have a simple reproduction, as our application is quite complex with a large tree of primitive and derived atoms, and we can only reproduce this when performing some complex operations that update many of those atoms.
However, I’ve noticed that when commenting out these lines: https://github.com/pmndrs/jotai/blob/fc96b2c72a057cb00afef0dfbe2ca30cbb7b23c4/src/core/store.ts#L866-L875 we get correct behavior, but we also get extra re-renders, and of course Jotai’s ‘no extra rerenders after commit with derived atoms (#1213)’ optimization test fails.
I’ll keep digging to see if I can identify the cause or a simple reproduction case, but wanted to raise this issue in case the cause is obvious to one of the maintainers.
Thanks!
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top GitHub Comments
It’s known as dual package hazard, and we know this library suffers from it. We spent lots of efforts previously, but at the moment, we think to leave the problem. (as we didn’t find reasonable solutions that work well for us.)
Hope you can configure your env to only use one bundle. Would also love to see a minimal reproduction. Please open a new discussion.
Thank you @dai-shi for the pointer. Posted a description and potential fix in #1537. Sorry for hijacking the thread.