diff --git a/src/jsc/ConsoleObject.zig b/src/jsc/ConsoleObject.zig index 2489ea14ea03..185f7dad814d 100644 --- a/src/jsc/ConsoleObject.zig +++ b/src/jsc/ConsoleObject.zig @@ -1136,7 +1136,7 @@ pub const Formatter = struct { pub fn canHaveCircularReferences(tag: Tag) bool { return switch (tag) { - .Function, .Array, .Object, .Map, .Set, .Error, .Class, .Event => true, + .Function, .Array, .Object, .Map, .Set, .Error, .Class, .Event, .JSX => true, else => false, }; } diff --git a/src/test_runner/pretty_format.zig b/src/test_runner/pretty_format.zig index 2a5fcdaf5600..2974d90e84f3 100644 --- a/src/test_runner/pretty_format.zig +++ b/src/test_runner/pretty_format.zig @@ -326,7 +326,7 @@ pub const JestPrettyFormat = struct { } pub inline fn canHaveCircularReferences(tag: Tag) bool { - return tag == .Array or tag == .Object or tag == .Map or tag == .Set; + return tag == .Array or tag == .Object or tag == .Map or tag == .Set or tag == .JSX; } const Result = struct { diff --git a/test/js/bun/util/inspect.test.js b/test/js/bun/util/inspect.test.js index 32a70af30183..ccf7647267bb 100644 --- a/test/js/bun/util/inspect.test.js +++ b/test/js/bun/util/inspect.test.js @@ -316,6 +316,24 @@ it("jsx with fragment", () => { expect(input).toBe(output); }); +it("jsx with circular reference", () => { + const el = { $$typeof: Symbol.for("react.element"), type: "div", key: null, ref: null, props: {} }; + el.key = el; + expect(Bun.inspect(el)).toBe("
"); + + const el2 = { $$typeof: Symbol.for("react.element"), type: "div", key: null, ref: null, props: {} }; + el2.props.foo = el2; + expect(Bun.inspect(el2)).toBe("
"); + + const el3 = { $$typeof: Symbol.for("react.element"), type: "div", key: null, ref: null, props: {} }; + el3.props.children = el3; + expect(Bun.inspect(el3)).toBe("
\n [Circular]\n
"); + + const el4 = { $$typeof: Symbol.for("react.element"), type: "div", key: null, ref: null, props: {} }; + el4.props.children = [el4]; + expect(Bun.inspect(el4)).toBe("
\n [Circular]\n
"); +}); + it("inspect", () => { expect(Bun.inspect(new TypeError("what")).includes("TypeError: what")).toBe(true); expect(Bun.inspect("hi")).toBe('"hi"');