Skip to content

Commit

Permalink
Add refresh visit action
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeiffer committed Feb 15, 2024
1 parent fccb3a4 commit 1fcc039
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/core/drive/page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class PageView extends View {
}

renderPage(snapshot, isPreview = false, willRender = true, visit) {
const shouldMorphPage = this.isPageRefresh(visit) && this.snapshot.shouldMorphPage
const shouldMorphPage = this.isMorphable(visit) && this.snapshot.shouldMorphPage
const rendererClass = shouldMorphPage ? MorphRenderer : PageRenderer

const renderer = new rendererClass(this.snapshot, snapshot, PageRenderer.renderElement, isPreview, willRender)
Expand Down Expand Up @@ -55,12 +55,20 @@ export class PageView extends View {
return this.snapshotCache.get(location)
}

isPageRefresh(visit) {
isReplacingSamePage(visit) {
return !visit || (this.lastRenderedLocation.pathname === visit.location.pathname && visit.action === "replace")
}

isRefreshing(visit) {
return visit && visit.action === "refresh"
}

isMorphable(visit) {
return this.isRefreshing(visit) || this.isReplacingSamePage(visit)
}

shouldPreserveScrollPosition(visit) {
return this.isPageRefresh(visit) && this.snapshot.shouldPreserveScrollPosition
return this.isMorphable(visit) && this.snapshot.shouldPreserveScrollPosition
}

get snapshot() {
Expand Down
4 changes: 3 additions & 1 deletion src/core/drive/visit.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export const SystemStatusCode = {
export const Direction = {
advance: "forward",
restore: "back",
replace: "none"
replace: "none",
refresh: "none"
}

export class Visit {
Expand Down Expand Up @@ -389,6 +390,7 @@ export class Visit {
getHistoryMethodForAction(action) {
switch (action) {
case "replace":
case "refresh":
return history.replaceState
case "advance":
case "restore":
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function registerAdapter(adapter) {
* @param location Location to visit (a URL or path)
* @param options Options to apply
* @param options.action Type of history navigation to apply ("restore",
* "replace" or "advance")
* "replace", "refresh" or "advance")
* @param options.historyChanged Specifies whether the browser history has
* already been changed for this visit or not
* @param options.referrer Specifies the referrer of this visit such that
Expand Down
2 changes: 1 addition & 1 deletion src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class Session {
const isRecentRequest = requestId && this.recentRequests.has(requestId)
if (!isRecentRequest) {
this.cache.exemptPageFromPreview()
this.visit(url, { action: "replace" })
this.visit(url, { action: "refresh" })
}
}

Expand Down

0 comments on commit 1fcc039

Please sign in to comment.