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: unwrap synchronously returns awaited values of resolved promise atoms #2880

Closed
wants to merge 1 commit into from

Conversation

dmaskasky
Copy link
Collaborator

@dmaskasky dmaskasky commented Dec 19, 2024

Related Bug Reports or Discussions

#2877

Summary

Synchronously return atom values whose promises have already resolved.

const asyncAtom = atom(Promise.resolve(0)
await store.get(asyncAtom)
store.get(unwrap(asyncAtom)) // 0

Check List

  • pnpm run prettier for formatting code and docs

@dmaskasky dmaskasky requested a review from dai-shi December 19, 2024 21:52
Copy link

vercel bot commented Dec 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 19, 2024 10:20pm

Copy link

codesandbox-ci bot commented Dec 19, 2024

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.

Copy link

pkg-pr-new bot commented Dec 19, 2024

Open in Stackblitz

More templates

npm i https://pkg.pr.new/jotai@2880

commit: 4efe200

Copy link

github-actions bot commented Dec 19, 2024

LiveCodes Preview in LiveCodes

Latest commit: 4efe200
Last updated: Dec 19, 2024 10:19pm (UTC)

Playground Link
React demo https://livecodes.io?x=id/7MCQHW67N

See documentations for usage instructions.

expect(store.get(syncAtom)).toBe(3)
})

it('should unwrap to a fulfilled value of an already resolved async atom', async () => {
const store = createStore()
const asyncAtom = atom(Promise.resolve('concrete'))

expect(await store.get(asyncAtom)).toEqual('concrete')
expect(store.get(unwrap(asyncAtom))).toEqual(undefined)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change in behavior.

@dai-shi
Copy link
Member

dai-shi commented Dec 20, 2024

Ohhhhh, my big apologies.
This is an intentional behavioral changed introduced in v2.10.0.
Sorry, I should have noticed when I read #2877 briefly. Thought something different with more recent changes.

This is not acceptable, but let's see if we have other solutions.

@dai-shi dai-shi closed this Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants