@jon49/sw 0.12.11 → 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.
@@ -51,11 +51,15 @@ export async function fileMapper(targetDirectory: string, force = false) {
51
51
  })
52
52
  .filter(isFileMapper)
53
53
 
54
- // Write mapper to file in src/web/file-map.js
55
54
  if (option.isWaiting) return
56
- let fileMapContent = `(() => { self.app = { links: ${JSON.stringify(mapper)} } })()`
57
- let hash = getHash(fileMapContent)
55
+ // Write mapper to file in src/web/file-map.js
56
+ let fileMapJsonContent = JSON.stringify(mapper)
57
+ let hash = getHash(fileMapJsonContent)
58
58
  let fileMapUrl = `/web/file-map.${hash}.js`
59
+
60
+ fileMapJsonContent = `${fileMapJsonContent.slice(0, -1)},{"url":"/web/file-map.js","file":"${fileMapUrl}"}]`
61
+
62
+ let fileMapContent = `(() => { self.app = { links: ${fileMapJsonContent} } })()`
59
63
  await write(`${targetDirectory}${fileMapUrl}`, fileMapContent)
60
64
 
61
65
  let globalFiles =
@@ -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.reload()
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
- // @ts-ignore
2
- let links: { file: string, url: string }[] | undefined = self.app?.links
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jon49/sw",
3
- "version": "0.12.11",
3
+ "version": "0.12.13",
4
4
  "description": "Packages for MVC service workers.",
5
5
  "type": "module",
6
6
  "files": [