Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(react-query): add support for react19 in v4 #8441

Open
wants to merge 23 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ jobs:
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- name: Run prettier
run: pnpm run test:format
test-react-17:
name: 'Test React 17'
test-react-version:
name: 'Test React Version'
runs-on: ubuntu-latest
strategy:
matrix:
react-version: [17, 18]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- uses: pnpm/[email protected]
with:
version: 8
Expand All @@ -118,12 +121,12 @@ jobs:
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v2
- name: Run Tests
- name: Run Tests for React ${{ matrix.react-version }}
uses: nick-fields/[email protected]
with:
timeout_minutes: 5
max_attempts: 3
command: npx nx affected --targets=test:lib --base=${{ github.event.pull_request.base.sha }}
env:
NX_CLOUD_DISTRIBUTED_EXECUTION: false
REACTJS_VERSION: 17
REACTJS_VERSION: ${{ matrix.react-version }}
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@
"@rollup/plugin-node-resolve": "^13.2.1",
"@rollup/plugin-replace": "^4.0.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.0.0",
"@testing-library/react": "^16.2.0",
"@testing-library/react-17": "npm:@testing-library/[email protected]",
"@testing-library/react-18": "npm:@testing-library/[email protected]",
"@testing-library/react-hooks": "^7.0.2",
"@testing-library/user-event": "14.4.3",
"@types/jest": "^26.0.4",
"@types/luxon": "^2.3.1",
"@types/node": "^17.0.25",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@types/semver": "^7.3.13",
"@types/testing-library__jest-dom": "^5.14.5",
"@typescript-eslint/eslint-plugin": "^5.41.0",
Expand Down Expand Up @@ -83,10 +84,12 @@
"nx-cloud": "16.3.0",
"prettier": "^2.6.2",
"prettier-plugin-svelte": "^2.9.0",
"react": "^18.2.0",
"react": "^19.0.0",
"react-17": "npm:react@^17.0.2",
"react-dom": "^18.2.0",
"react-18": "npm:react@^18.2.0",
"react-dom": "^19.0.0",
"react-dom-17": "npm:react-dom@^17.0.2",
"react-dom-18": "npm:react-dom@^18.2.0",
"rimraf": "^3.0.2",
"rollup": "^2.70.2",
"rollup-plugin-preserve-directives": "0.1.0",
Expand All @@ -102,6 +105,14 @@
"typescript": "^4.7.4",
"vue": "^3.2.33"
},
"pnpm": {
"overrides": {
"react": "18.2.0",
"react-dom": "18.2.0",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5"
}
},
Comment on lines +108 to +115
Copy link
Contributor Author

@gwansikk gwansikk Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test React 17 and 18, I had to use overrides.
Currently, react-query executes the test environment for each React version through PR-CI. However, since the version of @testing-library/react is fixed at React 19, errors occur due to breaking changes related to JSX and React.act.

'@testing-library/react-17':
  specifier: npm:@testing-library/[email protected]
  version: /@testing-library/[email protected]([email protected])([email protected]) # <<-- Fixed: React19
'@testing-library/react-18':
  specifier: npm:@testing-library/[email protected]
  version: /@testing-library/[email protected]([email protected])([email protected]) # <<-- Fixed: React19

"bundlewatch": {
"files": [
{
Expand Down
17 changes: 10 additions & 7 deletions packages/react-query-devtools/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@ notifyManager.setNotifyFunction((fn) => {
act(fn)
})

type ReactVersion = '18' | '17'
type ReactVersion = '19' | '18' | '17'

jest.mock('react', () => {
const packages = {
'18': 'react',
'19': 'react',
'18': 'react-18',
'17': 'react-17',
}
const version = (process.env.REACTJS_VERSION || '18') as ReactVersion
const version = (process.env.REACTJS_VERSION || '19') as ReactVersion

return jest.requireActual(packages[version]!)
})

jest.mock('react-dom', () => {
const packages = {
'18': 'react-dom',
'19': 'react-dom',
'18': 'react-dom-18',
'17': 'react-dom-17',
}
const version = (process.env.REACTJS_VERSION || '18') as ReactVersion
const version = (process.env.REACTJS_VERSION || '19') as ReactVersion

return jest.requireActual(packages[version])
})

jest.mock('@testing-library/react', () => {
const packages = {
'18': '@testing-library/react',
'19': '@testing-library/react',
'18': '@testing-library/react-18',
'17': '@testing-library/react-17',
}
const version = (process.env.REACTJS_VERSION || '18') as ReactVersion
const version = (process.env.REACTJS_VERSION || '19') as ReactVersion

return jest.requireActual(packages[version])
})
14 changes: 8 additions & 6 deletions packages/react-query-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
"build:types": "tsc --build && cp build/lib/index.d.ts build/lib/index.prod.d.ts"
},
"devDependencies": {
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@types/use-sync-external-store": "^0.0.3",
"react": "^18.2.0",
"react": "^19.0.0",
"react-17": "npm:react@^17.0.2",
"react-dom": "^18.2.0",
"react-18": "npm:react@^18.0.14",
"react-dom": "^19.0.0",
"react-dom-17": "npm:react-dom@^17.0.2",
"react-dom-18": "npm:react-dom@^18.2.0",
"react-error-boundary": "^3.1.4",
"@tanstack/react-query": "workspace:*"
},
Expand All @@ -66,8 +68,8 @@
"use-sync-external-store": "^1.2.0"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"@tanstack/react-query": "workspace:^"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ describe('ReactQueryDevtools', () => {
paddingRight: '20%',
}

function Parent({ children }: { children: React.ReactElement }) {
function Parent({ children }: { children: React.ReactNode }) {
return (
<div data-testid={parentElementTestid} style={parentPaddings}>
{children}
Expand Down
17 changes: 10 additions & 7 deletions packages/react-query-persist-client/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@ notifyManager.setNotifyFunction((fn) => {
act(fn)
})

type ReactVersion = '18' | '17'
type ReactVersion = '19' | '18' | '17'

jest.mock('react', () => {
const packages = {
'18': 'react',
'19': 'react',
'18': 'react-18',
'17': 'react-17',
}
const version = (process.env.REACTJS_VERSION || '18') as ReactVersion
const version = (process.env.REACTJS_VERSION || '19') as ReactVersion

return jest.requireActual(packages[version]!)
})

jest.mock('react-dom', () => {
const packages = {
'18': 'react-dom',
'19': 'react-dom',
'18': 'react-dom-18',
'17': 'react-dom-17',
}
const version = (process.env.REACTJS_VERSION || '18') as ReactVersion
const version = (process.env.REACTJS_VERSION || '19') as ReactVersion

return jest.requireActual(packages[version])
})

jest.mock('@testing-library/react', () => {
const packages = {
'18': '@testing-library/react',
'19': '@testing-library/react',
'18': '@testing-library/react-18',
'17': '@testing-library/react-17',
}
const version = (process.env.REACTJS_VERSION || '18') as ReactVersion
const version = (process.env.REACTJS_VERSION || '19') as ReactVersion

return jest.requireActual(packages[version])
})
10 changes: 6 additions & 4 deletions packages/react-query-persist-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
"build:types": "tsc --build"
},
"devDependencies": {
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"react": "^18.2.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"react": "^19.0.0",
"react-17": "npm:react@^17.0.2",
"react-dom": "^18.2.0",
"react-18": "npm:react@^18.0.14",
"react-dom": "^19.0.0",
"react-dom-17": "npm:react-dom@^17.0.2",
"react-dom-18": "npm:react-dom@^18.0.5",
"@tanstack/react-query": "workspace:*"
},
"dependencies": {
Expand Down
17 changes: 10 additions & 7 deletions packages/react-query/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@ notifyManager.setNotifyFunction((fn) => {
act(fn)
})

type ReactVersion = '18' | '17'
type ReactVersion = '19 ' | '18' | '17'

jest.mock('react', () => {
const packages = {
'18': 'react',
'19': 'react',
'18': 'react-18',
'17': 'react-17',
}
const version = (process.env.REACTJS_VERSION || '18') as ReactVersion
const version = (process.env.REACTJS_VERSION || '19') as ReactVersion

return jest.requireActual(packages[version]!)
})

jest.mock('react-dom', () => {
const packages = {
'18': 'react-dom',
'19': 'react-dom',
'18': 'react-dom-18',
'17': 'react-dom-17',
}
const version = (process.env.REACTJS_VERSION || '18') as ReactVersion
const version = (process.env.REACTJS_VERSION || '19') as ReactVersion

return jest.requireActual(packages[version])
})

jest.mock('@testing-library/react', () => {
const packages = {
'18': '@testing-library/react',
'19': '@testing-library/react',
'18': '@testing-library/react-18',
'17': '@testing-library/react-17',
}
const version = (process.env.REACTJS_VERSION || '18') as ReactVersion
const version = (process.env.REACTJS_VERSION || '19') as ReactVersion

return jest.requireActual(packages[version])
})
14 changes: 8 additions & 6 deletions packages/react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
],
"devDependencies": {
"@types/jscodeshift": "^0.11.3",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@types/use-sync-external-store": "^0.0.3",
"react": "^18.2.0",
"react": "^19.0.0",
"react-17": "npm:react@^17.0.2",
"react-dom": "^18.2.0",
"react-18": "npm:react@^18.2.0",
"react-dom": "^19.0.0",
"react-dom-17": "npm:react-dom@^17.0.2",
"react-dom-18": "npm:react-dom@^18.2.0",
"jscodeshift": "^0.13.1",
"react-error-boundary": "^3.1.4"
},
Expand All @@ -62,8 +64,8 @@
"use-sync-external-store": "^1.2.0"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-native": "*"
},
"peerDependenciesMeta": {
Expand Down
15 changes: 14 additions & 1 deletion packages/react-query/src/__tests__/ssr-hydration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,22 @@ import {
} from '..'
import { createQueryClient, setIsServer, sleep } from './utils'

const isReact18 = () => (process.env.REACTJS_VERSION || '18') === '18'
const isReact19 = () => (process.env.REACTJS_VERSION || '19') === '19'
const isReact18 = () => (process.env.REACTJS_VERSION || '19') === '18'

const ReactHydrate = (element: React.ReactElement, container: Element) => {
if (isReact19()) {
let root: any
// @ts-expect-error
React.act(() => {
// @ts-expect-error
root = ReactDOM.hydrateRoot(container, element)
})
return () => {
root.unmount()
}
}

if (isReact18()) {
let root: any
ReactDOMTestUtils.act(() => {
Expand Down
Loading
Loading