Skip to content

Commit a262b72

Browse files
committed
Clean up unnecessary code now that same-page link clicks are handled outside a Visit
1 parent 4ba8aea commit a262b72

File tree

4 files changed

+8
-61
lines changed

4 files changed

+8
-61
lines changed

src/core/drive/navigator.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getVisitAction } from "../../util"
22
import { FormSubmission } from "./form_submission"
3-
import { expandURL, getAnchor, getRequestURL } from "../url"
3+
import { expandURL } from "../url"
44
import { Visit } from "./visit"
55
import { PageSnapshot } from "./page_snapshot"
66

@@ -128,20 +128,10 @@ export class Navigator {
128128
delete this.currentVisit
129129
}
130130

131+
// Same-page links are no longer handled with a Visit.
132+
// This method is still needed for Turbo Native adapters.
131133
locationWithActionIsSamePage(location, action) {
132-
const anchor = getAnchor(location)
133-
const currentAnchor = getAnchor(this.view.lastRenderedLocation)
134-
const isRestorationToTop = action === "restore" && typeof anchor === "undefined"
135-
136-
return (
137-
action !== "replace" &&
138-
getRequestURL(location) === getRequestURL(this.view.lastRenderedLocation) &&
139-
(isRestorationToTop || (anchor != null && anchor !== currentAnchor))
140-
)
141-
}
142-
143-
visitScrolledToSamePageLocation(oldURL, newURL) {
144-
this.delegate.visitScrolledToSamePageLocation(oldURL, newURL)
134+
return false
145135
}
146136

147137
// Visits

src/core/drive/visit.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export class Visit {
8383
this.snapshot = snapshot
8484
this.snapshotHTML = snapshotHTML
8585
this.response = response
86-
this.isSamePage = this.delegate.locationWithActionIsSamePage(this.location, this.action)
8786
this.isPageRefresh = this.view.isPageRefresh(this)
8887
this.visitCachedSnapshot = visitCachedSnapshot
8988
this.willRender = willRender
@@ -110,10 +109,6 @@ export class Visit {
110109
return this.history.getRestorationDataForIdentifier(this.restorationIdentifier)
111110
}
112111

113-
get silent() {
114-
return this.isSamePage
115-
}
116-
117112
start() {
118113
if (this.state == VisitState.initialized) {
119114
this.recordTimingMetric(TimingMetric.visitStart)
@@ -250,7 +245,7 @@ export class Visit {
250245
const isPreview = this.shouldIssueRequest()
251246
this.render(async () => {
252247
this.cacheSnapshot()
253-
if (this.isSamePage || this.isPageRefresh) {
248+
if (this.isPageRefresh) {
254249
this.adapter.visitRendered(this)
255250
} else {
256251
if (this.view.renderPromise) await this.view.renderPromise
@@ -278,17 +273,6 @@ export class Visit {
278273
}
279274
}
280275

281-
goToSamePageAnchor() {
282-
if (this.isSamePage) {
283-
this.render(async () => {
284-
this.cacheSnapshot()
285-
this.performScroll()
286-
this.changeHistory()
287-
this.adapter.visitRendered(this)
288-
})
289-
}
290-
}
291-
292276
// Fetch request delegate
293277

294278
prepareRequest(request) {
@@ -350,9 +334,6 @@ export class Visit {
350334
} else {
351335
this.scrollToAnchor() || this.view.scrollToTop()
352336
}
353-
if (this.isSamePage) {
354-
this.delegate.visitScrolledToSamePageLocation(this.view.lastRenderedLocation, this.location)
355-
}
356337

357338
this.scrolled = true
358339
}
@@ -401,9 +382,7 @@ export class Visit {
401382
}
402383

403384
shouldIssueRequest() {
404-
if (this.isSamePage) {
405-
return false
406-
} else if (this.action == "restore") {
385+
if (this.action == "restore") {
407386
return !this.hasCachedSnapshot()
408387
} else {
409388
return this.willRender

src/core/native/browser_adapter.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export class BrowserAdapter {
2222
this.location = visit.location
2323
visit.loadCachedSnapshot()
2424
visit.issueRequest()
25-
visit.goToSamePageAnchor()
2625
}
2726

2827
visitRequestStarted(visit) {

src/core/session.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,7 @@ export class Session {
253253
this.view.markVisitDirection(visit.direction)
254254
}
255255
extendURLWithDeprecatedProperties(visit.location)
256-
if (!visit.silent) {
257-
this.notifyApplicationAfterVisitingLocation(visit.location, visit.action)
258-
}
256+
this.notifyApplicationAfterVisitingLocation(visit.location, visit.action)
259257
}
260258

261259
visitCompleted(visit) {
@@ -264,14 +262,6 @@ export class Session {
264262
this.notifyApplicationAfterPageLoad(visit.getTimingMetrics())
265263
}
266264

267-
locationWithActionIsSamePage(location, action) {
268-
return this.navigator.locationWithActionIsSamePage(location, action)
269-
}
270-
271-
visitScrolledToSamePageLocation(oldURL, newURL) {
272-
this.notifyApplicationAfterVisitingSamePageLocation(oldURL, newURL)
273-
}
274-
275265
// Form submit observer delegate
276266

277267
willSubmitForm(form, submitter) {
@@ -311,9 +301,7 @@ export class Session {
311301
// Page view delegate
312302

313303
viewWillCacheSnapshot() {
314-
if (!this.navigator.currentVisit?.silent) {
315-
this.notifyApplicationBeforeCachingSnapshot()
316-
}
304+
this.notifyApplicationBeforeCachingSnapshot()
317305
}
318306

319307
allowsImmediateRender({ element }, options) {
@@ -405,15 +393,6 @@ export class Session {
405393
})
406394
}
407395

408-
notifyApplicationAfterVisitingSamePageLocation(oldURL, newURL) {
409-
dispatchEvent(
410-
new HashChangeEvent("hashchange", {
411-
oldURL: oldURL.toString(),
412-
newURL: newURL.toString()
413-
})
414-
)
415-
}
416-
417396
notifyApplicationAfterFrameLoad(frame) {
418397
return dispatch("turbo:frame-load", { target: frame })
419398
}

0 commit comments

Comments
 (0)