Fix stack overflow in Bun.inspect with circular JSX elements - #30584
Closed
robobun wants to merge 2 commits into
Closed
Fix stack overflow in Bun.inspect with circular JSX elements#30584robobun wants to merge 2 commits into
robobun wants to merge 2 commits into
Conversation
The JSX formatter did not participate in circular reference detection because .JSX was missing from canHaveCircularReferences(). A React element that referenced itself via key, props, or children would recurse until the stack overflowed. Also guard against a non-object props value instead of unwrapping getObject() unconditionally.
Collaborator
Author
Contributor
Contributor
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/js/bun/util/inspect.test.js`:
- Around line 329-339: The test "jsx with circular reference as props object"
currently only asserts Bun.inspect(el) contains "[Circular]"; tighten it by also
asserting the JSX-format is preserved—e.g., check that the inspected output
begins with "<div" or otherwise contains the JSX-like opening tag for the
element type. Update the expectation in the test (the it block where el is
created with $$typeof Symbol.for("react.transitional.element") and props
circular reference) to include a second assertion that verifies the output's JSX
shape (startsWith "<div" or contains "<div") alongside the existing Circular
assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 30e7b424-7335-4eb5-957c-e34d653a6cc6
📒 Files selected for processing (3)
src/jsc/ConsoleObject.zigsrc/test_runner/pretty_format.zigtest/js/bun/util/inspect.test.js
Contributor
|
This PR may be a duplicate of:
🤖 Generated with Claude Code |
Collaborator
Author
|
Duplicate of #29709 which has the same fix with more thorough tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bun.inspect()/console.log()crashed with a stack overflow when given a React element that referenced itself viakey,props, orchildren.The JSX branch of the formatter recursively prints
key, each prop value, andchildren, but.JSXwas missing fromcanHaveCircularReferences()so it skipped both the visited-map check and theisSafeToRecurse()stack guard. Any cycle through a JSX element recursed until the stack blew out.Fix: include
.JSXincanHaveCircularReferences()in bothConsoleObject.zigandpretty_format.zigso cycles print as[Circular].Also replaced
props.getObject().?withprops.getObject() orelse break :props— the "JSX props are always objects" assumption is not true for arbitrary objects shaped like React elements, and unwrapping panicked onprops: 123.Found by Fuzzilli.