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

Dispose of the queryRef when changing to previously used variables to allow the InMemoryCache to determine cached behavior #11045

Merged
merged 55 commits into from
Jul 10, 2023

Conversation

jerelmiller
Copy link
Member

When changing variables to a previously used set of variables, the fetch policy is now correctly honored. Previously when using a fetch policy of network-only or no-cache, switching to previously used variables would return a cached result and would require a refetch to get data from the network again.

Now query refs are disposed of when changing variables so that switching back to previously used variables will either return from the InMemoryCache or will execute a network request to load from the server.

Checklist:

  • If this PR contains changes to the library itself (not necessary for e.g. docs updates), please include a changeset (see CONTRIBUTING.md)
  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@changeset-bot
Copy link

changeset-bot bot commented Jul 6, 2023

🦋 Changeset detected

Latest commit: ed724fb

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 Minor

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

@jerelmiller jerelmiller changed the title Dispose of the queryRef when changing variables to allow the InMemoryCache to determine cached behavior Dispose of the queryRef when changing to previously used variables to allow the InMemoryCache to determine cached behavior Jul 6, 2023
Base automatically changed from errors-in-deferred-chunks to release-3.8 July 7, 2023 22:12
@jerelmiller jerelmiller marked this pull request as ready for review July 8, 2023 00:08
@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2023

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 37 KB (+0.02% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 43.58 KB (+0.01% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 42.2 KB (+0.02% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 32.57 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 31.43 KB (0%)
import { ApolloProvider } from "dist/react/index.js" 1.23 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.22 KB (0%)
import { useQuery } from "dist/react/index.js" 4.26 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.08 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 4.58 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.39 KB (0%)
import { useMutation } from "dist/react/index.js" 2.5 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.48 KB (0%)
import { useSubscription } from "dist/react/index.js" 2.24 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 2.2 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 3.56 KB (-1.89% 🔽)
import { useSuspenseQuery } from "dist/react/index.js" (production) 2.98 KB (-2.22% 🔽)
import { useBackgroundQuery } from "dist/react/index.js" 3.88 KB (+0.08% 🔺)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.32 KB (+0.12% 🔺)
import { useReadQuery } from "dist/react/index.js" 2.66 KB (+2.1% 🔺)
import { useReadQuery } from "dist/react/index.js" (production) 2.64 KB (+2.12% 🔺)
import { useFragment } from "dist/react/index.js" 2.05 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2 KB (0%)

Copy link
Member

@phryneas phryneas left a comment

Choose a reason for hiding this comment

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

Generally approved - I left some comments with suggestions, but I'm fine with or without them.

src/react/cache/QueryReference.ts Outdated Show resolved Hide resolved
src/react/cache/QueryReference.ts Outdated Show resolved Hide resolved
@jerelmiller jerelmiller merged commit 9c1d4a1 into release-3.8 Jul 10, 2023
@jerelmiller jerelmiller deleted the switch-variables-caching branch July 10, 2023 16:38
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants