allow to auto-reset error in atomWithSuspenseQuery#75
allow to auto-reset error in atomWithSuspenseQuery#75grzesiek-ds wants to merge 1 commit intojotaijs:mainfrom
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.
_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.
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.
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.
|
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. |
|
@grzesiek-ds Is this PR still active? |
src/baseAtomWithQuery.ts
Outdated
|
|
||
| const clientAtom = atom(getQueryClient) | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| clientAtom.debugPrivate = true |
There was a problem hiding this comment.
debugPrivate is necessary here
TODO
debugPrivateto atoms