Skip to content

Commit

Permalink
Prevent unnecessary requests
Browse files Browse the repository at this point in the history
when restoring same-page visits with caching disabled.

Requests shouldn't be issued when navigating back/forward on same-page visits; the scroll position should just be restored. However, when caching is disabled Turbo does not have a scroll position value to restore to.

This change prioritizes checking for same-page visits to prevent unnecessary requests, and when restoring a scroll position, tries to scroll to the anchor if it exists. It's effectively the same outcome as before, without the request.
  • Loading branch information
ozguruysal authored and domchristie committed Jul 13, 2021
1 parent bbb4d4b commit 0800ec8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/drive/visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export class Visit implements FetchRequestDelegate {
performScroll() {
if (!this.scrolled) {
if (this.action == "restore") {
this.scrollToRestoredPosition() || this.scrollToTop()
this.scrollToRestoredPosition() || this.scrollToAnchor() || this.scrollToTop()
} else {
this.scrollToAnchor() || this.scrollToTop()
}
Expand Down Expand Up @@ -365,10 +365,10 @@ export class Visit implements FetchRequestDelegate {
}

shouldIssueRequest() {
if (this.action == "restore") {
return !this.hasCachedSnapshot()
} else if (this.isSamePage) {
if (this.isSamePage) {
return false
} else if (this.action == "restore") {
return !this.hasCachedSnapshot()
} else {
return true
}
Expand Down

0 comments on commit 0800ec8

Please sign in to comment.