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: setAtom uses stale pending on atom unmount #2811

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

dmaskasky
Copy link
Collaborator

@dmaskasky dmaskasky commented Nov 11, 2024

Related Bug Reports or Discussions

setAtom uses stale pending on atom unmount (#2812)

  • adds failing test: should use the correct pending on unmount
  • fixes failing test

Why is setAtom using a stale reference of pending?

Because setAtom is defined in mountAtom and references that function's pending.

Fix: dependency inject the current pending when invoking the pending functions

Check List

  • pnpm run prettier for formatting code and docs

Copy link

vercel bot commented Nov 11, 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 Nov 15, 2024 4:14am

Copy link

codesandbox-ci bot commented Nov 11, 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

github-actions bot commented Nov 11, 2024

LiveCodes Preview in LiveCodes

Latest commit: 772ba38
Last updated: Nov 15, 2024 4:14am (UTC)

Playground Link
React demo https://livecodes.io?x=id/3FR5Y8LMQ

See documentations for usage instructions.

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Nice catch.

tests/vanilla/store.test.tsx Outdated Show resolved Hide resolved
@dai-shi
Copy link
Member

dai-shi commented Nov 14, 2024

can't reopen. can't change the base branch. 😢

@dai-shi dai-shi reopened this Nov 14, 2024
@dai-shi dai-shi changed the base branch from fix/flush-pending-async to main November 14, 2024 02:29
@dai-shi
Copy link
Member

dai-shi commented Nov 14, 2024

now, it's reopened. can you please resolve conflicts?

@dmaskasky
Copy link
Collaborator Author

It looks good, but feels a bit complicated (especially currPending). Wondering if there's a simpler implementation.

Commit 2 changes this to use a mutable setAtom reference instead. Its cleaner but it adds an extra function call to the stack.

@dai-shi
Copy link
Member

dai-shi commented Nov 15, 2024

Cool. I was thinking of hiding isSync in the function createSetAtom too.

@dmaskasky
Copy link
Collaborator Author

commit 6 adds a createRuntime to clean up the code a little more.

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