Skip to content

search: preserve scroll position on navigating back to search results 馃帀

Created by: valerybugakov

Context

The scroll position is not preserved when going back to search results.

Changes

TLDR The scroll position is now preserved for page refresh and back navigation 馃帀

This PR does two things:

  • Adds ScrollManager that tracks the scroll position of the search results container, persists it to session storage, and restores it on back navigation or page refresh.
  • To avoid multiple UI jumps required to reach the previous scroll position, we need to render all items that the user already scrolled through. It's done by extending the itemsToShow state used in StreamingSearchResultsList.
    • It tracks the number of items shown for the last query and persists this info to session storage.
    • See use-items-to-show.test.ts with tests for all important use-cases.

https://user-images.githubusercontent.com/3846380/146541677-b48456d9-eaa5-42bd-a550-6fbeb97fc248.mov

Should be merged together with https://github.com/sourcegraph/sourcegraph/pull/29176. Closes https://github.com/sourcegraph/sourcegraph/issues/28845.

Merge request reports

Loading