Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link old service worker to new name #21581

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-scripts/gulp/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const compressDistZopfli = (rootDir, modernDir) =>
[
`${rootDir}/**/${filesGlob}`,
`!${modernDir}/**/${filesGlob}`,
`!${rootDir}/sw-modern.js`,
`!${rootDir}/{sw-modern,service_worker}.js`,
`${rootDir}/{authorize,onboarding}.html`,
],
{ base: rootDir }
Expand Down
12 changes: 9 additions & 3 deletions build-scripts/gulp/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { deleteAsync } from "del";
import gulp from "gulp";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join, relative } from "node:path";
import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";
import { basename, join, relative } from "node:path";
import { injectManifest } from "workbox-build";
import paths from "../paths.cjs";

Expand Down Expand Up @@ -41,10 +41,11 @@ gulp.task("gen-service-worker-app-prod", () =>
await readFile(join(outPath, "manifest.json"), "utf-8")
);
const swSrc = join(paths.app_output_root, manifest["service-worker.js"]);
const swDest = join(paths.app_output_root, `sw-${build}.js`);
const buildDir = relative(paths.app_output_root, outPath);
const { warnings } = await injectManifest({
swSrc,
swDest: join(paths.app_output_root, `sw-${build}.js`),
swDest,
injectionPoint: "__WB_MANIFEST__",
// Files that mach this pattern will be considered unique and skip revision check
// ignore JS files + translation files
Expand Down Expand Up @@ -76,6 +77,11 @@ gulp.task("gen-service-worker-app-prod", () =>
);
}
await deleteAsync(`${swSrc}?(.map)`);
// Needed to install new SW from a cached HTML
if (build === "modern") {
const swOld = join(paths.app_output_root, "service_worker.js");
await symlink(basename(swDest), swOld);
}
})
)
);
7 changes: 0 additions & 7 deletions src/util/register-service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ export const registerServiceWorker = async (
return;
}

if (reg?.active?.scriptURL.includes("service_worker.js")) {
// We are running an old version of the service worker. Force reload.
await reg.unregister();
// @ts-ignore Firefox supports force reload
location.reload(true);
}

reg.addEventListener("updatefound", () => {
const installingWorker = reg.installing;

Expand Down
Loading