-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Weird query lifecycle transitions #38
Comments
I'm not sure why at first you're getting graphql-react/src/test/useGraphQL.mjs Line 75 in 1b1234d
|
Yeah, weird. Let me try to reproduce the issue in a codesandbox. If I'm doing something wrong I'll probably find out then. I'll keep you posted. |
@jaydenseric I was able to reproduce it in this codesandbox. |
Bear with me, but I think this may be working as intended. It's been a while since I dove deep into React hooks, exploring all the gotchas ( The first log of Now my memory may be hazy/wrong, but when multiple You do need to make sure you nest any JSX using |
Closing because I'm pretty sure everything is working as intended; the general rule is to account for const { loading, cacheValue = {} } = useGraphQL({
// …
}) https://github.com/jaydenseric/graphql-react/tree/v9.1.0#examples-8 I always do It's potentially useful to be able to tell when rendering if there is no cache for a particular query, so it's probably good to leave the API the way it is and not default |
I'm having the same issue and I did a reproductible example with the doc snippet fetching a Pokemon: https://codesandbox.io/s/gracious-leakey-hisdk As described by @olistic there is a state that imo should not happen:
As you can see in that CodeSandbox I don't think there is any external hook hijacking the render loop in the middle that could cause that. So it seems to come from |
@Grsmto are you using I plan to look into how these lifecycle gotchas can be improved when I start work on the next version; I've been working hard on other projects lately (several new testing related packages, and |
Thanks for your quick reply.
Actually as you can see in this codesandbox example, that's not the case: https://codesandbox.io/s/green-architecture-023dc Anyway I will try to have a look at the source code of the |
Use ReactDOM.unstable_batchedUpdates in the useGraphQL React hook to reduce the number of renders when loading completes, fixing #38 .
This should be improved in v10.0.0 🚀 |
Use ReactDOM.unstable_batchedUpdates in the useGraphQL React hook to reduce the number of renders when loading completes, fixing jaydenseric/graphql-react#38 .
Hey there! I discovered your library yesterday and decided to give it a try because I think its caching mechanism is superior to what graphql-hooks (what I'm currently using) offers.
What I'm doing
To make migration easier, I'm creating the following hook:
What I expect
Later, in my component I expect to be able to use
useQuery
like this:What actually happens
Blows up when trying to access
data.post.title
. I traced that down to the different valuesloading
,error
anddata
have during the query lifecycle:{ loading: false, error: undefined, data: undefined }
All three values are falsy at the beginning, thus provoking the issue I just mentioned with my component's code.
{ loading: true, error: undefined, data: undefined }
loading
is set totrue
whenload()
is called insideuseGraphQL
.{ loading: false, error: undefined, data: undefined }
When that finishes,
loading
returns tofalse
, but neithererror
nordata
are set (problematic, if you ask me).{ loading: false, error: undefined, data: {…} }
Finally,
data
is populated with the result of the GraphQL query.I would expect this sequence to be like this instead:
{ loading: true, error: undefined, data: undefined }
{ loading: false, error: undefined, data: {…} }
Am I doing something wrong in my
useQuery
hook? Is this the expected behavior?The text was updated successfully, but these errors were encountered: