@jon49/sw 0.12.12 → 0.12.13
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/lib/new-app-notifier.ts +3 -1
- package/lib/routes.ts +12 -2
- package/package.json +1 -1
package/lib/new-app-notifier.ts
CHANGED
|
@@ -4,7 +4,9 @@ let refreshing = false
|
|
|
4
4
|
// Here we reload the page
|
|
5
5
|
navigator.serviceWorker.addEventListener('controllerchange', function () {
|
|
6
6
|
if (refreshing) return
|
|
7
|
-
window.location.
|
|
7
|
+
let url = new URL(window.location.href)
|
|
8
|
+
url.searchParams.set("refresh", "hard")
|
|
9
|
+
window.location.href = url.href
|
|
8
10
|
refreshing = true
|
|
9
11
|
})
|
|
10
12
|
|
package/lib/routes.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
let { html, links } =
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
self.app as { links: { file: string, url: string }[], html: Function }
|
|
3
4
|
|
|
4
5
|
if (!links) {
|
|
5
6
|
console.error("Expecting links defined with `self.app.links`, but found none.")
|
|
@@ -174,6 +175,15 @@ async function executeHandler({ url, req, event }: ExectuteHandlerOptions) : Pro
|
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
if (isHtml(result)) {
|
|
178
|
+
if (req.referrer.length > 0) {
|
|
179
|
+
let referrer = new URL(req.referrer)
|
|
180
|
+
if (referrer.pathname.startsWith("/web")
|
|
181
|
+
&& url.searchParams.get("refresh") !== "hard"
|
|
182
|
+
&& req.headers.get("HF-Request") !== "true") {
|
|
183
|
+
result = html`<template>${result}</template>`
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
177
187
|
return streamResponse({
|
|
178
188
|
body: result,
|
|
179
189
|
headers: htmfHeader(req, null, messages)
|