Detect circular references when inspecting JSX elements#30043
Conversation
Bun.inspect() on a React element whose key, prop, or children referred back to the element itself would recurse without the stack check or visited-map guard, crashing the process.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThe changes extend circular reference detection to JSX values in the pretty-printing and inspection logic. Two core files are updated to include Changes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Review rate limit: 4/5 reviews remaining, refill in 12 minutes. Comment |
|
This PR may be a duplicate of:
🤖 Generated with Claude Code |
|
Duplicate of #29709, which already contains this fix plus additional handling for non-object |
There was a problem hiding this comment.
LGTM — minimal fix that extends the existing circular-reference guard to the JSX format tag, with tests covering key/prop/children cycles.
Extended reasoning...
Overview
This PR adds .JSX to the canHaveCircularReferences() predicate in both src/bun.js/ConsoleObject.zig and src/bun.js/test/pretty_format.zig. Each is a one-token addition to an existing switch/or-chain. A new test in test/js/bun/util/inspect.test.js exercises three circular shapes (self-referential key, prop value, and children) and asserts the [Circular] rendering.
Security risks
None. The change only flips a comptime predicate so that the formatter's pre-existing visited-map + stack-safety guard runs for the .JSX tag, exactly as it already does for .Object, .Array, .Map, etc. No new parsing, allocation, or input handling is introduced.
Level of scrutiny
Low. This is a mechanical, pattern-following crash fix in inspect/pretty-print output code (not on a hot correctness path like the bundler or runtime semantics). The guarded code path (getOrPut on the visited map, print [Circular] on hit, remove on exit) is identical to what every other recursive tag already uses, so there's no novel logic to review.
Other factors
The PR was generated from a Fuzzilli crash fingerprint and includes regression tests that would have segfaulted before. The bug-hunting system found no issues. There are no outstanding reviewer comments and no prior reviews on the timeline.
Bun.inspect()crashes with a segfault when formatting a React element that contains a circular reference back to itself viakey, a prop value, orchildren.The
.JSXformat tag was not included incanHaveCircularReferences(), so the formatter recursed into the element without the stack-safety check or the visited-object map that normally prints[Circular].Repro
After
Found by Fuzzilli (fingerprint
bb8715595a137556).