Skip to content

Commit d27a348

Browse files
committed
fix(pretty-format): support react 19
1 parent 6324a00 commit d27a348

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

packages/pretty-format/package.json

Lines changed: 2 additions & 1 deletion
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:[email protected]"
4243
}
4344
}

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

Lines changed: 25 additions & 1 deletion
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

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)