Skip to content

Conversation

@hgray-instawork
Copy link
Collaborator

@hgray-instawork hgray-instawork commented May 30, 2025

To improve performance and reduce re-renders, memoize the styles created by createStyleProp. This required converting several class components to functional.

Asana

Improving performance by creating a new `hv-element` component as a
replacement for Render.renderElement. This allows memoizing the options
and props of the component to reduce unneeded re-renders.


[Asana](https://app.asana.com/1/47184964732898/project/1204008699308084/task/1210344460236268?focus=true)
Consolidate the logic between `src/services/render` and the new
`hv-element` component.
- Created a new utility to abstract the `null` render logic and logging
- Update render service to use logic and then return the component
- Update `hv-element` to use utility for logic and logging
- Export `hv-element` for access outside Hyperview
- Confirmed external use of `Hyperview.renderElement` with new logic
still working (using existing nav-back demo)
- Update `nav-back` demo to use component instead of function


[Asana](https://app.asana.com/1/47184964732898/project/1204008699308084/task/1210368849843731?focus=true)
Creating a component which can replace the use of the render service
`renderChildren`. Provides a mapping of child nodes to `<HvElement>`
components.

- [Created the new
component](0ece9f6)
- [Switched four element types from ts to
tsx](dd518da)
- Replaced `React.createElement` implementations with declarative
instances [using the new component to render
children](7c73c9b)
- Updated the sticky header logic to use the rendered children and
[added a verification of a valid
`getAttribute`](65d8b20)



[Asana](https://app.asana.com/1/47184964732898/project/1204008699308084/task/1210344460236290?focus=true)

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210344460236290
Removing changes made to demo until the next HV release.
The updated code was causing an increase in "Each child in a list should
have a unique key prop" warnings. It was determined that the legacy code
used spreading over the child array which causes React to not issue the
warning. [See
documentation](https://react.dev/reference/react/createElement#:~:text=You%20should%20only,they%20never%20reorder.).

This code temporarily reverts the various components which were throwing
the warnings in the Hyperview demo. They should be restored at a later
time to restore the intended functionality.

- [Added a key to the
\<HvElement\>](a6406bc)
- [Reverted use of declarative syntax where
needed](ec8e044)

Relates to
[Asana](https://app.asana.com/1/47184964732898/project/1205761271270033/task/1210424257505845?focus=true)
@hgray-instawork hgray-instawork requested a review from a team May 30, 2025 18:46
Copy link
Collaborator

@flochtililoch flochtililoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to observe less re-renders with this refactor?

A couple of issues stand out to me:

  • when components were converted from class to function, the former instance methods were not wrapped with useCallback - this will cause the functions to be recreated on every render
  • I think the memoization for the style prop is unlikely to bring a performance boost at that level, since props.stylesheets is one of the dependencies that changes every time we inject new styles - I assume we will need memoization within the createStyleProp method itself.

@hgray-instawork hgray-instawork marked this pull request as draft June 3, 2025 21:17
Base automatically changed from hardin/render-component-integration to master June 6, 2025 20:50
@hgray-instawork
Copy link
Collaborator Author

Closing in favor of improved approach: #1183

@hgray-instawork hgray-instawork deleted the hardin/render-style-memo branch June 9, 2025 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants