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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

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: 613d2f0

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: bc92e701cf27e9de5ac502d0

Copy link

pkg-pr-new bot commented Feb 10, 2025

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

commit: 613d2f0

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.26 KB (+0.05% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 50.7 KB (+0.03% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 47.78 KB (+0.04% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 36.26 KB (+0.04% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 33.65 KB (+0.05% 🔺)
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%)

Copy link

netlify bot commented Feb 10, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 613d2f0
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67ae58b2d659170008a1caad
😎 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
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.

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