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

experiment: keep ObservableQuery initiated from useQuery inactive before first subscription #12285

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

phryneas
Copy link
Member

Triggered by this Discord discussion

Generally, creating a ObservableQuery via watchQuery is already a side effect and adds the query to QueryManager.queries - and it will only be removed if it is subscribed and then unsubscribed.

There might be a number of edge-case scenarios where that is not the case, so this is an attempt from a different angle to solve this problem.

Copy link

changeset-bot bot commented Jan 21, 2025

🦋 Changeset detected

Latest commit: b4a06cc

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 21, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 96e5a3c4927b0e8781ac095b

Copy link

netlify bot commented Jan 21, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit b4a06cc
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67b323cc203cef0008e1d4f0
😎 Deploy Preview https://deploy-preview-12285--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 force-pushed the pr/inactiveBeforeSubscription branch from 507624d to ff3c4bd Compare January 21, 2025 11:32
Copy link

pkg-pr-new bot commented Jan 21, 2025

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

commit: b4a06cc

Copy link
Contributor

github-actions bot commented Jan 21, 2025

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 41.3 KB (+0.16% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 50.77 KB (+0.17% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 47.85 KB (+0.19% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 36.29 KB (+0.16% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 33.69 KB (+0.19% 🔺)
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" 9.92 KB (+90.35% 🔺)
import { useQuery } from "dist/react/index.js" (production) 8.84 KB (+105.83% 🔺)
import { useLazyQuery } from "dist/react/index.js" 10.39 KB (+82.16% 🔺)
import { useLazyQuery } from "dist/react/index.js" (production) 9.31 KB (+94.79% 🔺)
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.03% 🔺)
import { useSubscription } from "dist/react/index.js" (production) 3.48 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.88 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.54 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 5.37 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 4.03 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.45 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 4.11 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.42 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.36 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%)

@nikdimm
Copy link

nikdimm commented Jan 21, 2025

@nikdimm

@phryneas
Copy link
Member Author

There is one point I'm a bit concerned about, and that's this:

private getQuery(queryId: string): QueryInfo {
if (queryId && !this.queries.has(queryId)) {
this.queries.set(queryId, new QueryInfo(this, queryId));
}
return this.queries.get(queryId)!;
}

That means that if we delay registration like this and for whatever reason getQuery gets called (e.g. by a refetch call before the subscription started), a new QueryInfo that doesn't match the QueryInfo from the ObservableQuery gets injected.

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.

3 participants