Skip to content

Fix stack overflow when inspecting circular JSX elements#30629

Closed
robobun wants to merge 2 commits into
mainfrom
farm/e2dca145/fix-jsx-inspect-circular
Closed

Fix stack overflow when inspecting circular JSX elements#30629
robobun wants to merge 2 commits into
mainfrom
farm/e2dca145/fix-jsx-inspect-circular

Conversation

@robobun

@robobun robobun commented May 13, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes a stack overflow crash in Bun.inspect / console.log when formatting a React element whose props or children form a cycle back to the element itself.

const el = {
  $$typeof: Symbol.for("react.element"),
  type: "div",
};
el.props = el;
Bun.inspect(el); // segfault (stack overflow)

The JSX formatter was not included in canHaveCircularReferences(), so the visited-map check never ran for .JSX tags and the formatter recursed until the stack blew out.

Also fixes a null-unwrap panic when props is set to a non-object value — the formatter assumed props was always an object and did props.getObject().?. Now it skips prop iteration when props is not an object.

How did you verify your code works?

Added regression tests to test/js/bun/util/inspect.test.js covering circular props, circular children, and non-object props.

Found by Fuzzilli (fingerprint 380dfde18006ab21).

The JSX formatter in Bun.inspect did not participate in circular
reference detection, causing infinite recursion and a stack overflow
when a React element's props or children referenced the element
itself.

Also fix a null unwrap panic when props is not an object.
@robobun

robobun commented May 13, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 11:11 AM PT - May 13th, 2026

@robobun, your commit 17c406c has 1 failures in Build #54053 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 30629

That installs a local version of the PR into your bun-30629 executable, so you can run:

bun-30629 --bun

@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b0fadd47-9ce5-4138-bc18-cf46f5a65633

📥 Commits

Reviewing files that changed from the base of the PR and between b9c757b and e1f3bbe.

📒 Files selected for processing (2)
  • src/jsc/ConsoleObject.zig
  • test/js/bun/util/inspect.test.js

Walkthrough

JSX console formatting gains circular reference detection and improved robustness: the formatter now recognizes .JSX values as circular-reference–eligible, and JSX props field handling safely obtains an object without force-unwrapping, enabling graceful handling of non-object prop values. Tests validate circular reference rendering and non-object prop edge cases.

Changes

JSX Circular Reference and Props Handling

Layer / File(s) Summary
JSX circular eligibility and props safety
src/jsc/ConsoleObject.zig
canHaveCircularReferences now includes .JSX values; JSX props formatting replaces force-unwrap with a checked getObject() call, breaking early when props is non-object.
JSX formatting test cases
test/js/bun/util/inspect.test.js
Three tests verify circular references in JSX props and props.children render [Circular] markers, and that non-object props renders a self-closing tag.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing stack overflow when inspecting circular JSX elements, which matches the core issue addressed in the changeset.
Description check ✅ Passed The description covers both required template sections with detailed explanations: it explains what the PR does (fixes stack overflow and null-unwrap panic) and how it was verified (regression tests added, found by Fuzzilli).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. Fix crash when inspecting JSX elements with circular or non-object props #30630 - Same fix: adds .JSX to canHaveCircularReferences() and fixes non-object props null-unwrap in ConsoleObject.zig
  2. Fix stack overflow in Bun.inspect() on circular JSX elements #29709 - Same fix: adds .JSX to canHaveCircularReferences() and safely handles non-object props via orelse break :props
  3. Fix stack overflow in Bun.inspect for circular JSX elements #30126 - Partial overlap: adds .JSX to canHaveCircularReferences() to fix the same circular JSX stack overflow (lacks non-object props fix)

🤖 Generated with Claude Code

@robobun

robobun commented May 13, 2026

Copy link
Copy Markdown
Collaborator Author

Duplicate of #29709, which has the same fix plus the equivalent change in pretty_format.zig.

@robobun robobun closed this May 13, 2026
@robobun robobun deleted the farm/e2dca145/fix-jsx-inspect-circular branch May 13, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant