From cbe09147afe50379c6fbd27f1b9f421a226a4b93 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Fri, 24 Oct 2025 20:16:02 -0700 Subject: [PATCH] [bugfix] fix service worker registration timing to run after Pinia setup (#6272) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes Pinia initialization error that occurred when the auth service worker tried to access stores before Pinia was set up. The auth service worker was being imported at the top of `main.ts`, causing it to register immediately: ```typescript import '@/platform/auth/serviceWorker' // Runs immediately on import ``` This happened before Pinia was initialized, causing an error when the service worker setup tried to use stores: ``` Error: [🍍]: "getActivePinia()" was called but there was no active Pinia. ``` Moved the service worker registration to after Pinia is set up but before mounting the app: ```typescript .use(pinia) .use(i18n) .use(VueFire, { firebaseApp, modules: [VueFireAuth()] }) // Register auth service worker after Pinia is initialized (cloud-only) if (isCloud) { void import('@/platform/auth/serviceWorker') } app.mount('#vue-app') ``` - βœ… Pinia stores are available when service worker setup runs - βœ… Still tree-shaken for non-cloud builds via dynamic import in `if (isCloud)` - βœ… Registers before mounting, so service worker is active from the start - Verified no Pinia errors in cloud builds - Verified tree-shaking still works (service worker code not in localhost builds) ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6272-bugfix-fix-service-worker-registration-timing-to-run-after-Pinia-setup-2976d73d365081b998dfd2eded782070) by [Unito](https://www.unito.io) --- src/main.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 979b32d26d..90e060bb8f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,7 +13,6 @@ import { VueFire, VueFireAuth } from 'vuefire' import { FIREBASE_CONFIG } from '@/config/firebase' import '@/lib/litegraph/public/css/litegraph.css' -import '@/platform/auth/serviceWorker' import { isCloud } from '@/platform/distribution/types' import router from '@/router' @@ -85,4 +84,10 @@ app firebaseApp, modules: [VueFireAuth()] }) - .mount('#vue-app') + +// Register auth service worker after Pinia is initialized (cloud-only) +if (isCloud) { + void import('@/platform/auth/serviceWorker') +} + +app.mount('#vue-app')