-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix crash when inspecting circular or malformed JSX elements #30383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -772,3 +772,40 @@ it("CustomEvent", () => { | |
| }" | ||
| `); | ||
| }); | ||
|
|
||
| describe("JSX element", () => { | ||
| it("handles circular key", () => { | ||
| const elem = { | ||
| $$typeof: Symbol.for("react.element"), | ||
| type: "div", | ||
| key: null, | ||
| ref: null, | ||
| props: { children: [] }, | ||
| }; | ||
| elem.key = elem; | ||
| expect(Bun.inspect(elem)).toContain("[Circular]"); | ||
| }); | ||
|
|
||
| it("handles circular children", () => { | ||
| const elem = { | ||
| $$typeof: Symbol.for("react.element"), | ||
| type: "div", | ||
| key: null, | ||
| ref: null, | ||
| props: {}, | ||
| }; | ||
| elem.props.children = elem; | ||
| expect(Bun.inspect(elem)).toContain("[Circular]"); | ||
| }); | ||
|
|
||
| it("handles non-object props", () => { | ||
| const elem = { | ||
| $$typeof: Symbol.for("react.element"), | ||
| type: "div", | ||
| key: null, | ||
| ref: null, | ||
| props: 123, | ||
| }; | ||
| expect(Bun.inspect(elem)).toBe("<div />"); | ||
| }); | ||
|
Comment on lines
+777
to
+810
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: cat -n test/js/bun/util/inspect.test.js | sed -n '770,820p'Repository: oven-sh/bun Length of output: 1236 🏁 Script executed: rg "describe\.each" test/js/bun/util/inspect.test.js -A 5 -B 2Repository: oven-sh/bun Length of output: 37 🏁 Script executed: rg "describe\.each" test/js/bun/ --type js --type ts -l | head -20Repository: oven-sh/bun Length of output: 627 🏁 Script executed: cat test/js/bun/test/jest-each.test.ts | head -100Repository: oven-sh/bun Length of output: 1609 🏁 Script executed: rg "describe\.each|it\.each" test/js/bun/test/jest-each.test.ts -A 8 -B 1 | head -80Repository: oven-sh/bun Length of output: 1455 🏁 Script executed: rg "it\.each" test/js/bun/test/jest-each.test.ts -A 5 -B 1 | head -40Repository: oven-sh/bun Length of output: 1126 🏁 Script executed: # Check if there are examples of describe.each with complex objects in the test suite
rg "describe\.each.*\(" test/js/bun/ -A 10 -B 1 --type ts --type js | head -60Repository: oven-sh/bun Length of output: 4859 🏁 Script executed: # Let's verify the exact syntax expected by checking how describe.each callback should work
cat test/js/bun/udp/udp_socket.test.ts | sed -n '1,50p'Repository: oven-sh/bun Length of output: 2056 🏁 Script executed: # Check the jest-each test more carefully to understand the callback structure
rg "describe\.each.*\{" test/js/bun/typescript/type-export.test.ts -A 8 -B 2 | head -50Repository: oven-sh/bun Length of output: 1323 🏁 Script executed: # Let's confirm the exact callback signature expected for describe.each
rg "describe\.each.*\)" test/js/bun/udp/udp_socket.test.ts -A 5 -B 1Repository: oven-sh/bun Length of output: 358 🏁 Script executed: # Check if there's any example that directly executes logic in describe.each callback
rg "describe\.each" test/js/bun/ --type ts --type js -A 15 | grep -A 15 "describe\.each.*hostname" | head -25Repository: oven-sh/bun Length of output: 1780 🏁 Script executed: # Let me verify the exact structure needed - check if describe.each can work with verify functions or if we need it.each
cat test/js/bun/dns/resolve-dns.test.ts | grep -A 20 "describe.each(validHostnames)"Repository: oven-sh/bun Length of output: 546 Use Lines 777–810 contain repeated test structure with only fixture/assertion differences. Using ♻️ Suggested refactor describe("JSX element", () => {
- it("handles circular key", () => {
- const elem = {
- $$typeof: Symbol.for("react.element"),
- type: "div",
- key: null,
- ref: null,
- props: { children: [] },
- };
- elem.key = elem;
- expect(Bun.inspect(elem)).toContain("[Circular]");
- });
-
- it("handles circular children", () => {
- const elem = {
- $$typeof: Symbol.for("react.element"),
- type: "div",
- key: null,
- ref: null,
- props: {},
- };
- elem.props.children = elem;
- expect(Bun.inspect(elem)).toContain("[Circular]");
- });
-
- it("handles non-object props", () => {
- const elem = {
- $$typeof: Symbol.for("react.element"),
- type: "div",
- key: null,
- ref: null,
- props: 123,
- };
- expect(Bun.inspect(elem)).toBe("<div />");
- });
+ it.each([
+ {
+ name: "handles circular key",
+ setup: () => {
+ const elem = {
+ $$typeof: Symbol.for("react.element"),
+ type: "div",
+ key: null,
+ ref: null,
+ props: { children: [] },
+ };
+ elem.key = elem;
+ return elem;
+ },
+ assertion: (output) => expect(output).toContain("[Circular]"),
+ },
+ {
+ name: "handles circular children",
+ setup: () => {
+ const elem = {
+ $$typeof: Symbol.for("react.element"),
+ type: "div",
+ key: null,
+ ref: null,
+ props: {},
+ };
+ elem.props.children = elem;
+ return elem;
+ },
+ assertion: (output) => expect(output).toContain("[Circular]"),
+ },
+ {
+ name: "handles non-object props",
+ setup: () => ({
+ $$typeof: Symbol.for("react.element"),
+ type: "div",
+ key: null,
+ ref: null,
+ props: 123,
+ }),
+ assertion: (output) => expect(output).toBe("<div />"),
+ },
+ ])("$name", ({ setup, assertion }) => {
+ assertion(Bun.inspect(setup()));
+ });
});🤖 Prompt for AI Agents |
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: oven-sh/bun
Length of output: 1629
React 19 transitional elements still bypass the JSX formatter.
This file detects only
"react.element"and"react.fragment"(lines 419-422) but not"react.transitional.element", unlikesrc/jsc/ConsoleObject.zig(line 1307). React 19 elements will skip the hardened JSX path added in this PR and fall back to generic object formatting.🤖 Prompt for AI Agents