fix(service-worker): enhance unregister logic and update index.html
- 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.
This commit is contained in:
@@ -77,6 +77,18 @@ const LoginPage: React.FC = () => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Check and unregister ngsw-worker if present
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.getRegistrations().then(function(registrations) {
|
||||
const ngswWorker = registrations.find(reg => reg.active?.scriptURL.includes('ngsw-worker'));
|
||||
if (ngswWorker) {
|
||||
ngswWorker.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
trackMixpanelEvent(evt_login_page_visit);
|
||||
if (currentSession && !currentSession?.setup_completed) {
|
||||
navigate('/worklenz/setup');
|
||||
|
||||
Reference in New Issue
Block a user