Skip to content

Conversation

@grzesiek-ds
Copy link

@grzesiek-ds grzesiek-ds commented Mar 12, 2024

TODO

  • Remove comments
  • Add debugPrivate to atoms

@grzesiek-ds grzesiek-ds force-pushed the suggested-base-query-atom-changes branch from 03535ed to 350335a Compare March 12, 2024 20:58
Comment on lines +186 to +193
// 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
)
Copy link
Author

@grzesiek-ds grzesiek-ds Mar 12, 2024

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

Copy link
Collaborator

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.

Copy link
Collaborator

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)
Copy link
Author

Choose a reason for hiding this comment

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

@kalijonn
Copy link
Collaborator

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.

@grzesiek-ds grzesiek-ds force-pushed the suggested-base-query-atom-changes branch from 350335a to 82dac9a Compare April 12, 2024 11:38
@codesandbox-ci
Copy link

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.

@ThaddeusJiang
Copy link
Collaborator

@grzesiek-ds Is this PR still active?


const clientAtom = atom(getQueryClient)
if (process.env.NODE_ENV !== 'production') {
clientAtom.debugPrivate = true
Copy link
Member

Choose a reason for hiding this comment

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

debugPrivate is necessary here

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.

4 participants