Skip to content

Error and retry support for infinite scroll#30964

Merged
bl-nero merged 20 commits intomasterfrom
bl-nero/infinite-scroll-errors
Sep 18, 2023
Merged

Error and retry support for infinite scroll#30964
bl-nero merged 20 commits intomasterfrom
bl-nero/infinite-scroll-errors

Conversation

@bl-nero
Copy link
Copy Markdown
Contributor

@bl-nero bl-nero commented Aug 24, 2023

This PR hardens the existing hook, adds a bunch of tests, changes its API, and adds an error&retry UX on top of it.

Demo: https://www.loom.com/share/1b23d99dc6454f7d9f78380e17a81328?sid=d73d6915-fae7-482b-a578-157ee4259b28

Now it only exposes one fetch function that can be used to trigger fetches from infinite scroll, regardless of whether it's the initial or a subsequent fetch. Restarting the data stream is driven by changing filtering parameters.
Comment thread web/packages/teleport/src/UnifiedResources/Resources.tsx Outdated
Comment thread web/packages/teleport/src/UnifiedResources/Resources.tsx Outdated
Comment thread web/packages/teleport/src/UnifiedResources/Resources.tsx Outdated
Comment thread web/packages/teleport/src/components/hooks/useKeyBasedPagination.ts Outdated
Comment thread web/packages/teleport/src/components/hooks/useKeyBasedPagination.ts Outdated
Comment thread web/packages/teleport/src/components/hooks/useKeyBasedPagination.ts Outdated
Comment thread web/packages/teleport/src/components/hooks/useKeyBasedPagination.ts
Comment thread web/packages/teleport/src/components/hooks/useKeyBasedPagination.ts
Comment thread web/packages/teleport/src/services/agents/types.ts Outdated
Comment thread web/packages/teleport/src/components/hooks/useInfiniteScroll.ts Outdated
Comment thread web/packages/teleport/src/UnifiedResources/Resources.tsx Outdated
Comment thread web/packages/teleport/src/components/hooks/useKeyBasedPagination.ts Outdated
Comment thread web/packages/teleport/src/components/hooks/useKeyBasedPagination.ts Outdated
Comment thread web/packages/teleport/src/components/hooks/useKeyBasedPagination.ts
@avatus
Copy link
Copy Markdown
Contributor

avatus commented Aug 30, 2023

Seems reliable from local testing and I haven't been able to reproduce the bug you were talking about in a real-use scenario. Will go over the code again shortly

@bl-nero
Copy link
Copy Markdown
Contributor Author

bl-nero commented Aug 30, 2023

@avatus FYI, if you need to take a closer look at the error cases, it's easy with the new storybook that I created (PR in review, you can merge it with PR #31213 locally).

Comment thread web/packages/teleport/src/UnifiedResources/Resources.tsx Outdated
@bl-nero bl-nero requested review from avatus and kimlisa September 8, 2023 12:35
Comment thread web/packages/teleport/src/UnifiedResources/Resources.tsx
Comment thread web/packages/teleport/src/UnifiedResources/Resources.tsx
Comment thread web/packages/teleport/src/components/hooks/useInfiniteScroll/useInfiniteScroll.ts Outdated
Comment thread web/packages/teleport/src/services/agents/types.ts Outdated
Copy link
Copy Markdown
Contributor

@ibeckermayer ibeckermayer left a comment

Choose a reason for hiding this comment

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

Looking very close, just a final consideration re: useLayoutEffect vs the setState approach.

Comment on lines +69 to +70
// cause us to display incorrect data. This can be reproduced by rapidly
// changing filtering data on the resources list page.
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.

Suggested change
// cause us to display incorrect data. This can be reproduced by rapidly
// changing filtering data on the resources list page.
// cause us to display incorrect data. (This issue can be reproduced by switching this to
// `useEffect` and rapidly changing filtering data on the resources list page).

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 notice that we're using useLayoutEffect here for what seems to be an identical reason to why we're using this approach in useKeyBasedPagination. Is there a simple way that we can modify one or the other to use a single approach for achieving this effect? Related question: is there particular reason to generally prefer one over the other?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't know. Perhaps there is a better, simpler approach, but I think I reached a point of diminishing returns here with attempting to make this code as clear and robust as possible. I don't really remember why exactly, it was "just the way I did it".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Related question: is there particular reason to generally prefer one over the other?

I found this post to be useful. https://kentcdodds.com/blog/useeffect-vs-uselayouteffect

Copy link
Copy Markdown
Contributor

@ibeckermayer ibeckermayer Sep 15, 2023

Choose a reason for hiding this comment

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

@bl-nero If you don't know whether your design makes sense yet then feel free to convert this to a draft. Otherwise, come back to it and figure out the actual answer, I don't accept your apathetic response.

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.

Great tests

Co-authored-by: Isaiah Becker-Mayer <isaiah@goteleport.com>
Copy link
Copy Markdown
Contributor

@ibeckermayer ibeckermayer left a comment

Choose a reason for hiding this comment

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

@bl-nero bl-nero enabled auto-merge September 18, 2023 09:03
@bl-nero bl-nero added this pull request to the merge queue Sep 18, 2023
Merged via the queue into master with commit 1212306 Sep 18, 2023
@bl-nero bl-nero deleted the bl-nero/infinite-scroll-errors branch September 18, 2023 09:38
@public-teleport-github-review-bot
Copy link
Copy Markdown

@bl-nero See the table below for backport results.

Branch Result
branch/v14 Failed

bl-nero added a commit that referenced this pull request Sep 19, 2023
* Add some unit tests to the existing useInfiniteScroll hook

* Change the interface of the infinite scroll hook

Now it only exposes one fetch function that can be used to trigger fetches from infinite scroll, regardless of whether it's the initial or a subsequent fetch. Restarting the data stream is driven by changing filtering parameters.

* Harden useKeyBasedPagination

* Install jsdom-testing-mocks

* Error and retry support for infinite scroll

* Fix type-check

* Fix a state management bug

* Make useInfiniteScroll a wrapper over useKeyBasedPagination

* Get rid of unnecessary useEffect

* Address review comments

* Layout fixes

* Review

* Lint fix

* Add the license

* One more review round

* Tweak the comment in useInfiniteScroll

Co-authored-by: Isaiah Becker-Mayer <isaiah@goteleport.com>

---------

Co-authored-by: Isaiah Becker-Mayer <isaiah@goteleport.com>
github-merge-queue Bot pushed a commit that referenced this pull request Sep 19, 2023
* Add some unit tests to the existing useInfiniteScroll hook

* Change the interface of the infinite scroll hook

Now it only exposes one fetch function that can be used to trigger fetches from infinite scroll, regardless of whether it's the initial or a subsequent fetch. Restarting the data stream is driven by changing filtering parameters.

* Harden useKeyBasedPagination

* Install jsdom-testing-mocks

* Error and retry support for infinite scroll

* Fix type-check

* Fix a state management bug

* Make useInfiniteScroll a wrapper over useKeyBasedPagination

* Get rid of unnecessary useEffect

* Address review comments

* Layout fixes

* Review

* Lint fix

* Add the license

* One more review round

* Tweak the comment in useInfiniteScroll



---------

Co-authored-by: Isaiah Becker-Mayer <isaiah@goteleport.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants