Skip to content

Commit bab4786

Browse files
[bugfix] fix service worker registration timing to run after Pinia setup (#6272)
## Summary Fixes Pinia initialization error that occurred when the auth service worker tried to access stores before Pinia was set up. ## Problem 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. ``` ## Solution 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') ``` ## Benefits - ✅ 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 ## Testing - 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)
1 parent 3c28dd2 commit bab4786

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { VueFire, VueFireAuth } from 'vuefire'
1313

1414
import { FIREBASE_CONFIG } from '@/config/firebase'
1515
import '@/lib/litegraph/public/css/litegraph.css'
16-
import '@/platform/auth/serviceWorker'
1716
import router from '@/router'
1817

1918
import App from './App.vue'
@@ -82,4 +81,10 @@ app
8281
firebaseApp,
8382
modules: [VueFireAuth()]
8483
})
85-
.mount('#vue-app')
84+
85+
// Register auth service worker after Pinia is initialized (cloud-only)
86+
if (isCloud) {
87+
void import('@/platform/auth/serviceWorker')
88+
}
89+
90+
app.mount('#vue-app')

0 commit comments

Comments
 (0)