Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/formatter/sortObject.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
/* @flow */
import * as React from 'react';

export default function sortObject(value: any): any {
// return non-object value as is
if (value === null || typeof value !== 'object') {
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;
}

Expand Down
21 changes: 21 additions & 0 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1334,4 +1334,25 @@ describe('reactElementToJSXString(ReactElement)', () => {

expect(reactElementToJSXString(<Lazy />)).toEqual(`<Lazy />`);
});

it('should stringify `forwardRef` element with a circular property', () => {
function TagList({ tags }) {
return tags;
}

const Tag = React.forwardRef(function Tag({ text }, ref) {
return <span ref={ref}>{text}</span>;
});
Tag.emotionReal = Tag;

expect(
reactElementToJSXString(
<TagList tags={[<Tag key="oops" text="oops, circular" />]} />
)
).toEqual(`<TagList
tags={[
<Tag key="oops" text="oops, circular"/>
]}
/>`);
});
});