Skip to content
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

feat: Virtualised list for search results #3722

Merged
merged 6 commits into from
Oct 1, 2024

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Sep 23, 2024

What does this PR do?

  • Wraps the search results in a virtualised list, using react-virtuoso
  • Restructures hierarchy of components in order to fit the pattern required by Virtuoso -
    • Removes SearchNodeResult component - this is now just an item within the list (code)
    • Split inputs into SearchHeader
    • Retain logic and component state in Search
  • Updates tests to match the new pattern (wrapping in Virtuosos and setting up context)

What's changed?

Previously, performance felt sluggish when a large number of search results were returned. Scrolling was slow, and the text input would frequently freeze. This is mitigated by using a debounce for the search term, but still noticeable.

Please see this example flow, with search term "user" (215 results) - https://editor.planx.dev/opensystemslab/prior-approval-scope-check

On the Pizza, this should feel a fair bit quicker - we can see in the video below that only a small number of result cards are being rendered at any given moment.

Screen.Recording.2024-09-30.at.17.01.02.mov

Copy link

github-actions bot commented Sep 23, 2024

Removed vultr server and associated DNS entries

@DafyddLlyr DafyddLlyr force-pushed the dp/virtualised-search-list branch 4 times, most recently from 5272805 to c547ad9 Compare September 27, 2024 17:13
@DafyddLlyr DafyddLlyr force-pushed the dp/virtualised-search-list branch from c547ad9 to b718db7 Compare September 30, 2024 08:04
@DafyddLlyr DafyddLlyr force-pushed the dp/virtualised-search-list branch from b718db7 to 53b2db7 Compare September 30, 2024 08:20
@DafyddLlyr DafyddLlyr force-pushed the dp/virtualised-search-list branch from 76efb27 to 84cad19 Compare September 30, 2024 14:34
Comment on lines +104 to +108
components={{
Footer: ExternalPortalList,
List: ListComponent,
Item: ListItemComponent,
Header: SearchHeader,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Child components are passed in via the components prop (docs).

Comment on lines +40 to +49
const ListComponent = React.forwardRef<HTMLUListElement>((props, ref) => (
<List {...props} ref={ref} sx={{ mx: 3 }} />
)) as Components<Data, Context>["List"];

/**
* Accessibility - Render the Virtuoso item as a HTMLLiElement, not a HTMLDivElement
*/
const ListItemComponent = React.forwardRef<HTMLLIElement>((props, ref) => (
<ListItem disablePadding sx={{ pb: 2 }} {...props} ref={ref} />
)) as Components<Data, Context>["Item"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find a way to set this up without casting to Virtuoso types.

@@ -81,6 +81,7 @@
"react-navi-helmet-async": "^0.15.0",
"react-toastify": "^9.1.3",
"react-use": "^17.5.0",
"react-virtuoso": "^4.10.4",
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Sep 30, 2024

Choose a reason for hiding this comment

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

Why react-virtuoso?

  • Recommended in MUI docs
  • I tried the more basic react-window first and quickly found myself having a lot of CSS and layout issues - Virtuoso "just worked"
  • Good score on socket.dev
  • Docs were solid and clear

@DafyddLlyr DafyddLlyr changed the title feat(wip): Virtualised list for search results feat: Virtualised list for search results Sep 30, 2024
@DafyddLlyr DafyddLlyr requested a review from a team September 30, 2024 16:10
@DafyddLlyr DafyddLlyr marked this pull request as ready for review September 30, 2024 16:10
@DafyddLlyr
Copy link
Contributor Author

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

Feels like a solid improvement ! Appreciate the why-react-virtuoso decision making notes

Only noticed a few things not related to the virtulised table changes while reviewing which I've dropped in the Slack feedback thread, this seems good to go !

@DafyddLlyr
Copy link
Contributor Author

Thanks @jessicamcinchak - working my way through those comments now 👍

@DafyddLlyr DafyddLlyr merged commit 48213f7 into main Oct 1, 2024
12 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/virtualised-search-list branch October 1, 2024 07:38
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.

2 participants