Skip to content

Commit

Permalink
fix(pretty-format): support react 19
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 15, 2024
1 parent 6324a00 commit d27a348
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/pretty-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"devDependencies": {
"@types/react-is": "^18.3.0",
"react-is": "^18.3.1"
"react-is": "^18.3.1",
"react-is-19": "npm:[email protected]"
}
}
26 changes: 25 additions & 1 deletion packages/pretty-format/src/plugins/ReactElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,38 @@
*/

import type { Config, NewPlugin, Printer, Refs } from '../types'
import * as ReactIs from 'react-is'
import * as ReactIs18 from 'react-is'
// @ts-expect-error no type
import * as ReactIs19 from 'react-is-19'
import {
printChildren,
printElement,
printElementAsLeaf,
printProps,
} from './lib/markup'

const reactIsMethods = [
'isAsyncMode',
'isConcurrentMode',
'isContextConsumer',
'isContextProvider',
'isElement',
'isForwardRef',
'isFragment',
'isLazy',
'isMemo',
'isPortal',
'isProfiler',
'isStrictMode',
'isSuspense',
'isSuspenseList',
'isValidElementType',
] as const

const ReactIs: typeof ReactIs18 = Object.fromEntries(
reactIsMethods.map(m => [m, (v: any) => (ReactIs18 as any)[m](v) || ReactIs19[m](v)])

Check failure on line 38 in packages/pretty-format/src/plugins/ReactElement.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Missing trailing comma
) as any

// Given element.props.children, or subtree during recursive traversal,
// return flattened array of children.
function getChildren(arg: unknown, children: Array<unknown> = []) {
Expand Down
21 changes: 15 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d27a348

Please sign in to comment.