diff --git a/src/jsc/ConsoleObject.zig b/src/jsc/ConsoleObject.zig index 2489ea14ea03..917dfe29949a 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, }; } @@ -3140,13 +3140,12 @@ pub const Formatter = struct { } } - if (try value.get(this.globalThis, "props")) |props| { + if (try value.get(this.globalThis, "props")) |props| props: { const prev_quote_strings = this.quote_strings; defer this.quote_strings = prev_quote_strings; this.quote_strings = true; - // SAFETY: JSX props are always objects - const props_obj = props.getObject().?; + const props_obj = props.getObject() orelse break :props; var props_iter = try jsc.JSPropertyIterator(.{ .skip_empty_name = true, .include_value = true, diff --git a/test/js/bun/util/inspect.test.js b/test/js/bun/util/inspect.test.js index 32a70af30183..5c3b328e78bf 100644 --- a/test/js/bun/util/inspect.test.js +++ b/test/js/bun/util/inspect.test.js @@ -316,6 +316,34 @@ it("jsx with fragment", () => { expect(input).toBe(output); }); +it("jsx with circular props", () => { + const el = { + $$typeof: Symbol.for("react.element"), + type: "div", + }; + el.props = el; + expect(Bun.inspect(el)).toContain("[Circular]"); +}); + +it("jsx with circular children", () => { + const el = { + $$typeof: Symbol.for("react.element"), + type: "span", + props: {}, + }; + el.props.children = el; + expect(Bun.inspect(el)).toContain("[Circular]"); +}); + +it("jsx with non-object props", () => { + const el = { + $$typeof: Symbol.for("react.element"), + type: "p", + props: 42, + }; + expect(Bun.inspect(el)).toBe("
"); +}); + it("inspect", () => { expect(Bun.inspect(new TypeError("what")).includes("TypeError: what")).toBe(true); expect(Bun.inspect("hi")).toBe('"hi"');