Skip to content

Commit ff91a5b

Browse files
jedryczkatymonAntoni-Czaplicki
authored andcommitted
fix: lint errors
1 parent ece69d8 commit ff91a5b

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

public/sw.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@
1616
- Badges: https://microsoft.github.io/win-student-devs/#/30DaysOfPWA/advanced-capabilities/07?id=application-badges
1717
*/
1818

19-
const HOSTNAME_WHITELIST = [
20-
self.location.hostname,
19+
const HOSTNAME_WHITELIST = new Set([
20+
globalThis.location.hostname,
2121
"fonts.gstatic.com",
2222
"fonts.googleapis.com",
2323
"cdn.jsdelivr.net",
24-
];
24+
]);
2525

2626
// The Util Function to hack URLs of intercepted requests
27-
const getFixedUrl = (req) => {
28-
var now = Date.now();
29-
var url = new URL(req.url);
27+
const getFixedUrl = (request) => {
28+
const now = Date.now();
29+
const url = new URL(request.url);
3030

3131
// 1. fixed http URL
3232
// Just keep syncing with location.protocol
3333
// fetch(httpURL) belongs to active mixed content.
3434
// And fetch(httpRequest) is not supported yet.
35-
url.protocol = self.location.protocol;
35+
url.protocol = globalThis.location.protocol;
3636

3737
// 2. add query for caching-busting.
3838
// Github Pages served with Cache-Control: max-age=600
3939
// max-age on mutable content is error-prone, with SW life of bugs can even extend.
4040
// Until cache mode of Fetch API landed, we have to workaround cache-busting with query string.
4141
// Cache-Control-Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=453190
42-
if (url.hostname === self.location.hostname) {
43-
url.search += (url.search ? "&" : "?") + "cache-bust=" + now;
42+
if (url.hostname === globalThis.location.hostname) {
43+
url.search += `${url.search ? "&" : "?"}cache-bust=${now}`;
4444
}
4545
return url.href;
4646
};
@@ -51,8 +51,8 @@ const getFixedUrl = (req) => {
5151
*
5252
* waitUntil(): activating ====> activated
5353
*/
54-
self.addEventListener("activate", (event) => {
55-
event.waitUntil(self.clients.claim());
54+
globalThis.addEventListener("activate", (event) => {
55+
event.waitUntil(globalThis.clients.claim());
5656
});
5757

5858
/**
@@ -61,9 +61,9 @@ self.addEventListener("activate", (event) => {
6161
*
6262
* void respondWith(Promise<Response> r)
6363
*/
64-
self.addEventListener("fetch", (event) => {
64+
globalThis.addEventListener("fetch", (event) => {
6565
// Skip some of cross-origin requests, like those for Google Analytics.
66-
if (HOSTNAME_WHITELIST.indexOf(new URL(event.request.url).hostname) > -1) {
66+
if (HOSTNAME_WHITELIST.has(new URL(event.request.url).hostname) > -1) {
6767
// Stale-while-revalidate
6868
// similar to HTTP's stale-while-revalidate: https://www.mnot.net/blog/2007/12/12/stale
6969
// Upgrade from Jake's to Surma's: https://gist.github.com/surma/eb441223daaedf880801ad80006389f1

src/components/service-worker-register.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ export function ServiceWorkerRegister() {
88
window.addEventListener("load", () => {
99
navigator.serviceWorker.register("/sw.js").then(
1010
(registration) => {
11-
console.log(
12-
"Service Worker registration successful with scope: ",
11+
console.warn(
12+
"Service Worker registration successful with scope:",
1313
registration.scope,
1414
);
1515
},
16-
(err) => {
17-
console.error("Service Worker registration failed: ", err);
16+
(error: unknown) => {
17+
console.error("Service Worker registration failed:", error);
1818
},
1919
);
2020
});

0 commit comments

Comments
 (0)