File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ export function createRouter(
58
58
59
59
let latestPendingPath : string | null = null
60
60
61
- async function loadPage ( href : string , scrollPosition = 0 ) {
61
+ async function loadPage ( href : string , scrollPosition = 0 , isRetry = false ) {
62
62
const targetLoc = new URL ( href , fakeHost )
63
63
const pendingPath = ( latestPendingPath = targetLoc . pathname )
64
64
try {
@@ -106,6 +106,19 @@ export function createRouter(
106
106
if ( ! err . message . match ( / f e t c h / ) ) {
107
107
console . error ( err )
108
108
}
109
+
110
+ // retry on fetch fail: the page to hash map may have been invalidated
111
+ // because a new deploy happened while the page is open. Try to fetch
112
+ // the updated pageToHash map and fetch again.
113
+ if ( ! isRetry ) {
114
+ try {
115
+ const res = await fetch ( siteDataRef . value . base + 'hashmap.json' )
116
+ ; ( window as any ) . __VP_HASH_MAP__ = await res . json ( )
117
+ await loadPage ( href , scrollPosition , true )
118
+ return
119
+ } catch ( e ) { }
120
+ }
121
+
109
122
if ( latestPendingPath === pendingPath ) {
110
123
latestPendingPath = null
111
124
route . path = pendingPath
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { resolveConfig } from '../config'
5
5
import { renderPage } from './render'
6
6
import { OutputChunk , OutputAsset } from 'rollup'
7
7
import ora from 'ora'
8
+ import path from 'path'
8
9
9
10
export async function build (
10
11
root : string ,
@@ -68,6 +69,13 @@ export async function build(
68
69
spinner . stopAndPersist ( {
69
70
symbol : okMark
70
71
} )
72
+
73
+ // emit page hash map for the case where a user session is open
74
+ // when the site got redeployed (which invalidates current hash map)
75
+ fs . writeJSONSync (
76
+ path . join ( siteConfig . outDir , 'hashmap.json' ) ,
77
+ pageToHashMap
78
+ )
71
79
} finally {
72
80
await fs . remove ( siteConfig . tempDir )
73
81
}
You can’t perform that action at this time.
0 commit comments