-
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
POC reproduction of Issue #9204 #9407
POC reproduction of Issue #9204 #9407
Conversation
…the component re-renders
@jamesopti: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
@@ -219,8 +221,7 @@ export function useQuery< | |||
return () => subscription.unsubscribe(); | |||
}, [obsQuery, context.renderPromises, client.disableNetworkFetches]); | |||
|
|||
let partial: boolean | undefined; | |||
({ partial, ...result } = result); |
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.
I have to assume there was a reason for doing this that I don't understand, but it is one of the underlying causes of the loss of identity stability in the return value.
The result of the change here is that result
continues to include the partial
field, but it could be removed and maintain identity stability via delete result.partial
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 got fixed in PR #9459, and now works without rebinding any variables:
apollo-client/src/react/hooks/useQuery.ts
Line 454 in 3860b1f
const { data, partial, ...resultWithoutPartial } = result; |
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.
@jamesopti Thanks so much for submitting these test cases, and for making actual progress on fixing them. I cherry-picked your test cases and initial fixes into my PR #9459, which we just merged into release-3.6
and published in @apollo/[email protected]
, so you should be able to test the changes in your app(s) by running npm i @apollo/client@beta
. Let us know how it goes!
const watchQueryOptions = useMemo( | ||
() => createWatchQueryOptions(query, options, defaultWatchQueryOptions), | ||
[query, options, defaultWatchQueryOptions] | ||
) |
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.
One fun bug: this useMemo
works great as long as options
is undefined (just useQuery(query)
), but as soon as you call useQuery(query, {...})
with options, that's a fresh object for useMemo
, so watchQueryOptions
gets regenerated with every useMemo
call.
@@ -219,8 +221,7 @@ export function useQuery< | |||
return () => subscription.unsubscribe(); | |||
}, [obsQuery, context.renderPromises, client.disableNetworkFetches]); | |||
|
|||
let partial: boolean | undefined; | |||
({ partial, ...result } = result); |
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 got fixed in PR #9459, and now works without rebinding any variables:
apollo-client/src/react/hooks/useQuery.ts
Line 454 in 3860b1f
const { data, partial, ...resultWithoutPartial } = result; |
Closing because these commits were incorporated into #9459, which has been merged into |
Checklist:
Confirmed this test fails with an infinite loop in v3.5.8 and passes in v3.4.17