diff --git a/src/bun.js/ConsoleObject.zig b/src/bun.js/ConsoleObject.zig index a1cfeb510359..c9a7361ee4c2 100644 --- a/src/bun.js/ConsoleObject.zig +++ b/src/bun.js/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/test/js/bun/util/inspect.test.js b/test/js/bun/util/inspect.test.js index 32a70af30183..3352f5b1fd98 100644 --- a/test/js/bun/util/inspect.test.js +++ b/test/js/bun/util/inspect.test.js @@ -772,3 +772,34 @@ it("CustomEvent", () => { }" `); }); + +describe("JSX circular references", () => { + it("does not crash when key is a circular reference", () => { + const el = { $$typeof: Symbol.for("react.element"), type: "div", props: {}, key: null }; + el.key = el; + expect(Bun.inspect(el)).toBe("
"); + }); + + it("does not crash when a prop is a circular reference", () => { + const el = { $$typeof: Symbol.for("react.element"), type: "div", props: {}, key: null }; + el.props.foo = el; + expect(Bun.inspect(el)).toBe(""); + }); + + it("does not crash when children is a circular reference", () => { + const el = { $$typeof: Symbol.for("react.element"), type: "div", props: {}, key: null }; + el.props.children = el; + expect(Bun.inspect(el)).toBe("