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 networkStatus incorrectly reported as ready when using errorPolicy: 'all' with errors #12362

Merged
merged 19 commits into from
Mar 7, 2025

Conversation

jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented Feb 10, 2025

Fixes #12334

When calling observableQuery.getCurrentResult() when the errorPolicy was set to all, the networkStatus was incorrectly reporting the value as NetworkStatus.ready when there were errors returned in the result. This has now been corrected to return as NetworkStatus.error to match the value emitted from the observable.

This bug also affected useQuery and useLazyQuery since useQuery uses getCurrentResult under the hood.

Copy link

changeset-bot bot commented Feb 10, 2025

🦋 Changeset detected

Latest commit: 1576a09

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

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 38a4d1e6c82b9ebc2619afc3

Copy link

pkg-pr-new bot commented Feb 10, 2025

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

commit: 0a21f3b

Copy link

netlify bot commented Feb 10, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 4e08f3b
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67aa5f21b424f900087b1d49
😎 Deploy Preview https://deploy-preview-12362--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 10, 2025

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 41.27 KB (+0.05% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 50.71 KB (+0.03% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 47.79 KB (+0.05% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 36.25 KB (+0.04% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 33.64 KB (+0.04% 🔺)
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.89 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.55 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 5.38 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 4.04 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.47 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 4.12 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.43 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.38 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 Feb 10, 2025

Deploy Preview for apollo-client-docs ready!

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

loading: true,
networkStatus: NetworkStatus.loading,
loading: false,
networkStatus: NetworkStatus.error,
Copy link
Member Author

@jerelmiller jerelmiller Feb 10, 2025

Choose a reason for hiding this comment

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

This networkStatus might actually be legitimate since this is the loading state from the execute call. Looks like we just hold onto the error until the next request returns.

That said, its curious that we hold onto error here. In other cases (such as refetch) this error is reset until the next result comes back. This is different since we are calling execute again though which just re-evaluates the query against the fetch policy.

Should we be removing the error on this result in this case, or should we continue to handle this as-is? I think the loading state is the correct one here either way.

@jerelmiller jerelmiller removed the auto-cleanup 🤖 label Feb 11, 2025
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.

Looks good to me :)

@github-actions github-actions bot added the auto-cleanup 🤖 label Mar 7, 2025
@jerelmiller jerelmiller merged commit f6d387c into main Mar 7, 2025
36 checks passed
@jerelmiller jerelmiller deleted the jerel/fix-network-status branch March 7, 2025 17:04
@github-actions github-actions bot mentioned this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix inconsistency with networkStatus between emitted result and getCurrentResult for errorPolicy: 'all'
3 participants