Skip to content

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Sep 2, 2025

This fixes an error when invariant is called by external libraries and no dev error message handler is loaded.

As in that case, message will be a string and not a compiled-away number, error messages for invariant violations would now look like this, including a link:

Invariant Violation: An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#%7B%22version%22%3A%224.0.0%22%2C%22message%22%3A%22No%20apolloClientTransport%20defined%20on%20router%20context%22%2C%22args%22%3A%5B%5D%7D

For one, our error page couldn't display that (that part is already fixed), but also creating the link in the first place didn't make a lot of sense, since that string message could also just be printed out in the error message.


Verified with the pkg-pr-new build that no more urls are generated:

image

Copy link

changeset-bot bot commented Sep 2, 2025

🦋 Changeset detected

Latest commit: c11a112

The changes in this PR will be included in the next version bump.

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

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where invariant function calls from external libraries would generate unhelpful error messages with encoded URLs when no dev error message handler is loaded. The fix ensures that when the message is already a string, it gets formatted directly instead of being wrapped in a URL.

  • Adds string message handling to getFallbackErrorMsg function
  • Updates changeset documentation to describe the fix

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/utilities/invariant/index.ts Adds early return for string messages with proper argument substitution
.changeset/rare-months-camp.md Documents the bug fix in changeset

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@apollo-librarian
Copy link

apollo-librarian bot commented Sep 2, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: d74bcfb67748ad6397670eba
Build Logs: View logs

Copy link

pkg-pr-new bot commented Sep 2, 2025

npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@12899

commit: 681f9e7

Copy link
Contributor

github-actions bot commented Sep 2, 2025

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 42.82 KB (-0.08% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 37.8 KB (+0.11% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.66 KB (+0.06% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 26.85 KB (+0.07% 🔺)
import { ApolloProvider } from "@apollo/client/react" 5.91 KB (+0.2% 🔺)
import { ApolloProvider } from "@apollo/client/react" (production) 994 B (+3.44% 🔺)
import { useQuery } from "@apollo/client/react" 7.22 KB (+0.1% 🔺)
import { useQuery } from "@apollo/client/react" (production) 2.25 KB (+1.15% 🔺)
import { useLazyQuery } from "@apollo/client/react" 7.11 KB (+0.28% 🔺)
import { useLazyQuery } from "@apollo/client/react" (production) 2.16 KB (+1.29% 🔺)
import { useMutation } from "@apollo/client/react" 6.47 KB (+0.26% 🔺)
import { useMutation } from "@apollo/client/react" (production) 1.52 KB (+1.84% 🔺)
import { useSubscription } from "@apollo/client/react" 6.79 KB (+0.25% 🔺)
import { useSubscription } from "@apollo/client/react" (production) 1.81 KB (+1.26% 🔺)
import { useSuspenseQuery } from "@apollo/client/react" 8.55 KB (-0.04% 🔽)
import { useSuspenseQuery } from "@apollo/client/react" (production) 3.63 KB (+0.71% 🔺)
import { useBackgroundQuery } from "@apollo/client/react" 8.33 KB (+0.23% 🔺)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.4 KB (+0.5% 🔺)
import { useLoadableQuery } from "@apollo/client/react" 8.3 KB (+0.15% 🔺)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.39 KB (+0.79% 🔺)
import { useReadQuery } from "@apollo/client/react" 6.6 KB (+0.08% 🔺)
import { useReadQuery } from "@apollo/client/react" (production) 1.65 KB (+1.75% 🔺)
import { useFragment } from "@apollo/client/react" 6.66 KB (+0.36% 🔺)
import { useFragment } from "@apollo/client/react" (production) 1.71 KB (+1.04% 🔺)

@github-actions github-actions bot added the auto-cleanup 🤖 label Sep 2, 2025
@phryneas phryneas merged commit 5352c12 into main Sep 2, 2025
1 of 13 checks passed
@phryneas phryneas deleted the pr/invariant-string-handling branch September 2, 2025 15:59
@github-actions github-actions bot mentioned this pull request Sep 2, 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.

2 participants