@prunellejs/spa 0.7.3 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/prefetch.ts +1 -1
- package/src/regions.ts +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prunellejs/spa",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Opt-in SPA navigation with persistent islands plugin for Prunelle",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
"directory": "packages/plugin-spa"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"prunelle": "^0.7.
|
|
29
|
+
"prunelle": "^0.7.4"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/prefetch.ts
CHANGED
|
@@ -98,7 +98,7 @@ export async function prefetch(url: string, region?: string): Promise<void> {
|
|
|
98
98
|
|
|
99
99
|
const task = (async (): Promise<PrefetchEntry | undefined> => {
|
|
100
100
|
try {
|
|
101
|
-
const res = await fetch(clean.href, { headers: region === undefined ? { 'x-pru-spa': '1'
|
|
101
|
+
const res = await fetch(clean.href, { headers: { ...(region === undefined ? { 'x-pru-spa': '1' } : { 'x-pru-region': region }), 'accept': HTML_ACCEPT, 'purpose': 'prefetch' } })
|
|
102
102
|
if (!res.ok || !(res.headers.get('content-type') ?? '').includes('text/html')) {
|
|
103
103
|
void res.body?.cancel()
|
|
104
104
|
return undefined
|
package/src/regions.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import type { PrefetchEntry } from './prefetch'
|
|
12
12
|
import type { EntryScroll } from './swap'
|
|
13
13
|
import { announce } from './announcer'
|
|
14
|
-
import { countView, fetchKeyOf, getCachedHtml, getDocId, inflightPrefetch, isSameDocRegionState, listenIntent, prefetch, prefetchCache } from './prefetch'
|
|
14
|
+
import { countView, fetchKeyOf, getCachedHtml, getDocId, HTML_ACCEPT, inflightPrefetch, isSameDocRegionState, listenIntent, prefetch, prefetchCache } from './prefetch'
|
|
15
15
|
import { entryScroll, readScrolls, restoreScroll, saveScroll, swapInTransition, trackScroll, writeScrolls } from './swap'
|
|
16
16
|
|
|
17
17
|
const BUSY_DELAY = 150
|
|
@@ -78,11 +78,13 @@ async function load(swap: Swap, region: string, signal: AbortSignal): Promise<Pr
|
|
|
78
78
|
prefetchCache.delete(key)
|
|
79
79
|
return ready
|
|
80
80
|
}
|
|
81
|
-
const res = await fetch(fetchKeyOf(url), { headers: { 'x-pru-region': region }, signal, ...(post === undefined ? {} : { method: 'POST', body: post.body }) })
|
|
81
|
+
const res = await fetch(fetchKeyOf(url), { headers: { 'x-pru-region': region, 'accept': HTML_ACCEPT }, signal, ...(post === undefined ? {} : { method: 'POST', body: post.body }) })
|
|
82
82
|
if (post !== undefined)
|
|
83
83
|
swap.landed = res.url
|
|
84
|
-
if (!res.ok || !(res.headers.get('content-type') ?? '').includes('text/html'))
|
|
84
|
+
if (!res.ok || !(res.headers.get('content-type') ?? '').includes('text/html')) {
|
|
85
|
+
void res.body?.cancel()
|
|
85
86
|
return undefined
|
|
87
|
+
}
|
|
86
88
|
return { html: await res.text(), url: res.url || fetchKeyOf(url), ts: Date.now(), region: res.headers.get('x-pru-region'), title: res.headers.get('x-pru-title') }
|
|
87
89
|
}
|
|
88
90
|
|