-
Notifications
You must be signed in to change notification settings - Fork 14
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
allow to auto-reset error in atomWithSuspenseQuery #75
base: main
Are you sure you want to change the base?
allow to auto-reset error in atomWithSuspenseQuery #75
Conversation
03535ed
to
350335a
Compare
// therefore get optimisticResult but without activating query (_optimisticResults: undefined [I think that's how it works]) | ||
const { _optimisticResults, ...clearedDefaultedOptions } = | ||
defaultedOptions | ||
|
||
const erroredResult = observer.getOptimisticResult( | ||
clearedDefaultedOptions | ||
) |
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.
_optimisticResults: undefined
is not accepted by linter/ts config, therefore do that :<
Not sure is it even needed, maybe theres better way to do that? useBaseQuery
is referencing queryCache
in one place, so maybe that or client.getQueryData()
is worth checking.
https://github.com/TanStack/query/blob/main/packages/react-query/src/useBaseQuery.ts#L111
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.
introduced here in react query: TanStack/query#6611 .
I'll see if I can write a test to replicate that to see if its relevant.
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.
if observer.getCurrentResult() is stale you can probably try tapping into queryCache like above.
// Error handling is done in returnAtom, but first, current query result must be obtained. | ||
// | ||
// observer.currentResult() has outdated value, and observer.updateResult() doesn't help, | ||
// (I'm guessing that's due how observer.getOptimisticResult behaves with suspense = true) |
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.
I'm also exploring the option of making the atom a writable atom instead of a readonly atom and to use the write function to reset the query while resetting the error boundary. I think https://github.com/jotaijs/jotai-urql uses a similar pattern. Let me know what you think. |
350335a
to
82dac9a
Compare
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. |
TODO
debugPrivate
to atoms