Comments (15)
@eryue0220 Any progress? 有什么进展吗? Should I work on it, or does anyone else want to try?我应该努力,还是其他人想尝试?
I'm still working on it. Maybe more some time.
from jotai.
Sorry for the confusion. I was confused too. I will merge #2197 soon, which should fix the issue. Let me try your reproduction.
from jotai.
I wonder why we didn't have such tests until now.
from jotai.
Here's the failing test. It passes on v2.2.3.
diff --git a/tests/vanilla/store.test.tsx b/tests/vanilla/store.test.tsx
index a95d35b..6093439 100644
--- a/tests/vanilla/store.test.tsx
+++ b/tests/vanilla/store.test.tsx
@@ -423,3 +423,15 @@ it('should update derived atoms during write (#2107)', async () => {
store.set(countAtom, 2)
expect(store.get(countAtom)).toBe(2)
})
+
+it('should not recompute a derived atom value if unchanged (#2168)', async () => {
+ const store = createStore()
+ const countAtom = atom(1)
+ const derived1Atom = atom((get) => get(countAtom) * 0)
+ const derive2Fn = vi.fn((get: Getter) => get(derived1Atom))
+ const derived2Atom = atom(derive2Fn)
+ expect(store.get(derived2Atom)).toBe(0)
+ store.set(countAtom, (c) => c + 1)
+ expect(store.get(derived2Atom)).toBe(0)
+ expect(derive2Fn).toHaveBeenCalledTimes(1)
+})
from jotai.
Can I have a tried?
from jotai.
Sure!
from jotai.
@eryue0220 Any progress?
Should I work on it, or does anyone else want to try?
from jotai.
@dai-shi Hello,I have some doubts about this. I found the bug occurred because the hasPromiseAtomValue
call was omitted in this line. But I don't have much context to know why.
from jotai.
This line?
Line 356 in cdbfcdf
Can you open a PR? I will see if it makes sense or not.
from jotai.
Sorry, I marked a wrong line. It's here, and I committed the PR, but I'm still working on it. The current code still exists bugs.
from jotai.
Ah, I see. It doesn't seem ideal, because it recomputes for all promise dependencies (some tests may fail, or such tests are missing.)
btw, we have another issue related with promise handling. #2192 (reply in thread)
It's not the same issue as it doesn't fix with v2.2.3, but it might be somehow related.
Hopefully, we have a single solution to cover both.
from jotai.
Hopefully, we have a single solution to cover both.
It's unlikely as I investigated #2199.
from jotai.
I think it was our intentional behavioral change in v2.3.0.
So, #2168 (comment) the test doesn't take that into account.
It should subscribe to derived2Atom
.
Let me see if we can work around in jotai-recoil
.
from jotai.
Ooops, that's my oversight again. It's not solvable on jotai-recoil
...
So, I guess we should give up the idea in #2029 unless we find a better solution.
from jotai.
I guess we should give up the idea in #2029 unless we find a better solution.
Does this mean #2029 will get reverted in the next Jotai release?
My current project (migrating a big app from Recoil to Jotai) is blocked in some areas. No hurries - I'm just trying to decide if we should downgrade to Jotai v2.2.3 for now, or wait for this bug to get fixed.
Happy to help in any fashion also.
Thanks!
from jotai.
Related Issues (20)
- How do I use jotai in ordinary js files?not function component.
- [React Native] Atom updates that occur within setTimeout/setInterval trigger a re-render for every useAtom instance HOT 1
- mount is executed twice HOT 2
- Bad lingature for coding font on doc page
- Atoms remount on recalculations HOT 1
- (Testing) HydrateAtoms component resets atoms when using multiple initial values
- RFC: Add `atomWithRefresh` in `jotai/utils` HOT 4
- react re-render fire just init time HOT 1
- Confusing example in documentation HOT 1
- Jotai suspends unnecessarily when a fullfilled promise is used by a derived atom
- atomWithStorage not working in ReactNative HOT 1
- webpack support
- Fix Support Page HOT 4
- Nextjs 14 app router webpack error
- Idea: lazy initialization for primitive atoms HOT 17
- Investigate and fix possible memory leaks in `store2` HOT 6
- Store type is not exported for createStore() HOT 2
- Migrate to pnpm HOT 1
- Children components don't see update of one atom in parent one HOT 1
- Possible regression of 2.6.4 with derived atoms HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jotai.