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

Throw error on useAtom(undefined) or useAtom(null) #2778

Merged
merged 6 commits into from
Nov 11, 2024

Conversation

kevinschaich
Copy link
Contributor

Related Bug Reports or Discussions

Fixes #2777

Summary

useAtom(undefined) throws Invalid value used as weak map key

Check List

  • pnpm run prettier for formatting code and docs

Copy link

vercel bot commented Oct 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 Nov 11, 2024 10:58am

Copy link

codesandbox-ci bot commented Oct 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
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.

Thanks for opening up a PR.

Here are some suggestions.

src/react/useAtomValue.ts Outdated Show resolved Hide resolved
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
@kevinschaich
Copy link
Contributor Author

Nice, I like the second one @dai-shi. Simple and won't break apps in production.

Copy link

github-actions bot commented Oct 19, 2024

LiveCodes Preview in LiveCodes

Latest commit: fceda43
Last updated: Nov 11, 2024 10:58am (UTC)

Playground Link
React demo https://livecodes.io?x=id/2T87KR47E

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.

Thanks for the change.

I reviewed it again, and now wonder if this check should be in store.ts, because the issue isn't specific to hooks.

@kevinschaich
Copy link
Contributor Author

kevinschaich commented Oct 21, 2024

@dai-shi would that error get thrown in the place we expect / where we are hitting the bug now if we move it?

If that's the preferred path forward I'd need more guidance on where specifically you'd like the check implemented

@dai-shi
Copy link
Member

dai-shi commented Oct 23, 2024

I added two commits illustrating two ideas. Do they work as expected?

@dai-shi
Copy link
Member

dai-shi commented Nov 5, 2024

@kevinschaich whenever you have time.

@dai-shi dai-shi added this to the v2.10.2 milestone Nov 5, 2024
@kevinschaich
Copy link
Contributor Author

Hey @dai-shi, changes working as expected for me. I think this is OK to move forward with.

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.

Thanks for confirming. Will merge it later.

@dai-shi dai-shi merged commit 6afbc09 into pmndrs:main Nov 11, 2024
40 checks passed
dmaskasky pushed a commit to dmaskasky/jotai that referenced this pull request Nov 14, 2024
* Fix undefined or null atoms

* Simplify conditional, only in dev mode

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>

* Update useSetAtom.ts

* move warning to store.ts

* move the warning in getAtomState

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Co-authored-by: daishi <daishi@axlight.com>
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