Skip to content

Commit a69327c

Browse files
committed
remove R19 exception from test, chores
1 parent fed117b commit a69327c

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
lines changed

.changeset/nasty-olives-act.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": minor
3+
---
4+
5+
Rewrite big parts of `useQuery` and `useLazyQuery` to be more compliant with the Rules of React and React Compiler

.size-limits.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"dist/apollo-client.min.cjs": 39604,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32852
2+
"dist/apollo-client.min.cjs": 39808,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32851
44
}

src/react/hooks/__tests__/useQuery.test.tsx

+1-28
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { useApolloClient } from "../useApolloClient";
3838
import { useLazyQuery } from "../useLazyQuery";
3939

4040
const IS_REACT_17 = React.version.startsWith("17");
41-
const IS_REACT_19 = React.version.startsWith("19");
4241

4342
describe("useQuery Hook", () => {
4443
describe("General use", () => {
@@ -1536,33 +1535,7 @@ describe("useQuery Hook", () => {
15361535

15371536
function checkObservableQueries(expectedLinkCount: number) {
15381537
const obsQueries = client.getObservableQueries("all");
1539-
/*
1540-
This is due to a timing change in React 19
1541-
1542-
In React 18, you observe this pattern:
1543-
1544-
1. render
1545-
2. useState initializer
1546-
3. component continues to render with first state
1547-
4. strictMode: render again
1548-
5. strictMode: call useState initializer again
1549-
6. component continues to render with second state
1550-
1551-
now, in React 19 it looks like this:
1552-
1553-
1. render
1554-
2. useState initializer
1555-
3. strictMode: call useState initializer again
1556-
4. component continues to render with one of these two states
1557-
5. strictMode: render again
1558-
6. component continues to render with the same state as during the first render
1559-
1560-
Since useQuery breaks the rules of React and mutably creates an ObservableQuery on the state during render if none is present, React 18 did create two, while React 19 only creates one.
1561-
1562-
This is pure coincidence though, and the useQuery rewrite that doesn't break the rules of hooks as much and creates the ObservableQuery as part of the state initializer will end up with behaviour closer to the old React 18 behaviour again.
1563-
1564-
*/
1565-
expect(obsQueries.size).toBe(IS_REACT_19 ? 1 : 2);
1538+
expect(obsQueries.size).toBe(2);
15661539

15671540
const activeSet = new Set<typeof result.current.observable>();
15681541
const inactiveSet = new Set<typeof result.current.observable>();

0 commit comments

Comments
 (0)