Skip to content

Commit e956da3

Browse files
committed
fix(offline): improve failure mode around package version injection
Also clarify comment on security header usage
1 parent 9d818b5 commit e956da3

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

public/service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ self.addEventListener("activate", (event) => {
6363
self.clients.claim();
6464
});
6565

66-
// Pyodide needs SharedArrayBuffer which requires the page to be cross-origin isolated. That means serving COOP + COEP on the HTML response, and CORP on every cross-origin resource the page loads
66+
// Pyodide needs SharedArrayBuffer which requires the page to be cross-origin isolated. That means serving COOP + COEP on the HTML response, and CORP on every cross-origin resource the page loads. We already set these headers on editor-static.raspberrypi.org, but worth being explicit here for other hosts eg. cdn.jsdelivr.net
6767
function addSecurityHeaders(response) {
6868
if (response.type === "opaque") return response;
6969
const headers = new Headers(response.headers);

webpack.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,16 @@ const mainConfig = {
240240
to: "",
241241
transform: (content, filePath) => {
242242
if (!filePath.endsWith("service-worker.js")) return content;
243-
const version = process.env.npm_package_version;
243+
const version =
244+
process.env.npm_package_version ??
245+
require("./package.json").version;
244246
return content
245247
.toString()
246248
.replace("editor-app-v1", `editor-app-v${version}`)
247-
.replace("editor-translations-v1", `editor-translations-v${version}`);
249+
.replace(
250+
"editor-translations-v1",
251+
`editor-translations-v${version}`,
252+
);
248253
},
249254
},
250255
{ from: "src/projects", to: "projects" },

0 commit comments

Comments
 (0)