Skip to content

Commit

Permalink
web: Register PWA reload script earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
schneefux committed Dec 22, 2024
1 parent 20b8323 commit 8d423f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions web/renderer/+onRenderClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ export { onRenderClient }
async function onRenderClient(pageContext: PageContext) {
const params = createApp(pageContext)

initSentry(pageContext.envConfig.sentryDsn, params.app, params.router)
hydrate(params.queryClient, pageContext.vueQueryState)
params.pinia.state.value = SuperJSON.parse(pageContext.piniaState)
await params.router.isReady()

const { registerSW } = await import('virtual:pwa-register') // use dynamic import to fetch sw at runtime
registerSW({
immediate: true, // reload app when service worker updates
Expand All @@ -29,5 +24,12 @@ async function onRenderClient(pageContext: PageContext) {
})
},
})

initSentry(pageContext.envConfig.sentryDsn, params.app, params.router)
hydrate(params.queryClient, pageContext.vueQueryState)
params.pinia.state.value = SuperJSON.parse(pageContext.piniaState)

await params.router.isReady()

params.app.mount('#app')
}
2 changes: 1 addition & 1 deletion web/renderer/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function createApp(pageContext: PageContext) {
},
],
link: [
{ rel: 'manifest', href: '/manifest.webmanifest' },
{ rel: 'manifest', href: '/manifest.webmanifest' }, // TODO try https://vite-pwa-org.netlify.app/frameworks/#accessing-pwa-info instead
{ rel: 'icon', href: '/icons/favicon.ico', sizes: 'any' },
{ rel: 'icon', href: '/icons/favicon.svg', type: 'image/svg+xml' },
{ rel: 'apple-touch-icon', href: '/icons/icon_x512.png', sizes: '512x512' },
Expand Down
2 changes: 1 addition & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const config: UserConfig = {
resolver: 'vue',
}),
VitePWA({
injectRegister: null, // not supported by vike, injected in all.page.client instead
injectRegister: null, // not supported by vike, injected in +onRenderClient.ts instead
registerType: 'autoUpdate',
devOptions: {
enabled: false,
Expand Down

0 comments on commit 8d423f7

Please sign in to comment.