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

keep deferred inFlightLinkObservables until the response is finished #12338

Merged
merged 5 commits into from
Feb 6, 2025

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Feb 4, 2025

An experiment. This might be required for query streaming with @defer and useSuspenseQuery.

Copy link

changeset-bot bot commented Feb 4, 2025

🦋 Changeset detected

Latest commit: b201bc0

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 Feb 4, 2025

⚠️ Docs preview not attached to branch

The preview was not built because the PR's base branch release-3.13 is not in the list of sources.

An Apollo team member can comment one of the following commands to dictate which branch to attach the preview to:

  • !docs set-base-branch version-2.6
  • !docs set-base-branch main

Build ID: cc19e4a82fbc673e4b124e13

Copy link

pkg-pr-new bot commented Feb 4, 2025

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

commit: b201bc0

Copy link

netlify bot commented Feb 4, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit b201bc0
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67a4a3f11cee2c0008cefa23
😎 Deploy Preview https://deploy-preview-12338--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.

Copy link
Contributor

github-actions bot commented Feb 4, 2025

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 41.24 KB (+0.07% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 50.68 KB (+0.06% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 47.75 KB (+0.06% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 36.24 KB (+0.09% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 33.63 KB (+0.08% 🔺)
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%)
import { useQuery } from "dist/react/index.js" (production) 4.29 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.7 KB (0%)
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.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%)

@phryneas phryneas changed the base branch from main to release-3.13 February 6, 2025 09:58
@phryneas
Copy link
Member Author

phryneas commented Feb 6, 2025

I have verified over in apollographql/apollo-client-nextjs#424 that this is exactly what this needs.

Gonna polish this PR, add a few tests and then we should get this into 3.13.

@phryneas phryneas force-pushed the pr/keep-deferred-inFlightLinkObservables branch from b0183ec to b201bc0 Compare February 6, 2025 11:58
@phryneas
Copy link
Member Author

phryneas commented Feb 6, 2025

Added a test, this should be ready for review.

@phryneas phryneas marked this pull request as ready for review February 6, 2025 12:05
@phryneas phryneas requested a review from jerelmiller February 6, 2025 12:05
Comment on lines +1185 to +1190
concast.beforeNext(function cb(method, arg: FetchResult) {
if (method === "next" && "hasNext" in arg && arg.hasNext) {
concast.beforeNext(cb);
} else {
inFlightLinkObservables.remove(printedServerQuery, varJson);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this change right now applies to @defer etc., but not to subscriptions.
Changing that for subscriptions would be nice, but feels a bit more breaking, so I think we should probably do that in 4.0 - WDYT @jerelmiller ?

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense to me. I see no reason why two subscriptions kicked off with the same document/variables shouldn't be deduped, especially since it can be disabled per-subscription if need be. Mind making a tracking issue and putting it in the milestone so that we don't forget to update?

Copy link
Member Author

Choose a reason for hiding this comment

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

#12348 👍

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.

Fantastic test addition that demonstrates all the things I was hoping to see. Thanks for getting this done!

@github-actions github-actions bot added the auto-cleanup 🤖 label Feb 6, 2025
@jerelmiller jerelmiller merged commit 67c16c9 into release-3.13 Feb 6, 2025
54 checks passed
@jerelmiller jerelmiller deleted the pr/keep-deferred-inFlightLinkObservables branch February 6, 2025 16:45
@github-actions github-actions bot mentioned this pull request Feb 6, 2025
@phryneas
Copy link
Member Author

phryneas commented Feb 6, 2025

Fantastic test addition that demonstrates all the things I was hoping to see. Thanks for getting this done!

We're getting to a point where we have all the tools in place that writing these tests is actually fun :)

@github-actions github-actions bot mentioned this pull request Feb 13, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants