-
-
Notifications
You must be signed in to change notification settings - Fork 122
[core] Performance/refactor: useRender
#1934
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
base: master
Are you sure you want to change the base?
Conversation
commit: |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
const { render, props, state, refs } = params; | ||
const { ref: intrinsicRefProp, ...intrinsicProps } = props || {}; | ||
const renderParams = params as useRender.Parameters<State, RenderedElementType> & { | ||
disableStyleHooks: boolean; | ||
}; | ||
renderParams.disableStyleHooks = true; | ||
|
||
const renderElement = useRenderElementLazy( | ||
undefined, | ||
{ render }, | ||
{ | ||
props: intrinsicProps, | ||
state, | ||
ref: [intrinsicRefProp, ...(refs || [])].filter( | ||
(x): x is React.Ref<RenderedElementType> => x != null, | ||
), | ||
disableStyleHooks: true, | ||
}, | ||
); | ||
const element = useRenderElement(undefined, renderParams, renderParams); | ||
|
||
return { | ||
renderElement, | ||
}; | ||
return element; |
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.
I don't insist on the mutable .disableStyleHooks
line, I just wrote it this way to highlight what this refactor made evident: useRender
is really just useRenderElement
but with style hooks turned off.
The prop/ref destructuring & handling logic was all unnecessary: it's duplicated with the logic in useRenderElement
which already does all that.
* Refs to be merged together to access the rendered DOM element. | ||
* The ref to apply to the rendered element. | ||
*/ | ||
refs?: React.Ref<RenderedElementType>[]; | ||
ref?: React.Ref<RenderedElementType> | React.Ref<RenderedElementType>[]; |
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.
I standardized this with useRenderElement
, both use ref
for the propname, while still allowing an array.
docs/src/app/(public)/(content)/react/utils/use-render/page.mdx
Outdated
Show resolved
Hide resolved
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.
What about the conditional rendering optimization with an early null
return, or was that not much of a concern in your perf tests?
I have not seen a case where the lazyness was actually needed, we seem to call |
Searching |
Ah right, I didn't look at the deprecated There could be more lazyness though. Laziness is set just at the |
This is both perf/refactor. Make
useRender
match theuseRenderElement
API.