diff --git a/src/formatter/sortObject.js b/src/formatter/sortObject.js index 85655415c..2415cba56 100644 --- a/src/formatter/sortObject.js +++ b/src/formatter/sortObject.js @@ -1,4 +1,5 @@ /* @flow */ +import * as React from 'react'; export default function sortObject(value: any): any { // return non-object value as is @@ -6,8 +7,12 @@ export default function sortObject(value: any): any { return value; } - // return date and regexp values as is - if (value instanceof Date || value instanceof RegExp) { + // return date, regexp and react element values as is + if ( + value instanceof Date || + value instanceof RegExp || + React.isValidElement(value) + ) { return value; } diff --git a/src/index.spec.js b/src/index.spec.js index de66c1e53..ce1d400c3 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -1334,4 +1334,25 @@ describe('reactElementToJSXString(ReactElement)', () => { expect(reactElementToJSXString()).toEqual(``); }); + + it('should stringify `forwardRef` element with a circular property', () => { + function TagList({ tags }) { + return tags; + } + + const Tag = React.forwardRef(function Tag({ text }, ref) { + return {text}; + }); + Tag.emotionReal = Tag; + + expect( + reactElementToJSXString( + ]} /> + ) + ).toEqual(` + ]} + />`); + }); });