Skip to content
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

3.5 hotfixes #9144

Merged
merged 7 commits into from
Dec 2, 2021
Merged

3.5 hotfixes #9144

merged 7 commits into from
Dec 2, 2021

Conversation

brainkim
Copy link
Contributor

@brainkim brainkim commented Nov 30, 2021

Review by commit.

Moves a bunch of logic directly in the render function where side effects shouldn’t be done, but we’re doing it because useEffect() is just not to be trusted.

Fixes #9111, #9135

… loops by useQuery in v3.5.x" in a test.

#9135
The test seems to be passing so we’re probably going to have to go in
blind.
There are instances in Apollo Studio where the execute function from
useMutation is placed in a useEffect dependency array for some reason.
The fact that the callback can change seems to cause React-185s. This
change makes the execute function the same for the lifetime of the
component.

This also incidentally seems to fix #9111 because we’re now updating the
ref directly in the render function. I dunno anymore.
An attempt to fix #9135. I was not able to create a unit test to
reproduce the bug. It seems like we just can’t rely on `useEffect()` for
certain parts of the hooks. The tests that changed just seem to be about
random legacy component timings.
@brainkim brainkim marked this pull request as ready for review December 2, 2021 16:32
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great (and we'll get the graphql HOC deprecated at some point 😬). Thanks for this @brainkim!

@brainkim brainkim merged commit 383ead2 into main Dec 2, 2021
@brainkim brainkim deleted the brian-3.5-triage branch December 2, 2021 17:39
Comment on lines +3558 to +3561
const client = new ApolloClient({
defaultOptions: {
watchQuery: {
pollInterval: 10,
Copy link
Member

@benjamn benjamn Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any risk this client will keep polling after the test finishes? Do we need to call client.stop() or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m pretty sure component teardown will clear the polling interval, which each test does?

Comment on lines +50 to +52
{
Object.assign(ref.current, { client, options, mutation });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these curly braces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I’ve just developed a weird habit where I’m putting bad-boy rendering “side-effects” in a single block. I can remove the block if you’d prefer.


// We assign options during rendering as a guard to make sure that
// callbacks like onCompleted and onError are not stale.
Object.assign(ref.current, { options });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Object.assign(ref.current, { options: obsQuery.options }), or are those objects guaranteed to be === here?

Copy link
Contributor Author

@brainkim brainkim Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options here are the ones passed into the call. obsQuery.options is not guaranteed to be up-to-date. This was preemptively done so that onError and onCompleted are never stale.

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brainkim Finished my review with a few comments to discuss (above). Thanks for jumping on this after the v3.5 release!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As of 3.5.0, useMutation onCompleted doesn't have the expected lexical scope
3 participants