-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Ensure remounted components properly adhere to fetchPolicy
and nextFetchPolicy
#10239
Conversation
…nent is unmount and remounted
@@ -270,7 +270,6 @@ export class ObservableQuery< | |||
// terminates after a complete cache read, we can assume the next result | |||
// we receive will have NetworkStatus.ready and !loading. | |||
if ( | |||
diff.complete && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is already checked on line 264. To reduce noise, I went ahead and removed this since we already know its true
.
The more I work with this change, the less confident I feel in the solution. While I believe that using the argument passed to Given how much has been affected by this seemingly small change, it might be a signal that releasing an update such as this could have wide-ranging negative impacts. We can hope our tests catch 99% of them, but I'm not so sure. Something I've noticed while working on this fix is that many of our tests do not check for This change is what caused the unmount/remount bug, but I think @benjamn's reasoning for this change is sound and will help prevent other types of bugs. It feels a bit like a game of whack-a-mole at this point where fixing one thing seems to cause something else. At this point, I feel I might need to consider a different approach. Ultimately I think we should highly consider fixing the root issue where we are unable to get the correct data through the |
glad to see this is getting some attention, thanks @jerelmiller. if you get a fix out, even if its in an alpha build or something, i'll happily test it for you in a substantially sized application and report any problems I find (our multi hundred thousand line app basically exclusively uses this fetch policy combo + "no-cache" in a few instances). |
@dairyisscary sounds great! I've stepped away from this a bit as I've been focused on adding suspense support to the client, but I'm hopeful I can come back to this sometime soon to come up with a better solution than whats in this PR. |
It appears this was fixed by #10631 and is no longer needed. I'm going to go ahead and close this out as this issue has already been solved. |
Fixes #10222
This fix ensures the
fetchPolicy
andnextFetchPolicy
is properly adhered to when a component unmounts, then remounts. In v3.6.8 and below, afetchPolicy
ofnetwork-only
andnextFetchPolicy
ofcache-first
would properly return the loading state when remounted. In v3.6.9 and above, a remounted component would return cached data too early due to a change in #9823 that synchronously updated thefetchPolicy
as soon as the initial query was kicked off.Internally, we were using
observableQuery.getCurrentResult()
in ouronNext
function passed to the subscription to get the result of the query, rather than relying on the argument passed toonNext
. This meant in some cases whereonNext
was triggered, we were callingobservableQuery.getCurrentResult()
with a fetch policy that had already been changed to thenextFetchPolicy
, therefore we were returning cached data too early (in other words, thenetwork-only
result hadn't yet finished loading).I opted to patch
useQuery
with some of the behavior inobservableQuery.getCurrentResult()
to try and limit the blast radius of the changes. The patch really should be a part ofQueryManager
, but I didn't know how how many people rely on the current behavior in how results are returned (which differ fromobservableQuery.getCurrentResult()
.