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 issue where a merge function that returns an incomplete result would not allow the client to refetch from network #11839

Merged
merged 14 commits into from May 14, 2024

Conversation

jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented May 10, 2024

Fixes #11759

Modifies the logic added in #11579 which fixed an issue where a partial cache update caused it to be reported to a query that had an error. There were some situations in which a partial cache write should cause a refetch from the server in order to fulfill the data requirements in the query. The check from #11579 did not allow this to perform correctly as it assumed that all partial cache updates were "bad" and did not report them.

This change tweaks the check to only swallow the partial update if the query has previously errored, which maintains the change that #11579 was intending to fix. This reverts back to more closely resemble the logic from 3.9.4 which allowed the partial cache result to cause a network request.

Copy link

changeset-bot bot commented May 10, 2024

🦋 Changeset detected

Latest commit: a4750ee

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

Copy link
Contributor

github-actions bot commented May 10, 2024

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 38.65 KB (-0.02% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 47.42 KB (-0.02% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 44.99 KB (-0.02% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 34.2 KB (-0.02% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 32.05 KB (-0.02% 🔽)
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" 5.28 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.36 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.52 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.59 KB (0%)
import { useMutation } from "dist/react/index.js" 3.52 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.74 KB (0%)
import { useSubscription } from "dist/react/index.js" 3.21 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 2.4 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.44 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.1 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 4.96 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.61 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.07 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.72 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.33 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.27 KB (0%)
import { useFragment } from "dist/react/index.js" 2.29 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.23 KB (0%)

@jerelmiller
Copy link
Member Author

/release:pr

Copy link
Contributor

A new release has been made for this PR. You can install it with:

npm i @apollo/client@0.0.0-pr-11839-20240510211204

Copy link

netlify bot commented May 10, 2024

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 2100d30
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/663e8c8c0ca1780008e5cc11
😎 Deploy Preview https://deploy-preview-11839--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

netlify bot commented May 10, 2024

Deploy Preview for apollo-client-docs ready!

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

@@ -4281,6 +4281,543 @@ describe("useQuery Hook", () => {
await expect(Profiler).not.toRerender();
});

it("rerenders errored query for full cache write", async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is mainly a "documenting" test case since this behavior is currently built-in. I verified that we can write a full cache result to a query that had returned an error and have it re-render with the full cache result.

This may or may not be something we want to revisit in a future major since this has implications on UX, especially for overlapping queries.

await expect(Profiler).not.toRerender();
});

it("delivers the full network response when a merge function returns an incomplete result", async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is also a documenting test. I wanted to make sure we captured this as behavior in the client since I did not expect to see this behavior work.

// go and fetch the missing data.
!(oldDiff && oldDiff.complete)
) {
if (diff && !diff.complete && this.observableQuery?.getLastError()) {
Copy link
Member

@phryneas phryneas May 14, 2024

Choose a reason for hiding this comment

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

Wouldn't an update be okay in an error-but returnPartialData: true case?
Staying closer to the previous logic (although I'll admit I'm a bit hazy on some of it)

    if (
      diff &&
      !diff.complete &&
+    this.observableQuery?.getLastError() &&
      !this.observableQuery?.options.returnPartialData &&
      // In the case of a cache eviction, the diff will become partial so we
      // schedule a notification to send a network request (this.oqListener) to
      // go and fetch the missing data.
      !(oldDiff && oldDiff.complete)
    ) {

@github-actions github-actions bot added the auto-cleanup 🤖 label May 14, 2024
@phryneas
Copy link
Member

There's no perfect behaviour here, but this is probably less surprising.

@jerelmiller jerelmiller merged commit 6481fe1 into main May 14, 2024
33 checks passed
@jerelmiller jerelmiller deleted the jerel/issue-11759-partial-cache branch May 14, 2024 17:13
@github-actions github-actions bot mentioned this pull request May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in 3.9.5 with cache updates and error responses
2 participants