apollo-client: useLazyQuery throw error when error data is null or undefined
Issue Description
After I upgraded to version 3.8, I noticed that if I call the function returned by useLazyQuery hook and the data
field of the error is null
, my app instantly crash even if I wrapped the function call in try
and catch
block.
Link to Reproduction
https://github.com/quocluongha/rn-apollo-test
Reproduction Steps
- Install React Native CLI.
- Run
npm install
oryarn install
. - Run
npm run start
oryarn start
. - Run
npm run android
/yarn android
for Android ornpm run ios
/yarn ios
for iOS. - Press the “Get Data” button.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 23 (9 by maintainers)
@quocluongha thanks for the ping! I have to admit, I missed your reproduction - when you originally filed the issue, I was on vacation (I’m @plausible-phry), and I scrolled by it every time after.
With your reproduction, I can see the error, and it seems to be an internal timing problem that for some curious reason only happens in React Native.
I am working on a fix (still digging for the original reason of this!), but here is a workaround you can already use: you need to add a link that slightly delays the
onComplete
callback:This seemed to fix the error for me.
I’ll give it a try tomorrow!
I think I might have solved this.
Could you please try the build from #11249 ?
In our case we are using
onError
callback. It seems I need to delay on Error as well. I feel like it’s related to Hermes engine. @phryneas