Skip to content

Add spinner when loading results#1828

Merged
koesie10 merged 1 commit intomainfrom
koesie10/results-loading
Dec 7, 2022
Merged

Add spinner when loading results#1828
koesie10 merged 1 commit intomainfrom
koesie10/results-loading

Conversation

@koesie10
Copy link
Copy Markdown
Member

@koesie10 koesie10 commented Dec 2, 2022

This will add a spinner to each repo row when the results for a particular repo are loading. It will also disable the row to make clear that it is loading and not clickable.

Screen.Recording.2022-12-02.at.16.22.42.mov

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

This will add a spinner to each repo row when the results for a
particular repo are loading. It will also disable the row to make clear
that it is loading and not clickable.
@koesie10 koesie10 added the secexp label Dec 2, 2022
@koesie10 koesie10 requested a review from a team as a code owner December 2, 2022 15:24
{!isExpanded && !resultsLoading && (
<ExpandCollapseCodicon name="chevron-right" label="Expand" />
)}
{resultsLoading && <LoadingIcon label="Results are loading" />}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Really like the idea. It makes it much nicer to use because you know it's doing somehting.

The only problem I see if that it only triggers the loading icon the first time you expand the results. We don't set resultsLoading on subsequent expandings. It is quicker to display the second time but it still takes almost as long, and the spinner doesn't show up so you're back to the experience where you think it's frozen.

The UI freezes quite badly for me when opening a large set of results, so it's not clear whether other clicks on things are doing anything. That's not a problem of this PR though, and this PR is only making things better.

Could we show the spinner every time? Would there be a problem knowing when to stop showing it? As in, is there an event that fires once rendering is complete?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unfortunately, React doesn't fire any event when it has completed rendering, so we can't really do that. We are also not really able to render the spinner icon before rendering the expanded results since React will try to batch these updates automatically. We could artificially try to add some delay between these two renders, but I think that will result in code that is really hard to follow.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we gradually render results, rather than a big bang?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure that's possible, since we would still be blocking the main rendering thread. If we stream in results and render e.g. 100 results every second, it might freeze every second and the layout might jump around since new results can potentially be rendered while scrolling.

The real solution here would probably be react-window or react-virtualized, but as far as I can tell they require us to know the height of every rendered result. Both do support differing heights for different items, but I think it would be quite hard to tell the exact height of every element without rendering them. We would need to take into account the height of every code snippet, as well as knowing padding, wrapping etc. This might be possible, but should probably be investigated as part of a larger issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah that sounds crazy complicated :D This might be something that would be worth involving Design in too btw.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree the virtualized rendering is probably the best solution, but it's hard to implement.

What I understood from @charisk's comment was the classic "load more" button (e.g. we render 10 results, but you can click a button to load the rest or load a larger chunk like 1000). That would be a lot easier to implement, but we'd want to run it past design before implementing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've created a simple proof of concept for virtualization, which skips implementing some of the harder parts: https://github.com/github/vscode-codeql/tree/koesie10/results-virtualization. It is now heavily based on heuristics, but does render the results instantly.

I agree with you that adding a simple button to load more results or some other form of pagination would be a lot easier to implement, but I think that can be a separate PR. For this PR, just implementing the spinner will still improve the experience of loading results.

@koesie10 koesie10 requested a review from a team December 6, 2022 08:06
Copy link
Copy Markdown
Contributor

@elenatanasoiu elenatanasoiu left a comment

Choose a reason for hiding this comment

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

:shipit: We can continue the virtualization discussion (which Koen has already kinda sorta implemented?! ⚡) but I think this is a good enough change on its own. Any indication of progress is an improvement. 👍

@koesie10 koesie10 merged commit 0f5117e into main Dec 7, 2022
@koesie10 koesie10 deleted the koesie10/results-loading branch December 7, 2022 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants