Skip to content

Commit

Permalink
fix(oidc): force sw update when new registration appears (release) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wermanoid authored Oct 2, 2024
1 parent c740d47 commit cc731c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/react-oidc-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"url": "https://github.com/AxaGuilDEv/react-oidc.git"
},
"scripts": {
"start": "vite",
"start": "pnpm prestart && pnpm vite",
"prestart": "node ./node_modules/@axa-fr/react-oidc/bin/copy-service-worker-files.mjs public",
"build": "vite build",
"serve": "vite preview",
"clean": "rimraf dist",
Expand Down
7 changes: 6 additions & 1 deletion packages/oidc-client/src/initWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export const initWorkerAsync = async (
registration = await configuration.service_worker_register(serviceWorkerRelativeUrl);
} else {
registration = await navigator.serviceWorker.register(serviceWorkerRelativeUrl);

if (registration.active && registration.waiting) {
console.log('Detected new service worker waiting, unregistering and reloading');
await configuration.service_worker_update_require_callback?.(registration, stopKeepAlive);
}
}

try {
Expand Down Expand Up @@ -151,7 +156,7 @@ export const initWorkerAsync = async (
console.warn(
`Service worker ${serviceWorkerVersion} version mismatch with js client version ${codeVersion}, unregistering and reloading`,
);
await oidcConfiguration.service_worker_update_require_callback(registration, stopKeepAlive);
await oidcConfiguration.service_worker_update_require_callback?.(registration, stopKeepAlive);
}

// @ts-ignore
Expand Down

0 comments on commit cc731c1

Please sign in to comment.