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

WEBDEV-6636 Delay scrolling to page until content has loaded in #429

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/collection-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ export class CollectionBrowser
*/
private isScrollingToCell = false;

/**
* When we attempt to scroll to a page before the infinite scroller has
* been populated, this flag will be set, allowing us to complete the scroll
* once it is possible.
*/
private needsScrollToPage = false;

/**
* When page width resizes from desktop to mobile, set true to
* disable expand/collapse transition when loading.
Expand Down Expand Up @@ -1475,6 +1482,15 @@ export class CollectionBrowser
}

this.ensureAvailableTilesDisplayed();

if (
this.needsScrollToPage &&
this.currentPage &&
this.infiniteScroller?.itemCount
) {
this.needsScrollToPage = false;
this.scrollToPage(this.currentPage);
}
}

connectedCallback(): void {
Expand Down Expand Up @@ -1915,6 +1931,16 @@ export class CollectionBrowser
private scrollToPage(pageNumber: number): Promise<void> {
return new Promise(resolve => {
const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
// If the desired cell is not yet present in the infinite scroller, flag it to be
// scrolled later one ready.
if (
!this.infiniteScroller ||
this.infiniteScroller.itemCount < cellIndexToScrollTo
) {
this.needsScrollToPage = true;
return;
}

// without this setTimeout, Safari just pauses until the `fetchPage` is complete
// then scrolls to the cell
setTimeout(() => {
Expand Down
Loading