Giter Site home page Giter Site logo

Comments (15)

eryue0220 avatar eryue0220 commented on May 28, 2024 2

@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.

dai-shi avatar dai-shi commented on May 28, 2024 1

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.

dai-shi avatar dai-shi commented on May 28, 2024

I wonder why we didn't have such tests until now.

from jotai.

dai-shi avatar dai-shi commented on May 28, 2024

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.

eryue0220 avatar eryue0220 commented on May 28, 2024

Can I have a tried?

from jotai.

dai-shi avatar dai-shi commented on May 28, 2024

Sure!

from jotai.

dai-shi avatar dai-shi commented on May 28, 2024

@eryue0220 Any progress?
Should I work on it, or does anyone else want to try?

from jotai.

eryue0220 avatar eryue0220 commented on May 28, 2024

@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.

dai-shi avatar dai-shi commented on May 28, 2024

This line?

const readAtomState = <Value>(

Can you open a PR? I will see if it makes sense or not.

from jotai.

eryue0220 avatar eryue0220 commented on May 28, 2024

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.

dai-shi avatar dai-shi commented on May 28, 2024

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.

dai-shi avatar dai-shi commented on May 28, 2024

Hopefully, we have a single solution to cover both.

It's unlikely as I investigated #2199.

from jotai.

dai-shi avatar dai-shi commented on May 28, 2024

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.

dai-shi avatar dai-shi commented on May 28, 2024

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.

stevemolitor avatar stevemolitor commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.