From 120847dda65612c4174b73b14c3dfd606ea64b09 Mon Sep 17 00:00:00 2001 From: Dom Christie Date: Sat, 20 Jul 2024 21:19:49 +0100 Subject: [PATCH] Clean up unnecessary code now that same-page link clicks are handled outside a Visit --- src/core/drive/navigator.js | 16 +++------------- src/core/drive/visit.js | 25 ++----------------------- src/core/native/browser_adapter.js | 1 - src/core/session.js | 25 ++----------------------- 4 files changed, 7 insertions(+), 60 deletions(-) diff --git a/src/core/drive/navigator.js b/src/core/drive/navigator.js index 8210c7471..a4698b65a 100644 --- a/src/core/drive/navigator.js +++ b/src/core/drive/navigator.js @@ -128,20 +128,10 @@ export class Navigator { delete this.currentVisit } + // Same-page links are no longer handled with a Visit. + // This method is still needed for Turbo Native adapters. locationWithActionIsSamePage(location, action) { - const anchor = getAnchor(location) - const currentAnchor = getAnchor(this.view.lastRenderedLocation) - const isRestorationToTop = action === "restore" && typeof anchor === "undefined" - - return ( - action !== "replace" && - getRequestURL(location) === getRequestURL(this.view.lastRenderedLocation) && - (isRestorationToTop || (anchor != null && anchor !== currentAnchor)) - ) - } - - visitScrolledToSamePageLocation(oldURL, newURL) { - this.delegate.visitScrolledToSamePageLocation(oldURL, newURL) + return false } // Visits diff --git a/src/core/drive/visit.js b/src/core/drive/visit.js index ec7565979..27b3a3741 100644 --- a/src/core/drive/visit.js +++ b/src/core/drive/visit.js @@ -83,7 +83,6 @@ export class Visit { this.snapshot = snapshot this.snapshotHTML = snapshotHTML this.response = response - this.isSamePage = this.delegate.locationWithActionIsSamePage(this.location, this.action) this.isPageRefresh = this.view.isPageRefresh(this) this.visitCachedSnapshot = visitCachedSnapshot this.willRender = willRender @@ -110,10 +109,6 @@ export class Visit { return this.history.getRestorationDataForIdentifier(this.restorationIdentifier) } - get silent() { - return this.isSamePage - } - start() { if (this.state == VisitState.initialized) { this.recordTimingMetric(TimingMetric.visitStart) @@ -250,7 +245,7 @@ export class Visit { const isPreview = this.shouldIssueRequest() this.render(async () => { this.cacheSnapshot() - if (this.isSamePage || this.isPageRefresh) { + if (this.isPageRefresh) { this.adapter.visitRendered(this) } else { if (this.view.renderPromise) await this.view.renderPromise @@ -278,17 +273,6 @@ export class Visit { } } - goToSamePageAnchor() { - if (this.isSamePage) { - this.render(async () => { - this.cacheSnapshot() - this.performScroll() - this.changeHistory() - this.adapter.visitRendered(this) - }) - } - } - // Fetch request delegate prepareRequest(request) { @@ -350,9 +334,6 @@ export class Visit { } else { this.scrollToAnchor() || this.view.scrollToTop() } - if (this.isSamePage) { - this.delegate.visitScrolledToSamePageLocation(this.view.lastRenderedLocation, this.location) - } this.scrolled = true } @@ -401,9 +382,7 @@ export class Visit { } shouldIssueRequest() { - if (this.isSamePage) { - return false - } else if (this.action == "restore") { + if (this.action == "restore") { return !this.hasCachedSnapshot() } else { return this.willRender diff --git a/src/core/native/browser_adapter.js b/src/core/native/browser_adapter.js index 6f4c73bfe..54ceda298 100644 --- a/src/core/native/browser_adapter.js +++ b/src/core/native/browser_adapter.js @@ -22,7 +22,6 @@ export class BrowserAdapter { this.location = visit.location visit.loadCachedSnapshot() visit.issueRequest() - visit.goToSamePageAnchor() } visitRequestStarted(visit) { diff --git a/src/core/session.js b/src/core/session.js index 1e1ae92ed..c88aade15 100644 --- a/src/core/session.js +++ b/src/core/session.js @@ -253,9 +253,7 @@ export class Session { this.view.markVisitDirection(visit.direction) } extendURLWithDeprecatedProperties(visit.location) - if (!visit.silent) { - this.notifyApplicationAfterVisitingLocation(visit.location, visit.action) - } + this.notifyApplicationAfterVisitingLocation(visit.location, visit.action) } visitCompleted(visit) { @@ -264,14 +262,6 @@ export class Session { this.notifyApplicationAfterPageLoad(visit.getTimingMetrics()) } - locationWithActionIsSamePage(location, action) { - return this.navigator.locationWithActionIsSamePage(location, action) - } - - visitScrolledToSamePageLocation(oldURL, newURL) { - this.notifyApplicationAfterVisitingSamePageLocation(oldURL, newURL) - } - // Form submit observer delegate willSubmitForm(form, submitter) { @@ -311,9 +301,7 @@ export class Session { // Page view delegate viewWillCacheSnapshot() { - if (!this.navigator.currentVisit?.silent) { - this.notifyApplicationBeforeCachingSnapshot() - } + this.notifyApplicationBeforeCachingSnapshot() } allowsImmediateRender({ element }, options) { @@ -405,15 +393,6 @@ export class Session { }) } - notifyApplicationAfterVisitingSamePageLocation(oldURL, newURL) { - dispatchEvent( - new HashChangeEvent("hashchange", { - oldURL: oldURL.toString(), - newURL: newURL.toString() - }) - ) - } - notifyApplicationAfterFrameLoad(frame) { return dispatch("turbo:frame-load", { target: frame }) }