fix(sw): guard navigator.serviceWorker access before feature check; fix EOF newline

Accessing navigator.serviceWorker.controller before the 'serviceWorker' in navigator
guard would throw a TypeError on browsers without SW support. Moved the guard into
the had_controller expression so the property is never accessed on unsupported browsers.

Also adds the missing trailing newline to core__export.ts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-06-22 21:09:21 -04:00
parent 6c822bc466
commit 3f73fc059e
2 changed files with 4 additions and 2 deletions

View File

@@ -65,4 +65,4 @@ export async function download_export__obj_type({
}
return result;
}
}

View File

@@ -346,7 +346,9 @@ $effect(() => {
// Added 2026-06-22 to close this gap.
// Capture before registering — if null, this is first activation (fresh page load)
// and the reload is unnecessary since assets were already fetched without the SW.
const had_controller = !!navigator.serviceWorker.controller;
// Guard must be part of the expression: navigator.serviceWorker doesn't exist on
// browsers without SW support, so accessing .controller before checking would throw.
const had_controller = 'serviceWorker' in navigator && !!navigator.serviceWorker.controller;
const on_controller_change = () => {
if (had_controller) window.location.reload();
};