Skip to content

Commit

Permalink
Allow using the browser build of ApolloNextAppProvider outside of N…
Browse files Browse the repository at this point in the history
…ext.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
  • Loading branch information
phryneas authored May 8, 2024
1 parent 882b4ed commit c1c0fb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions integration-test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ __metadata:
linkType: hard

"@apollo/client-react-streaming@exec:./shared/build-client-react-streaming.cjs::locator=%40integration-test%2Froot%40workspace%3A.":
version: 0.8.0
version: 0.10.0
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."
dependencies:
superjson: "npm:^1.12.2 || ^2.0.0"
ts-invariant: "npm:^0.10.3"
peerDependencies:
"@apollo/client": ^3.9.0
"@apollo/client": ^3.9.6
react: ^18
checksum: 10/8e12155ebcb9672f5b645c364d356018014df750412c61613341121ebb4d4eabb5f42cd9018cc3a81ad988f1b425548d68254ca49ede19c31d0d9e5a9a4f240a
languageName: node
Expand Down Expand Up @@ -82,12 +82,12 @@ __metadata:
linkType: hard

"@apollo/experimental-nextjs-app-support@exec:./shared/build-experimental-nextjs-app-support.cjs::locator=%40integration-test%2Froot%40workspace%3A.":
version: 0.8.0
version: 0.10.0
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."
dependencies:
"@apollo/client-react-streaming": "npm:^0.9.0"
"@apollo/client-react-streaming": "npm:0.10.0"
peerDependencies:
"@apollo/client": ^3.9.0
"@apollo/client": ^3.9.6
next: ^13.4.1 || ^14.0.0
react: ^18
checksum: 10/505b723bac0f3a7f15287ea32fab9f2e8c0cd567149abf11d750855f8a9bfc0aa26e44179ad10c32f7d162ad86318717032413ef8e1a25385185178e022588fa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ export const ApolloNextAppProvider = /*#__PURE__*/ WrapApolloProvider(
useInsertHtml() {
const insertHtml = useContext(ServerInsertedHTMLContext);
if (!insertHtml) {
if (process.env.REACT_ENV === "browser") {
//Allow using the browser build of ApolloNextAppProvider outside of Next.js, e.g. for tests.
return () => {};
}
throw new Error(
"ApolloNextAppProvider cannot be used outside of the Next App Router!"
"The SSR build of ApolloNextAppProvider cannot be used outside of the Next App Router!\n" +
'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.'
);
}
return insertHtml;
Expand Down

0 comments on commit c1c0fb9

Please sign in to comment.