Skip to content

Commit bd29bcc

Browse files
authoredNov 18, 2024··
fix(pretty-format): support react 19 (#6909)
1 parent dc238e9 commit bd29bcc

File tree

6 files changed

+103
-10
lines changed

6 files changed

+103
-10
lines changed
 

‎packages/pretty-format/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
},
3939
"devDependencies": {
4040
"@types/react-is": "^18.3.0",
41-
"react-is": "^18.3.1"
41+
"react-is": "^18.3.1",
42+
"react-is-19": "npm:react-is@19.0.0-rc-b01722d5-20241114"
4243
}
4344
}

‎packages/pretty-format/src/plugins/ReactElement.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,38 @@
66
*/
77

88
import type { Config, NewPlugin, Printer, Refs } from '../types'
9-
import * as ReactIs from 'react-is'
9+
import * as ReactIs18 from 'react-is'
10+
// @ts-expect-error no type
11+
import * as ReactIs19 from 'react-is-19'
1012
import {
1113
printChildren,
1214
printElement,
1315
printElementAsLeaf,
1416
printProps,
1517
} from './lib/markup'
1618

19+
const reactIsMethods = [
20+
'isAsyncMode',
21+
'isConcurrentMode',
22+
'isContextConsumer',
23+
'isContextProvider',
24+
'isElement',
25+
'isForwardRef',
26+
'isFragment',
27+
'isLazy',
28+
'isMemo',
29+
'isPortal',
30+
'isProfiler',
31+
'isStrictMode',
32+
'isSuspense',
33+
'isSuspenseList',
34+
'isValidElementType',
35+
] as const
36+
37+
const ReactIs: typeof ReactIs18 = Object.fromEntries(
38+
reactIsMethods.map(m => [m, (v: any) => (ReactIs18 as any)[m](v) || ReactIs19[m](v)]),
39+
) as any
40+
1741
// Given element.props.children, or subtree during recursive traversal,
1842
// return flattened array of children.
1943
function getChildren(arg: unknown, children: Array<unknown> = []) {

‎pnpm-lock.yaml

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

‎test/core/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"debug": "^4.3.4",
2727
"immutable": "5.0.0-beta.5",
2828
"memfs": "^4.8.2",
29+
"react": "^18.3.1",
30+
"react-19": "npm:react@19.0.0-rc-b01722d5-20241114",
2931
"sweetalert2": "^11.6.16",
3032
"tinyrainbow": "^1.2.0",
3133
"tinyspy": "^1.0.2",
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @jsxRuntime automatic
2+
// @jsxImportSource react-19
3+
4+
import { expect, test } from 'vitest'
5+
6+
test('react 19', () => {
7+
expect(<div>hello</div>).toMatchInlineSnapshot(`
8+
<div>
9+
hello
10+
</div>
11+
`)
12+
})
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @jsxRuntime automatic
2+
// @jsxImportSource react
3+
4+
import { expect, test } from 'vitest'
5+
6+
test('react 18', () => {
7+
expect(<div>hello</div>).toMatchInlineSnapshot(`
8+
<div>
9+
hello
10+
</div>
11+
`)
12+
})

0 commit comments

Comments
 (0)
Please sign in to comment.