Skip to content

Commit

Permalink
Clean up unnecessary code now that same-page link clicks are handled …
Browse files Browse the repository at this point in the history
…outside a Visit
  • Loading branch information
domchristie committed Jul 20, 2024
1 parent ce33887 commit e396fa5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 68 deletions.
16 changes: 3 additions & 13 deletions src/core/drive/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,10 @@ export class Navigator {
this.delegate.visitCompleted(visit)
}

// 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
Expand Down
37 changes: 6 additions & 31 deletions src/core/drive/visit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.visitCachedSnapshot = visitCachedSnapshot
this.willRender = willRender
this.updateHistory = updateHistory
Expand All @@ -109,10 +108,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)
Expand Down Expand Up @@ -249,17 +244,13 @@ export class Visit {
const isPreview = this.shouldIssueRequest()
this.render(async () => {
this.cacheSnapshot()
if (this.isSamePage) {
this.adapter.visitRendered(this)
} else {
if (this.view.renderPromise) await this.view.renderPromise
if (this.view.renderPromise) await this.view.renderPromise

await this.renderPageSnapshot(snapshot, isPreview)
await this.renderPageSnapshot(snapshot, isPreview)

this.adapter.visitRendered(this)
if (!isPreview) {
this.complete()
}
this.adapter.visitRendered(this)
if (!isPreview) {
this.complete()
}
})
}
Expand All @@ -277,17 +268,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) {
Expand Down Expand Up @@ -349,9 +329,6 @@ export class Visit {
} else {
this.scrollToAnchor() || this.view.scrollToTop()
}
if (this.isSamePage) {
this.delegate.visitScrolledToSamePageLocation(this.view.lastRenderedLocation, this.location)
}

this.scrolled = true
}
Expand Down Expand Up @@ -400,9 +377,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
Expand Down
1 change: 0 additions & 1 deletion src/core/native/browser_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class BrowserAdapter {
this.location = visit.location
visit.loadCachedSnapshot()
visit.issueRequest()
visit.goToSamePageAnchor()
}

visitRequestStarted(visit) {
Expand Down
25 changes: 2 additions & 23 deletions src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,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) {
Expand All @@ -263,14 +261,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) {
Expand Down Expand Up @@ -310,9 +300,7 @@ export class Session {
// Page view delegate

viewWillCacheSnapshot() {
if (!this.navigator.currentVisit?.silent) {
this.notifyApplicationBeforeCachingSnapshot()
}
this.notifyApplicationBeforeCachingSnapshot()
}

allowsImmediateRender({ element }, options) {
Expand Down Expand Up @@ -404,15 +392,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 })
}
Expand Down

0 comments on commit e396fa5

Please sign in to comment.