-
-
Notifications
You must be signed in to change notification settings - Fork 589
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
feat(utils): Add loadable #698
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pmndrs/jotai/7vC8KaT7kiUF2X1EP16WUV92zd1o |
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. Latest deployment of this branch, based on commit 15fbff3:
|
Nice work. However:
Oh, right... This is not resolved yet, if it's same as #601. |
@dai-shi I wasn't aware that it was a bug for all atoms Given that this is a bug with all atoms, I think it's OK to release as-is. It should probably be documented somewhere that error recovery doesn't work. Should I mark the test as skipped or remove altogether? |
I'm not 100% sure if it's the same bug as #601. (tbh, I haven't spent much time on it yet.) Please leave the tests as skipped. Let's tackle it separately, if this is useful as is. |
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.
My final recommendation is to use WeakMap instead of refAtom, but let me shamelessly leave my intermediate comments.
6560615
to
e538df4
Compare
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 very nice!
Added a small suggestion to refactor.
e538df4
to
4144825
Compare
@dai-shi done! I did the same for the loadable cache as well, it's only one key |
await findByText('Error: An error occurred') | ||
}) | ||
|
||
it('loadable turns primitive throws into values', 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.
As we're using a WeakMap
, I added this test case. If a primitive value ever became a key for error
, it wouldn't work.
Interestingly, I didn't notice it. Thanks. (There might be other utils we could do the same.) |
4144825
to
68747fd
Compare
68747fd
to
15fbff3
Compare
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! Thanks so much.
Would you also work on docs? For now, docs are in a separate repo for now. |
@dai-shi yep I can have a look at that, will probably be next week |
EDIT: Moving my comment in the open discussion instead |
Fixes: #672 (or at least tries to)
This implements loadable as discussed in the mentioned issue.
I can't get all edge-cases to work. In particular, recovering from error, when an atom goes through these states:
suspense -> error -> suspense -> resolved
Going from
error -> suspense
does not trigger a re-render.I think this might need some changes to core, as I suspect by catching the error/promise, we are preventing some state-keeping logic from happening.
@dai-shi could you have a look? It's the last test in
loadable.test.tsx
that's failing.