- Updated the index.html to load the env-config.js script as a module for better compatibility. - Improved the unregister logic in both the unregister-sw.js and login-page.tsx to specifically target the ngsw-worker, ensuring it is unregistered correctly and the page reloads afterward. This prevents multiple unregister attempts and enhances user experience.
23 lines
879 B
JavaScript
23 lines
879 B
JavaScript
if ('serviceWorker' in navigator) {
|
|
// Check if we've already attempted to unregister in this session
|
|
if (!sessionStorage.getItem('swUnregisterAttempted')) {
|
|
navigator.serviceWorker.getRegistrations().then(function(registrations) {
|
|
const ngswWorker = registrations.find(reg => reg.active?.scriptURL.includes('ngsw-worker'));
|
|
|
|
if (ngswWorker) {
|
|
// Mark that we've attempted to unregister
|
|
sessionStorage.setItem('swUnregisterAttempted', 'true');
|
|
// Unregister the ngsw-worker
|
|
ngswWorker.unregister().then(() => {
|
|
// Reload the page after unregistering
|
|
window.location.reload(true);
|
|
});
|
|
} else {
|
|
// If no ngsw-worker is found, unregister any other service workers
|
|
for(let registration of registrations) {
|
|
registration.unregister();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|