-
-
Notifications
You must be signed in to change notification settings - Fork 638
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: should update dependents with the value of the unwrapped atom when the promise resolves #2920
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
commit: |
Size Change: -142 B (-0.15%) Total Size: 91.7 kB
ℹ️ View Unchanged
|
Preview in LiveCodesLatest commit: 897dc90
See documentations for usage instructions. |
f4e7433
to
31df90f
Compare
31df90f
to
66a134a
Compare
…hen the promise resolves
66a134a
to
fc05691
Compare
b060677
to
c827397
Compare
c827397
to
7addd25
Compare
it('should update dependents with the value of the unwrapped atom when the promise resolves', async () => { | ||
const store = createStore() | ||
const asyncTarget = atom(() => Promise.resolve('value')) | ||
const target = unwrap(asyncTarget) | ||
const results: string[] = [] | ||
const derived = atom(async (get) => { | ||
await Promise.resolve() | ||
results.push('effect ' + get(target)) | ||
}) | ||
store.sub(derived, () => {}) | ||
await new Promise((r) => setTimeout(r)) | ||
expect(results).toEqual(['effect undefined', 'effect value']) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. So, it's a regression, right? My bad... I'll see what I can do with the impl. It will be step by step and take a bit of time. Sorry folks for waiting.
|
I change my mind. Let me use this branch, which is easier for me to push changes. |
@@ -94,7 +94,7 @@ it('correctly handles the same promise being returned twice from an atom getter | |||
await expect(store.get(derivedAtom)).resolves.toBe('Asynchronous Data') | |||
}) | |||
|
|||
it('keeps atoms mounted between recalculations', async () => { | |||
it('keeps sync atoms mounted between recalculations', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the planned breaking change in v2.12.0.
@yuneco Will you be able to check if this breaks your app?
npm i https://pkg.csb.dev/pmndrs/jotai/commit/b4bb8a8d/jotai
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split to #2940. |
Related Bug Reports or Discussions
#2914
Summary
Caused by 34b4f8e and e777f46
Fix
Implementation
atomState.m.q is a Set of all atoms added async. Atoms added async with getter in readAtomState are added to this set. This Set is cleared when a new atom value is set and after recomputeDependents has completed. Only unmount dependencies not present in this Set.
Example:
Check List
pnpm run fix:format
for formatting code and docs