QueryErrorResetBoundary not rest when i have enabled option #2930
Send to my agentDescribe the bug QueryErrorResetBoundary rest dont work with useQuery has changable 'enabled' option, I don't know if this is the correct behavior?
To Reproduce
just click try again button
demolink

Expected behavior i hope queryfn recall when i reset
Desktop (please complete the following information):
OS: MacOS Browser: Chrome Version: latest Smartphone (please complete the following information):
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser: [e.g. stock browser, safari]
- Version: [e.g. 22]
Additional context Add any other context about the problem here.
TkDodo added labelsbug
TkDodo closed this
:tada: This issue has been resolved in version 3.32.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
tannerlinsley added labelsreleased
@TkDodo This change made me think for some time,version 3.32.2 did solve my problem about this issue , But i find other problem in ohter case,sorry,i am not sure is this behavior right now ?
enbale: falsewithreftchfunction demo in fact ,I have some code like this, because i need to get something when i click button😞,am I usingreftchfunction incorrectly? or i should useuseMutationwhen i click buttonchange back to
falseif i change enable to true, I don't know if I can change back enable to false, seems like dependent-queries example,!!userIdfasle => ture => false, (if projects query's querykey dont include useId )I dont know what is right behavior if i change back to false,this one is a little confusing。
sorry ,my English is bad,i am a litter confusing about this.😵
what you would need to do is:
- have local state
- on button click, set that state
- disable the query when the state is falsy
I have forked your example here: https://codesandbox.io/s/refetch-with-enabled-false-forked-mmc9d?file=/src/index.js
However, you are right, the fix did introduce another "bug". Now,
disabledqueries that you run withrefetchwill never throw errors to an error boundary.I need to think about how to solve that, because in the original issue, we explicitly did not want disabled queries to throw, but now we do :/
what you would need to do is:
- have local state
- on button click, set that state
- disable the query when the state is falsy
I have forked your example here: codesandbox.io/s/refetch-with-enabled-false-forked-mmc9d?file=/src/index.js
@TkDodo Thanks for your help, i can do this to replace my
refetch. But i userefetchbeacausequeryKey: ['foo'],i need run queryFn when i click Button ,then queryFn is finish- second click Button,i can use
queryInstance.state === 'succeed'was directly get cache data - queryKey change to
queryKey: ['bar'] - then i click Button ,i can use
queryInstance.state === 'idle'to tell me should irefetchquery or get cache data
so if i use local state to do this, i should let
enablechange back to false when query is succeed, but we dont have api for get data callback(from cache or remote,i think i should't do effect inonSelectcallback) because i only need refetch when i click button, but if i userefetchmethod to do this, queryInstance always be disable.it seems like side effect.... useMutation dont have cache ,so i use useQuery to implement this feather
then i found
resetnot work with error cache. this behavior is really strange.However, you are right, the fix did introduce another "bug". Now,
disabledqueries that you run withrefetchwill never throw errors to an error boundary.I need to think about how to solve that, because in the original issue, we explicitly did not want disabled queries to throw, but now we do :/
I have no idea about this, not only
refetch, nowenable:falsebehavior is never throw error, but we just want not throw error when we runreset, so i think the problem is we should clear error cache when we runresetfunction?I edit demo code .you can see SecondCpt get error state in mount,but enable is false,the query state should be idle ? I think this behavior is most better .
btw: should i open a new issue or a discussions about this?
@WeiShengv99 can you test with this PR please: https://github.com/tannerlinsley/react-query/pull/2935
Sign in to join this conversation.
I think what happens is the following:
falseerrorstateloadingstate, but it doesn't because ofenabledit's a bit tricky. I think what should happen is that the query goes from
errortoidlestate because it's disabled and has no data yet. That way, we wouldn't re-throw the error. It could also potentially stay inerrorstate, but I think withuseErrorBoundary, we don't want queries in error state to actually render "normally" ...