Skip to content

Commit 83746c8

Browse files
committed
refactor: remove null check in register.ts options.base
Inside registerServiceWorker, we were originally using the nullash coalescing operator to check if options.base was null or undefined. However, I realized this check is not necessary. If you look at getOptions' return value, we return an object with a key "base" which is of type "string". We get that value by calling resolveBase which always returns a string. As a result, we didn't need to check if options.base was null or undefined because it never can be.
1 parent 6f2709b commit 83746c8

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/browser/register.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import "./pages/error.css"
44
import "./pages/global.css"
55
import "./pages/login.css"
66

7-
async function registerServiceWorker(): Promise<void> {
7+
export async function registerServiceWorker(): Promise<void> {
88
const options = getOptions()
99
const path = normalize(`${options.csStaticBase}/dist/serviceWorker.js`)
1010
try {
1111
await navigator.serviceWorker.register(path, {
12-
scope: (options.base ?? "") + "/",
12+
scope: options.base + "/",
1313
})
1414
console.log("[Service Worker] registered")
1515
} catch (error) {

test/unit/register.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ describe("register", () => {
105105
const location: LocationLike = {
106106
pathname: "",
107107
origin: "http://localhost:8080",
108-
// search: "?environmentId=600e0187-0909d8a00cb0a394720d4dce",
109108
}
110109
const { window } = new JSDOM()
111110
global.window = (window as unknown) as Window & typeof globalThis

0 commit comments

Comments
 (0)