Skip to content

Commit 769f643

Browse files
committed
Force clear remembered state on page reload
1 parent f1e360c commit 769f643

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

packages/inertia/src/router.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class Router {
1414
protected resolveComponent!: PageResolver
1515
protected swapComponent!: PageHandler
1616
protected visitOptions!: VisitOptions
17+
protected navigationType?: string
1718
protected activeVisit?: ActiveVisit
1819
protected visitId: VisitId = null
1920

@@ -33,6 +34,9 @@ export class Router {
3334
this.swapComponent = swapComponent
3435
this.visitOptions = visitOptions
3536

37+
this.setNavigationType()
38+
this.clearRememberedStateOnReload()
39+
3640
if (this.isBackForwardVisit()) {
3741
this.handleBackForwardVisit(this.page)
3842
} else if (this.isLocationVisit()) {
@@ -44,6 +48,18 @@ export class Router {
4448
this.setupEventListeners()
4549
}
4650

51+
protected setNavigationType(): void {
52+
this.navigationType = (window.performance && window.performance.getEntriesByType('navigation').length > 0)
53+
? (window.performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming).type
54+
: 'navigate'
55+
}
56+
57+
protected clearRememberedStateOnReload(): void {
58+
if (this.navigationType === 'reload' && window.history.state?.rememberedState) {
59+
delete window.history.state.rememberedState
60+
}
61+
}
62+
4763
protected handleInitialPageVisit(page: Page): void {
4864
this.page.url += window.location.hash
4965
this.setPage(page, { preserveState: true }).then(() => fireNavigateEvent(page))
@@ -109,10 +125,7 @@ export class Router {
109125
}
110126

111127
protected isBackForwardVisit(): boolean {
112-
return window.history.state
113-
&& window.performance
114-
&& window.performance.getEntriesByType('navigation').length > 0
115-
&& (window.performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming).type === 'back_forward'
128+
return window.history.state && this.navigationType === 'back_forward'
116129
}
117130

118131
protected handleBackForwardVisit(page: Page): void {

0 commit comments

Comments
 (0)