Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: derived atom is not recomputed after its dependencies changed #2906 #2907

Merged
merged 14 commits into from
Jan 14, 2025
18 changes: 18 additions & 0 deletions tests/vanilla/store.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,24 @@ it('recomputes dependents of unmounted atoms', () => {
expect(bRead).not.toHaveBeenCalled()
})

it('recomputes all changed atom dependents together', async () => {
const a = atom([0])
const b = atom([0])
const a0 = atom((get) => get(a)[0]!)
const b0 = atom((get) => get(b)[0]!)
const a0b0 = atom((get) => [get(a0), get(b0)])
const w = atom(null, (_, set) => {
set(a, [0])
set(b, [1])
})
const store = createStore()
store.sub(a0b0, () => {})
store.set(w)
expect(store.get(a0)).toBe(0)
expect(store.get(b0)).toBe(1)
expect(store.get(a0b0)).toEqual([0, 1])
})

it('should not inf on subscribe or unsubscribe', async () => {
const store = createStore()
const countAtom = atom(0)
Expand Down
Loading