-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix(react): Hoist component resolution in OverrideOrDefault #120028
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 1 commit
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 |
|---|---|---|
|
|
@@ -62,16 +62,19 @@ export function OverrideOrDefault<H extends OverrideName>({ | |
| return defaultComponent; | ||
| } | ||
|
|
||
| function OverrideOrDefaultComponent(props: Props) { | ||
| // Defining the props here is unnecessary and slow for typescript | ||
| const OverrideComponent: React.ComponentType<any> = | ||
| getOverride(overrideName)?.() ?? getDefaultComponent(); | ||
| // Resolve the component once at factory scope so that the component type | ||
| // identity is stable across renders. Creating components during render gives | ||
| // React a new type on every render, causing unnecessary unmount/remount cycles | ||
| // and breaking React Compiler's StaticComponents optimization. | ||
| const ResolvedComponent: React.ComponentType<any> | undefined = | ||
| getOverride(overrideName)?.() ?? getDefaultComponent(); | ||
|
Comment on lines
+65
to
+66
Member
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. looks like this was pulled out of the function and the value is closed-over now. Keeps |
||
|
|
||
| if (!OverrideComponent) { | ||
| function OverrideOrDefaultComponent(props: Props) { | ||
| if (!ResolvedComponent) { | ||
| return null; | ||
| } | ||
|
sentry[bot] marked this conversation as resolved.
|
||
|
|
||
| return <OverrideComponent {...props} />; | ||
| return <ResolvedComponent {...props} />; | ||
| } | ||
|
|
||
|
Comment on lines
+65
to
75
Contributor
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. Bug: The Suggested FixHoist the calls to Prompt for AI AgentAlso affects:
|
||
| OverrideOrDefaultComponent.displayName = `OverrideOrDefaultComponent(${overrideName})`; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.