Skip to content

Commit 120805b

Browse files
committed
wip
1 parent 1f179fb commit 120805b

File tree

3 files changed

+151
-101
lines changed

3 files changed

+151
-101
lines changed

packages/react-urql/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@
4141
"prepublishOnly": "run-s clean build"
4242
},
4343
"devDependencies": {
44-
"@cypress/react": "^8.0.2",
44+
"@cypress/react": "^9.0.0",
4545
"@cypress/vite-dev-server": "^5.2.0",
46-
"@testing-library/react": "^16.0.1",
47-
"@types/react": "^18.3.8",
48-
"@types/react-test-renderer": "^17.0.1",
46+
"@testing-library/react": "^16.3.0",
47+
"@types/react": "^19.0.0",
48+
"@types/react-test-renderer": "^18.0.0",
4949
"@urql/core": "workspace:*",
5050
"cypress": "^13.14.0",
5151
"graphql": "^16.6.0",
52-
"react": "^18.3.1",
53-
"react-dom": "^18.3.1",
54-
"react-is": "^18.3.1",
55-
"react-ssr-prepass": "^1.5.0",
56-
"react-test-renderer": "^18.3.1"
52+
"react": "^19.0.0",
53+
"react-dom": "^19.0.0",
54+
"react-is": "^19.0.0",
55+
"react-ssr-prepass": "^1.6.0",
56+
"react-test-renderer": "^19.0.0"
5757
},
5858
"peerDependencies": {
5959
"@urql/core": "^6.0.0",

packages/react-urql/src/hooks/useQuery.cross-component-warning.test.tsx

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22

33
import React from 'react';
44
import { render } from '@testing-library/react';
5-
import { vi } from 'vitest';
5+
import { describe, it, beforeEach } from 'vitest';
6+
import { Client, cacheExchange, Operation, Exchange } from '@urql/core';
7+
import { delay, map, pipe } from 'wonka';
68

9+
import { Provider } from '../context';
710
import { useQuery } from './useQuery';
811

9-
// Mock the client so we can exercise useQuery without a real Client instance
10-
vi.mock('../context', async () => {
11-
const { fromValue } = await vi.importActual<typeof import('wonka')>('wonka');
12-
13-
const mock = {
14-
// Emit a synchronous result so the parent can quickly flip from loading to not loading
15-
executeQuery: vi.fn(() => fromValue({ data: { activeFeatureFlags: [] } })),
16-
} as const;
17-
18-
return {
19-
useClient: () => mock,
20-
};
21-
});
12+
const mockExchange: Exchange = () => ops$ => {
13+
return pipe(
14+
ops$,
15+
delay(100),
16+
map((operation: Operation) => ({
17+
operation,
18+
data: { activeFeatureFlags: [] },
19+
stale: false,
20+
hasNext: false,
21+
}))
22+
);
23+
};
2224

2325
function useFeature() {
2426
const [result] = useQuery({
@@ -45,12 +47,26 @@ function Repro() {
4547
return <ReproComponent />;
4648
}
4749

48-
describe('useQuery cross-component update warning', () => {
49-
it('does not warn when the same query is used in parent and child', () => {
50-
// Our global test setup throws when console.error is called.
51-
// If React emits "Cannot update a component ... while rendering a different component ...",
52-
// this render will throw and the test will fail, capturing the regression.
53-
render(<Repro />);
50+
describe('component update warning', () => {
51+
let client: Client;
52+
53+
beforeEach(() => {
54+
client = new Client({
55+
url: 'https://example.com/graphql',
56+
exchanges: [cacheExchange, mockExchange],
57+
});
5458
});
55-
});
5659

60+
it('does not warn when the same query is used in parent and child', async () => {
61+
const { findByText, debug } = render(
62+
<Provider value={client}>
63+
<Repro />
64+
</Provider>
65+
);
66+
67+
// Wait for the component to finish loading and render the child
68+
await findByText('Check console');
69+
70+
debug();
71+
});
72+
});

0 commit comments

Comments
 (0)