Skip to content

Commit 5089516

Browse files
authored
add a react-server entry point, remove rehackt (#12438)
* add a `react-server` entry point * drop rehackt dependency * changeset * add `exports` test * small fixup * fix imports, skip some linter warnings * knip, chores
1 parent b86e50b commit 5089516

38 files changed

+184
-64
lines changed

.changeset/clean-sheep-hide.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@apollo/client": minor
3+
---
4+
5+
Drop `rehackt` dependency.
6+
We can now directly import from `react` without causing build errors in RSC.

.changeset/rare-houses-prove.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": minor
3+
---
4+
5+
Add `react-server` entry point with stubs for normal exports.

.size-limit.cjs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const checks = [
3232
brotli: true,
3333
ignore: [
3434
...(config.ignore || []),
35-
"rehackt",
3635
"react",
3736
"react-dom",
3837
"@graphql-typed-document-node/core",

.size-limits.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43200,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38700,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33359,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 28372
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 42782,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38120,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33090,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27946
66
}

config/apiExtractor.ts

+1-24
Original file line numberDiff line numberDiff line change
@@ -127,36 +127,13 @@ async function buildReport(
127127
})
128128
);
129129

130-
let succeededAdditionalChecks = true;
131-
if (fs.existsSync(extractorConfig.reportFilePath)) {
132-
const contents = readFileSync(extractorConfig.reportFilePath, "utf8");
133-
if (contents.includes("rehackt")) {
134-
succeededAdditionalChecks = false;
135-
console.error(
136-
"❗ %s contains a reference to the `rehackt` package!",
137-
extractorConfig.reportFilePath
138-
);
139-
}
140-
if (contents.includes('/// <reference types="react" />')) {
141-
succeededAdditionalChecks = false;
142-
console.error(
143-
"❗ %s contains a reference to the global `React` type!/n" +
144-
'Use `import type * as ReactTypes from "react";` instead',
145-
extractorConfig.reportFilePath
146-
);
147-
}
148-
}
149-
150-
if (extractorResult.succeeded && succeededAdditionalChecks) {
130+
if (extractorResult.succeeded) {
151131
console.log(`✅ API Extractor completed successfully`);
152132
} else {
153133
console.error(
154134
`❗ API Extractor completed with ${extractorResult.errorCount} errors` +
155135
` and ${extractorResult.warningCount} warnings`
156136
);
157-
if (!succeededAdditionalChecks) {
158-
console.error("Additional checks failed.");
159-
}
160137
process.exitCode = 1;
161138
}
162139
}

config/listImports.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* used via e.g.
3+
```sh
4+
node --experimental-transform-types --no-warnings --conditions 'react-server' config/listImports.ts @apollo/client/react
5+
```
6+
from `src/__tests__/exports.ts`
7+
*/
8+
import { registerHooks } from "node:module";
9+
10+
registerHooks({
11+
resolve(specifier, context, nextResolve) {
12+
try {
13+
return nextResolve(specifier, context);
14+
} catch (e) {
15+
if (specifier.endsWith(".js")) {
16+
for (const ext of [".ts", ".tsx"]) {
17+
return nextResolve(specifier.slice(0, -3) + ext, context);
18+
}
19+
}
20+
throw e;
21+
}
22+
},
23+
});
24+
25+
Object.keys(await import(process.argv[2]))
26+
.sort()
27+
.forEach((i) => console.log(i));

config/package.json

-3
This file was deleted.

knip.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const config = {
3939
".yalc/**/*",
4040
"config/schema.package.json.ts",
4141
"src/config/jest/resolver.ts",
42+
"config/listImports.ts",
4243
],
4344
ignoreBinaries: ["jq"],
4445
ignoreDependencies: [

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
"./link/utils": "./src/link/utils/index.ts",
5050
"./link/ws": "./src/link/ws/index.ts",
5151
"./masking": "./src/masking/index.ts",
52-
"./react": "./src/react/index.ts",
52+
"./react": {
53+
"react-server": "./src/react/index.react-server.ts",
54+
"default": "./src/react/index.ts"
55+
},
5356
"./react/context": "./src/react/context/index.ts",
5457
"./react/hooks": "./src/react/hooks/index.ts",
5558
"./react/internal": "./src/react/internal/index.ts",
@@ -149,7 +152,6 @@
149152
"@wry/trie": "^0.5.0",
150153
"graphql-tag": "^2.12.6",
151154
"optimism": "^0.18.0",
152-
"rehackt": "^0.1.0",
153155
"tslib": "^2.3.0"
154156
},
155157
"devDependencies": {

src/__tests__/__snapshots__/exports.ts.snap

+25
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,31 @@ Array [
270270
]
271271
`;
272272

273+
exports[`exports of public entry points @apollo/client/react with conditions [react-server] 1`] = `
274+
Array [
275+
"ApolloConsumer",
276+
"ApolloProvider",
277+
"DocumentType",
278+
"createQueryPreloader",
279+
"getApolloContext",
280+
"operationName",
281+
"parser",
282+
"useApolloClient",
283+
"useBackgroundQuery",
284+
"useFragment",
285+
"useLazyQuery",
286+
"useLoadableQuery",
287+
"useMutation",
288+
"useQuery",
289+
"useQueryRefHandlers",
290+
"useReactiveVar",
291+
"useReadQuery",
292+
"useSubscription",
293+
"useSuspenseFragment",
294+
"useSuspenseQuery",
295+
]
296+
`;
297+
273298
exports[`exports of public entry points @apollo/client/react/context 1`] = `
274299
Array [
275300
"ApolloConsumer",

src/__tests__/exports.ts

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// A) JSDOM doesn't yet support the TextEncoder/TextDecoder globals added in node 11, meaning certain imports (e.g. reactSSR) will fail (See https://github.com/jsdom/jsdom/issues/2524)
44
// B) We're just testing imports/exports, so no reason not to use Node for slightly better performance.
55

6+
import { resolve } from "node:path";
7+
8+
import { $ } from "zx";
9+
610
import * as client from "@apollo/client";
711
import * as cache from "@apollo/client/cache";
812
import * as core from "@apollo/client/core";
@@ -51,6 +55,18 @@ describe("exports of public entry points", () => {
5155
expect(Object.keys(ns).sort()).toMatchSnapshot();
5256
});
5357
}
58+
function checkWithConditions(id: string, conditions: string[]) {
59+
test(`${id} with conditions [${conditions.join(",")}]`, async () => {
60+
const exports = await $({
61+
cwd: resolve(__dirname, "../../"),
62+
})`node --experimental-transform-types --no-warnings ${conditions.flatMap(
63+
(condition) => [`--conditions`, condition]
64+
)} config/listImports.ts ${id}`;
65+
expect(
66+
exports.stdout.split("\n").filter((x) => x.trim() !== "")
67+
).toMatchSnapshot();
68+
});
69+
}
5470

5571
check("@apollo/client", client);
5672
check("@apollo/client/cache", cache);
@@ -87,6 +103,8 @@ describe("exports of public entry points", () => {
87103
check("@apollo/client/utilities/invariant", utilitiesInvariant);
88104
check("@apollo/client/utilities/environment", utilitiesEnvironment);
89105

106+
checkWithConditions("@apollo/client/react", ["react-server"]);
107+
90108
it("completeness", () => {
91109
const { join } = require("path").posix;
92110
entryPoints.forEach((info: Record<string, any>) => {

src/link/batch/batching.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Subscription } from "rxjs";
2-
import { Observable, EMPTY } from "rxjs";
2+
import { EMPTY, Observable } from "rxjs";
33

44
import type {
55
FetchResult,

src/react/context/ApolloConsumer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type * as ReactTypes from "react";
2-
import * as React from "rehackt";
2+
import * as React from "react";
33

44
import type { ApolloClient } from "@apollo/client/core";
55
import { invariant } from "@apollo/client/utilities/invariant";

src/react/context/ApolloContext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type * as ReactTypes from "react";
2-
import * as React from "rehackt";
2+
import * as React from "react";
33

44
import type { ApolloClient } from "@apollo/client/core";
55
import type { RenderPromises } from "@apollo/client/react/ssr";

src/react/context/ApolloProvider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type * as ReactTypes from "react";
2-
import * as React from "rehackt";
2+
import * as React from "react";
33

44
import type { ApolloClient } from "@apollo/client/core";
55
import { invariant } from "@apollo/client/utilities/invariant";

src/react/hooks/internal/__tests__/useRenderGuard.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable testing-library/render-result-naming-convention */
2-
import * as React from "rehackt";
32
import { render, waitFor } from "@testing-library/react";
3+
import * as React from "react";
44

55
import { useRenderGuard } from "../useRenderGuard.js";
66

src/react/hooks/internal/__use.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "rehackt";
1+
import * as React from "react";
22

33
import { wrapPromiseWithState } from "@apollo/client/utilities";
44

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { equal } from "@wry/equality";
22
import type { DependencyList } from "react";
3-
import * as React from "rehackt";
3+
import * as React from "react";
44

55
export function useDeepMemo<TValue>(
66
memoFn: () => TValue,
77
deps: DependencyList
88
) {
99
const ref = React.useRef<{ deps: DependencyList; value: TValue }>(void 0);
10-
10+
// eslint-disable-next-line react-compiler/react-compiler
1111
if (!ref.current || !equal(ref.current.deps, deps)) {
1212
// eslint-disable-next-line react-compiler/react-compiler
1313
ref.current = { value: memoFn(), deps };
1414
}
15-
15+
// eslint-disable-next-line react-compiler/react-compiler
1616
return ref.current.value;
1717
}

src/react/hooks/internal/useIsomorphicLayoutEffect.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "rehackt";
1+
import * as React from "react";
22

33
import { canUseDOM } from "@apollo/client/utilities";
44

src/react/hooks/internal/useRenderGuard.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "rehackt";
1+
import * as React from "react";
22

33
let Ctx: React.Context<null>;
44

src/react/hooks/useApolloClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "rehackt";
1+
import * as React from "react";
22

33
import type { ApolloClient } from "@apollo/client/core";
44
import { getApolloContext } from "@apollo/client/react/context";

src/react/hooks/useBackgroundQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "rehackt";
1+
import * as React from "react";
22

33
import { canonicalStringify } from "@apollo/client/cache";
44
import type {

src/react/hooks/useFragment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import equal from "@wry/equality";
2-
import * as React from "rehackt";
2+
import * as React from "react";
33

44
import type {
55
Cache,

src/react/hooks/useLazyQuery.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
22
import { equal } from "@wry/equality";
33
import type { DocumentNode } from "graphql";
4-
import * as React from "rehackt";
4+
import * as React from "react";
55

66
import type {
77
ApolloClient,
@@ -240,7 +240,6 @@ export function useLazyQuery<
240240
const previousData = resultRef.current?.data;
241241

242242
if (previousData && !equal(previousData, result.data)) {
243-
// eslint-disable-next-line react-compiler/react-compiler
244243
previousDataRef.current = previousData;
245244
}
246245

@@ -275,6 +274,7 @@ export function useLazyQuery<
275274
const eagerMethods = React.useMemo(() => {
276275
const eagerMethods: Record<string, any> = {};
277276
for (const key of EAGER_METHODS) {
277+
// eslint-disable-next-line react-compiler/react-compiler
278278
eagerMethods[key] = function () {
279279
invariant(
280280
resultRef.current,
@@ -373,9 +373,11 @@ export function useLazyQuery<
373373
...eagerMethods,
374374
...observableResult,
375375
client,
376+
// eslint-disable-next-line react-compiler/react-compiler
376377
previousData: previousDataRef.current,
377378
variables: observable.variables,
378379
observable,
380+
// eslint-disable-next-line react-compiler/react-compiler
379381
called: !!resultRef.current,
380382
}),
381383
[client, observableResult, eagerMethods, observable]

src/react/hooks/useLoadableQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "rehackt";
1+
import * as React from "react";
22

33
import { canonicalStringify } from "@apollo/client/cache";
44
import type {

src/react/hooks/useMutation.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
22
import { equal } from "@wry/equality";
33
import type { DocumentNode } from "graphql";
4-
import * as React from "rehackt";
4+
import * as React from "react";
55

66
import type {
77
ApolloCache,
@@ -231,7 +231,6 @@ export function useMutation<
231231

232232
React.useEffect(() => {
233233
const current = ref.current;
234-
// eslint-disable-next-line react-compiler/react-compiler
235234
current.isMounted = true;
236235

237236
return () => {

src/react/hooks/useQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
/** */
1818
import { equal } from "@wry/equality";
19-
import * as React from "rehackt";
19+
import * as React from "react";
2020
import { asapScheduler, observeOn } from "rxjs";
2121

2222
import type {

src/react/hooks/useQueryRefHandlers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "rehackt";
1+
import * as React from "react";
22

33
import type { OperationVariables } from "@apollo/client/core";
44
import type { SubscribeToMoreFunction } from "@apollo/client/core";

src/react/hooks/useReactiveVar.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "rehackt";
1+
import * as React from "react";
22

33
import type { ReactiveVar } from "@apollo/client/core";
44

src/react/hooks/useReadQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from "rehackt";
1+
import * as React from "react";
22

33
import type {
44
ApolloClient,

0 commit comments

Comments
 (0)