diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 57b25ee2..84a9aa4e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,9 +4,15 @@ on: paths: - "package/**" - "integration-test/**" + pull_request: + paths: + - "package/**" + - "integration-test/**" workflow_dispatch: jobs: test: + name: Run unit tests + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -18,6 +24,7 @@ jobs: - run: yarn workspace @apollo/experimental-nextjs-app-support run test > $GITHUB_STEP_SUMMARY tests_playwright: name: Run Playwright tests + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/package/package.json b/package/package.json index a4bd9bff..54a2f23c 100644 --- a/package/package.json +++ b/package/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/experimental-nextjs-app-support", - "version": "0.4.1", + "version": "0.4.3", "repository": { "url": "git+https://github.com/apollographql/apollo-client-nextjs" }, @@ -64,6 +64,7 @@ "react": "^18" }, "dependencies": { + "server-only": "^0.0.1", "superjson": "^1.12.2", "ts-invariant": "^0.10.3" } diff --git a/package/src/rsc/registerApolloClient.tsx b/package/src/rsc/registerApolloClient.tsx index 1051053e..65e717fc 100644 --- a/package/src/rsc/registerApolloClient.tsx +++ b/package/src/rsc/registerApolloClient.tsx @@ -1,18 +1,9 @@ +import "server-only"; + import type { ApolloClient } from "@apollo/client"; import * as React from "react"; -function assertRSC( - reactImport: typeof import("react") -): asserts reactImport is typeof import("react") & { cache(x: () => T): T } { - if ("createContext" in React) { - throw new Error( - "`registerApolloClient` should only be used in a React Server Component context - in Client Components, use the `ApolloNextAppProvider`!" - ); - } -} - export function registerApolloClient(makeClient: () => ApolloClient) { - assertRSC(React); const getClient = React.cache(makeClient); return { getClient, diff --git a/package/src/ssr/NextSSRApolloClient.tsx b/package/src/ssr/NextSSRApolloClient.tsx index 3a10b677..69fdc4aa 100644 --- a/package/src/ssr/NextSSRApolloClient.tsx +++ b/package/src/ssr/NextSSRApolloClient.tsx @@ -124,6 +124,7 @@ export class NextSSRApolloClient< ); }); + promise.finally(cleanup); byVariables.set( varJson, (observable = new Observable((observer) => { @@ -134,8 +135,7 @@ export class NextSSRApolloClient< }) .catch((err) => { observer.error(err); - }) - .finally(cleanup); + }); })) ); diff --git a/yarn.lock b/yarn.lock index f1f27b31..3498a7fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -126,6 +126,7 @@ __metadata: next: ^13.4.4 react: ^18.2.0 rimraf: ^5.0.0 + server-only: ^0.0.1 superjson: ^1.12.2 ts-invariant: ^0.10.3 ts-node: ^10.9.1