-
-
Notifications
You must be signed in to change notification settings - Fork 522
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
onResult does not fire on the first load of useLazyQuery #1543
Comments
Hello @minako-ph, I could not reproduce this issue. Can you please create a minimal repro either in a github repo or using codesandbox so the team can debug this issue? |
@nickmessing As an additional note, I found that downgrading to 4.0.0-beta.9 makes onResult work as expected on the first load, while upgrading to 4.0.0-beta.10 causes onResult to not fire only on the first load. I suspect the following change might be the cause: Please let me know if you need any further information. Thank you for your cooperation in resolving this issue. |
@minako-ph There's version 4.0.2, did you test on that? |
I upgraded from 4.0.0-beta.1 to 4.0.2 and noticed that the onResult stopped firing on the first load completion when using useLazyQuery. As a workaround, I tried downgrading the version. I found that it works up to 4.0.0-beta.9, but stops working from 4.0.0-beta.10 onwards. Here are the results of my testing:
|
Thank you for investing the time into this. Unfortunately as you can see I couldn't reproduce it in codesandbox (and locally). Sorry for the inconvenience |
I am using nuxt/apollo that package using this package , and meet same problem . May |
Describe the bug
When using
useLazyQuery
, theonResult
callback does not fire on the first execution of theload
function, even though theresult
is updated correctly.To Reproduce
Steps to reproduce the behavior:
useLazyQuery
as follows:onResult
callback:load
function based on a condition:Expected behavior
The
onResult
callback should be triggered whenever theresult
is updated, including on the first execution of theload
function.Versions
Additional context
The issue seems to be caused by a mismatch in the handling of asynchronous operations between
useLazyQuery
anduseQuery
.In
useLazyQuery
, the firstload
returns aPromise
that resolves when the query result is received. However, the resolution of thisPromise
does not directly trigger theonResult
callback defined inuseQuery
.In
useQuery
, theonResult
callback is triggered by awatch
on theresult
ref. However, thiswatch
does not react immediately to the changes made toresult
inside thePromise
returned byuseLazyQuery
'sload
function.As a result, although
myResult
is updated after the firstload
,onMyResult
is not triggered until the nextload
call.To resolve this issue, we might need to find a way to synchronize the state between
useLazyQuery
anduseQuery
, possibly by explicitly triggering thewatch
inuseQuery
afterresult
is updated inuseLazyQuery
, or by making thewatch
inuseQuery
aware of thePromise
returned byuseLazyQuery
.The text was updated successfully, but these errors were encountered: