Skip to content

Commit 5352c12

Browse files
authored
Fix an issue when invariant is called by external libraries when no dev error message handler is loaded. (#12899)
* Fix an issue when `invariant` is called by external libraries when no dev error message handler is loaded. * Clean up Prettier, Size-limit, and Api-Extractor --------- Co-authored-by: phryneas <4282439+phryneas@users.noreply.github.com>
1 parent c0d5be7 commit 5352c12

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.changeset/rare-months-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Fix an issue when `invariant` is called by external libraries when no dev error message handler is loaded.

.size-limits.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43878,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38665,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33423,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27476
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43845,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38704,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33443,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27495
66
}

src/utilities/invariant/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ function getFallbackErrorMsg(
122122
messageArgs: unknown[] = []
123123
) {
124124
if (!message) return;
125+
if (typeof message === "string") {
126+
return messageArgs.reduce<string>(
127+
(msg, arg) => msg.replace(/%[sdfo]/, stringify(arg)),
128+
message
129+
);
130+
}
125131
return `An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#${encodeURIComponent(
126132
JSON.stringify({
127133
version,

0 commit comments

Comments
 (0)