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

Fix a timing problem where useQuery would execute an outdated callback reference. #12319

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Jan 29, 2025

This changes the timing to save the callbacks to the ref ever so slightly sooner.
By my testing in the user-supplied reproduction, this fixes #12316 where a cache hit would have triggered setResult before the callback ref could have been updated.

Copy link

changeset-bot bot commented Jan 29, 2025

🦋 Changeset detected

Latest commit: 134e5c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svc-apollo-docs
Copy link

svc-apollo-docs commented Jan 29, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 1 changed, 0 removed
* (developer-tools)/react/(latest)/data/fragments.mdx

Build ID: b50330828fc68f6022ef305c

URL: https://www.apollographql.com/docs/deploy-preview/b50330828fc68f6022ef305c

Copy link

pkg-pr-new bot commented Jan 29, 2025

npm i https://pkg.pr.new/@apollo/client@12319

commit: 134e5c3

Copy link
Contributor

github-actions bot commented Jan 29, 2025

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 40.67 KB (+0.01% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 50.08 KB (+0.01% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 47.2 KB (+0.01% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 36.18 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 33.58 KB (0%)
import { ApolloProvider } from "dist/react/index.js" 1.26 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.24 KB (0%)
import { useQuery } from "dist/react/index.js" 5.21 KB (+0.02% 🔺)
import { useQuery } from "dist/react/index.js" (production) 4.29 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.7 KB (+0.02% 🔺)
import { useLazyQuery } from "dist/react/index.js" (production) 4.78 KB (0%)
import { useMutation } from "dist/react/index.js" 3.62 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.84 KB (0%)
import { useSubscription } from "dist/react/index.js" 4.42 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 3.48 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.51 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.17 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 5.01 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.66 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.09 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.74 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.41 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.35 KB (0%)
import { useFragment } from "dist/react/index.js" 2.36 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.31 KB (0%)

Copy link

netlify bot commented Jan 29, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 134e5c3
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/6799f0559edbc00008be1111
😎 Deploy Preview https://deploy-preview-12319--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@phryneas phryneas changed the title attempt to alleviate #12316 Fix a timing problem where useQuery would execute an outdated callback reference. Jan 29, 2025
@phryneas phryneas requested a review from jerelmiller January 29, 2025 09:09
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

Approved assuming this fixes the reported issue

@jerelmiller
Copy link
Member

Given that we will be deprecating onCompleted, can we close this?

@phryneas
Copy link
Member Author

@jerelmiller It might at least make the bug trigger a bit less, and it doesn't add a lot of bundle size, so I'd suggest we still ship this - it just doesn't hurt.

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

Successfully merging this pull request may close these issues.

useQuery onCompleted callback is one render out of date
3 participants