-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Enable anonymous function naming in React Compiler #84070
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
102039f
854cefa
c94a6ce
425c2f8
4d342b8
af3c151
592b4dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||||||||||||||||||||
| 'use client' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import { useEffect, useState } from 'react' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export default function Page() { | ||||||||||||||||||||||||
| const [callFrame, setCallFrame] = useState(null) | ||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||
| const error = new Error('test-top-frame') | ||||||||||||||||||||||||
| console.error(error) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const callStack = new Error('test-top-frame').stack.split( | ||||||||||||||||||||||||
| 'test-top-frame\n' | ||||||||||||||||||||||||
| )[1] | ||||||||||||||||||||||||
| // indices might change due to different compiler optimizations | ||||||||||||||||||||||||
| const callFrame = callStack.split('\n')[0] | ||||||||||||||||||||||||
|
Comment on lines
+11
to
+15
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.
Suggested change
The stack trace parsing code can throw a TypeError if the stack format doesn't match expectations, causing the test to fail unexpectedly. View DetailsAnalysisTypeError in stack trace parsing can crash function-naming testWhat fails: How to reproduce: // Simulate non-standard stack format (can occur in different browsers/engines)
const mockError = { stack: 'Error: some-other-error\n at somewhere' };
const callStack = mockError.stack.split('test-top-frame\n')[1]; // undefined
const callFrame = callStack.split('\n')[0]; // TypeError: Cannot read properties of undefined (reading 'split')Result: TypeError: "Cannot read properties of undefined (reading 'split')" when stack doesn't contain expected pattern Expected: Should handle missing/malformed stack traces gracefully per MDN Error.stack docs - stack format varies between engines and isn't standardized
Member
Author
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. That's fine. Then the test fails. |
||||||||||||||||||||||||
| setCallFrame(callFrame) | ||||||||||||||||||||||||
| }, []) | ||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||
| <pre data-testid="call-frame" aria-busy={callFrame === null}> | ||||||||||||||||||||||||
| {String(callFrame)} | ||||||||||||||||||||||||
| </pre> | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,31 @@ | ||
| 'use client' | ||
|
|
||
| import { useEffect } from 'react' | ||
| import { Profiler, useReducer } from 'react' | ||
|
|
||
| export default function Page() { | ||
| let $_: any | ||
| if (typeof window !== 'undefined') { | ||
| // eslint-disable-next-line no-eval | ||
| $_ = eval('$') | ||
|
Member
Author
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. React Compiler now bails out when it detects |
||
| } | ||
| if (typeof window !== 'undefined') { | ||
| ;(window as any).staticChildRenders = 0 | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| if (Array.isArray($_)) { | ||
| document.getElementById('react-compiler-enabled-message')!.textContent = | ||
| `React compiler is enabled with ${$_!.length} memo slots` | ||
| } | ||
| }) | ||
| function StaticChild() { | ||
| return ( | ||
| <Profiler | ||
| onRender={(id, phase) => { | ||
| ;(window as any).staticChildRenders += 1 | ||
| }} | ||
| id="test" | ||
| > | ||
| <div>static child</div> | ||
| </Profiler> | ||
| ) | ||
| } | ||
|
|
||
| export default function Page() { | ||
| const [count, increment] = useReducer((n) => n + 1, 1) | ||
| return ( | ||
| <> | ||
| <div> | ||
| <h1 id="react-compiler-enabled-message" /> | ||
| <p>hello world</p> | ||
| </div> | ||
| <div data-testid="parent-commits">Parent commits: {count}</div> | ||
| <button onClick={increment}>Increment</button> | ||
| <StaticChild /> | ||
| </> | ||
| ) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.