From 902d52a640c146cada2c8d248f347533b39f19e2 Mon Sep 17 00:00:00 2001 From: robobun Date: Sun, 26 Apr 2026 09:30:14 +0000 Subject: [PATCH] Fix stack overflow when inspecting JSX elements with circular references --- src/bun.js/ConsoleObject.zig | 2 +- test/js/bun/util/inspect.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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..54a43f17e818 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 in key", () => { + const el = { $$typeof: Symbol.for("react.element"), type: "div", key: null, ref: null, props: {} }; + el.key = el; + expect(Bun.inspect(el)).toContain("[Circular]"); +}); + +it("jsx with circular reference in props", () => { + const el = { $$typeof: Symbol.for("react.element"), type: "div", key: null, ref: null, props: {} }; + el.props.foo = el; + expect(Bun.inspect(el)).toBe("
"); +}); + +it("jsx with circular reference in children", () => { + const el = { $$typeof: Symbol.for("react.element"), type: "div", key: null, ref: null, props: {} }; + el.props.children = [el]; + expect(Bun.inspect(el)).toBe("
\n [Circular]\n
"); +}); + it("inspect", () => { expect(Bun.inspect(new TypeError("what")).includes("TypeError: what")).toBe(true); expect(Bun.inspect("hi")).toBe('"hi"');