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

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
chore: react overrides
  • Loading branch information
gwansikk committed Jan 28, 2025
commit 2c1cc8668fbf00b1b80220f4a6e18bc2c80ce169
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,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
4 changes: 2 additions & 2 deletions packages/react-query-devtools/src/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type Entry = {
}

type RendererProps = {
handleEntry: (entry: Entry) => React.JSX.Element
handleEntry: (entry: Entry) => JSX.Element
label?: string
value: unknown
subEntries: Entry[]
Expand Down Expand Up @@ -220,7 +220,7 @@ export function chunkArray<T>(array: T[], size: number): T[][] {
return result
}

type Renderer = (props: RendererProps) => React.JSX.Element
type Renderer = (props: RendererProps) => JSX.Element

export const DefaultRenderer: Renderer = ({
handleEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const PersistQueryClientProvider = ({
persistOptions,
onSuccess,
...props
}: PersistQueryClientProviderProps): React.JSX.Element => {
}: PersistQueryClientProviderProps): JSX.Element => {
const [isRestoring, setIsRestoring] = React.useState(true)
const refs = React.useRef({ persistOptions, onSuccess })
const didRestore = React.useRef(false)
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/QueryClientProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const QueryClientProvider = ({
children,
context,
contextSharing = false,
}: QueryClientProviderProps): React.JSX.Element => {
}: QueryClientProviderProps): JSX.Element => {
React.useEffect(() => {
client.mount()
return () => {
Expand Down
33 changes: 22 additions & 11 deletions packages/react-query/src/__tests__/ssr-hydration.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as React from 'react'
import ReactDOM from 'react-dom'
import ReactDOMTestUtils from 'react-dom/test-utils'
import ReactDOMServer from 'react-dom/server'
// eslint-disable-next-line import/no-unresolved -- types only for module augmentation
import type {} from 'react-dom/next'

import {
QueryCache,
Expand All @@ -11,28 +14,36 @@ import {
} from '..'
import { createQueryClient, setIsServer, sleep } from './utils'

const isReact17 = () => (process.env.REACTJS_VERSION || '17') === '17'
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 (isReact17()) {
if (isReact19()) {
let root: any
// @ts-expect-error
React.act(() => {
// @ts-expect-error
ReactDOM.hydrate(element, container)
root = ReactDOM.hydrateRoot(container, element)
})
return () => {
root.unmount()
}
}

if (isReact18()) {
let root: any
ReactDOMTestUtils.act(() => {
// @ts-expect-error
ReactDOM.unmountComponentAtNode(container)
root = ReactDOM.hydrateRoot(container, element)
})
return () => {
root.unmount()
}
}

let root: any
React.act(() => {
// @ts-expect-error
root = ReactDOM.hydrateRoot(container, element)
})
ReactDOM.hydrate(element, container)
return () => {
root.unmount()
ReactDOM.unmountComponentAtNode(container)
}
}

Expand Down
Loading
Loading