-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix stack overflow when inspecting JSX elements with circular references #29931
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 |
|---|---|---|
|
|
@@ -50,4 +50,46 @@ | |
| // Verify it actually formatted and showed the diff (not just crashed) | ||
| expect(stderr).toContain("expect(received).toEqual(expected)"); | ||
| }, 30000); | ||
|
|
||
| test("JSX element with circular or non-object props", async () => { | ||
| const dir = tempDirWithFiles("pretty-format-jsx", { | ||
| "jsx.test.ts": ` | ||
| import { test, expect } from "bun:test"; | ||
|
|
||
| test("circular props", () => { | ||
| const el: any = { $$typeof: Symbol.for("react.element"), type: "div", props: {} }; | ||
| el.props = el; | ||
| expect(el).toEqual({}); | ||
| }); | ||
|
|
||
| test("circular children", () => { | ||
| const el: any = { $$typeof: Symbol.for("react.element"), type: "div", props: {} }; | ||
| el.props.children = el; | ||
| expect(el).toEqual({}); | ||
| }); | ||
|
|
||
| test("non-object props", () => { | ||
| const el: any = { $$typeof: Symbol.for("react.element"), type: "div", props: 42 }; | ||
| expect(el).toEqual({}); | ||
| }); | ||
| `, | ||
| }); | ||
|
|
||
| const proc = Bun.spawn({ | ||
| cmd: [bunExe(), "test", "jsx.test.ts"], | ||
| env: bunEnv, | ||
| cwd: dir, | ||
| stderr: "pipe", | ||
| stdout: "pipe", | ||
| }); | ||
|
|
||
| const [stderr, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect(exitCode).toBe(1); | ||
| expect(stderr).not.toContain("panic"); | ||
| expect(stderr).not.toContain("SIGSEGV"); | ||
| expect(stderr).toContain("[Circular]"); | ||
| expect(stderr).toContain("expect(received).toEqual(expected)"); | ||
| expect(stderr).toContain("3 fail"); | ||
|
Check warning on line 93 in test/js/bun/test/pretty-format-overflow.test.ts
|
||
|
Comment on lines
+88
to
+93
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. 🟡 nit: per root CLAUDE.md, when spawning processes the test should assert on Extended reasoning...What the bug isThe new test in
How it manifests / step-by-stepThis test exists to catch a regression where
Why existing code doesn't prevent it
ImpactPurely a test-ergonomics / diagnostics issue — the test still correctly fails on regression, it just produces a much less helpful failure message. Given this PR is specifically guarding against a crash, having the failure surface the crash output is valuable. This is nit-level: it doesn't affect correctness, and it matches the ordering already used by the pre-existing "deeply nested object" test in the same file (lines 46-51). How to fixReorder the assertions so the stderr content checks run first and the expect(stderr).not.toContain("panic");
expect(stderr).not.toContain("SIGSEGV");
expect(stderr).toContain("[Circular]");
expect(stderr).toContain("expect(received).toEqual(expected)");
expect(stderr).toContain("3 fail");
expect(exitCode).toBe(1);Optionally apply the same reordering to the pre-existing test above for consistency. |
||
| }, 30000); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.