Skip to content

Commit 1fe203a

Browse files
committed
Fix issue with isValidElementType invariant check crashing on valid type with circular structure
1 parent 775f1ac commit 1fe203a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/components/connectAdvanced.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import { isValidElementType } from 'react-is'
55

66
import { ReactReduxContext } from './Context'
77

8+
const stringifyComponent = Comp => {
9+
try {
10+
return JSON.stringify(Comp)
11+
} catch (err) {
12+
return String(Comp)
13+
}
14+
}
15+
816
export default function connectAdvanced(
917
/*
1018
selectorFactory is a func that is responsible for returning the selector function used to
@@ -86,7 +94,7 @@ export default function connectAdvanced(
8694
invariant(
8795
isValidElementType(WrappedComponent),
8896
`You must pass a component to the function returned by ` +
89-
`${methodName}. Instead received ${JSON.stringify(WrappedComponent)}`
97+
`${methodName}. Instead received ${stringifyComponent(WrappedComponent)}`
9098
)
9199
}
92100

0 commit comments

Comments
 (0)