Skip to content

Commit c1c0fb9

Browse files
authored
Allow using the browser build of ApolloNextAppProvider outside of Next.js, e.g. for tests. (#284)
* Allow using the browser build of `ApolloNextAppProvider` outside of Next.js, e.g. for tests. * update lockfiles * more lockfile updates * slight refactor * message
1 parent 882b4ed commit c1c0fb9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

integration-test/yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ __metadata:
3232
linkType: hard
3333

3434
"@apollo/client-react-streaming@exec:./shared/build-client-react-streaming.cjs::locator=%40integration-test%2Froot%40workspace%3A.":
35-
version: 0.8.0
35+
version: 0.10.0
3636
resolution: "@apollo/client-react-streaming@exec:./shared/build-client-react-streaming.cjs#./shared/build-client-react-streaming.cjs::hash=48b117&locator=%40integration-test%2Froot%40workspace%3A."
3737
dependencies:
3838
superjson: "npm:^1.12.2 || ^2.0.0"
3939
ts-invariant: "npm:^0.10.3"
4040
peerDependencies:
41-
"@apollo/client": ^3.9.0
41+
"@apollo/client": ^3.9.6
4242
react: ^18
4343
checksum: 10/8e12155ebcb9672f5b645c364d356018014df750412c61613341121ebb4d4eabb5f42cd9018cc3a81ad988f1b425548d68254ca49ede19c31d0d9e5a9a4f240a
4444
languageName: node
@@ -82,12 +82,12 @@ __metadata:
8282
linkType: hard
8383

8484
"@apollo/experimental-nextjs-app-support@exec:./shared/build-experimental-nextjs-app-support.cjs::locator=%40integration-test%2Froot%40workspace%3A.":
85-
version: 0.8.0
85+
version: 0.10.0
8686
resolution: "@apollo/experimental-nextjs-app-support@exec:./shared/build-experimental-nextjs-app-support.cjs#./shared/build-experimental-nextjs-app-support.cjs::hash=fd83cc&locator=%40integration-test%2Froot%40workspace%3A."
8787
dependencies:
88-
"@apollo/client-react-streaming": "npm:^0.9.0"
88+
"@apollo/client-react-streaming": "npm:0.10.0"
8989
peerDependencies:
90-
"@apollo/client": ^3.9.0
90+
"@apollo/client": ^3.9.6
9191
next: ^13.4.1 || ^14.0.0
9292
react: ^18
9393
checksum: 10/505b723bac0f3a7f15287ea32fab9f2e8c0cd567149abf11d750855f8a9bfc0aa26e44179ad10c32f7d162ad86318717032413ef8e1a25385185178e022588fa

packages/experimental-nextjs-app-support/src/ApolloNextAppProvider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ export const ApolloNextAppProvider = /*#__PURE__*/ WrapApolloProvider(
4646
useInsertHtml() {
4747
const insertHtml = useContext(ServerInsertedHTMLContext);
4848
if (!insertHtml) {
49+
if (process.env.REACT_ENV === "browser") {
50+
//Allow using the browser build of ApolloNextAppProvider outside of Next.js, e.g. for tests.
51+
return () => {};
52+
}
4953
throw new Error(
50-
"ApolloNextAppProvider cannot be used outside of the Next App Router!"
54+
"The SSR build of ApolloNextAppProvider cannot be used outside of the Next App Router!\n" +
55+
'If you encounter this in a test, make sure that your tests are using the browser build by adding the "browser" import condition to your test setup.'
5156
);
5257
}
5358
return insertHtml;

0 commit comments

Comments
 (0)