Jotai v2.7.0+ useAtomValue for Async Derived Atoms Not Updated Under Specific Conditions #2565
Unanswered
yuneco
asked this question in
Bug report
Replies: 1 comment 4 replies
-
Thanks for reporting. I added a test in #2567. The same code on stackblitz: https://stackblitz.com/edit/vitejs-vite-veyv13?file=src%2FApp.tsx&terminal=dev It works with |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
In #2554, I reported an edge case regarding the re-calculation of derived atoms, which has been fixed in v2.8.1 (great thanks for the quick response!). However, I noticed that v2.8.1 may still have a similar problem.
Sample Reproducible Code:
https://codesandbox.io/p/sandbox/jotai-2-7-atom-recalculation-issue-forked-45smpl
Sample Code Overview and Expected Output:
We create a simple counter atom that can be incremented synchronously using an update action.
We also create an async atom that provides a counter base value. The total counter value can be obtained via
totalCountAtom
.In the components, we expect the incremented value with every single click of the button that calls
countUpAction
.This works on v2.6.5, but does not update after second click on v2.7.0+ including v2.8.1.
v2.6.5 Console log
v2.8.1 Console log
In v2.8.1, the atom itself is re-rendered but the component using the atom value is not re-rendered. It seems this problem occurs when dependencies are read after an async atom read.
More to the point, the primary factor is not
baseCountAtom
but seems to be theawait
before get.I assume that this problem is also related to the #2396 refactoring but need help to solve.
Beta Was this translation helpful? Give feedback.
All reactions