AxaFrance / oidc-client

Light, Secure, Pure Javascript OIDC (Open ID Connect) Client. We provide also a REACT wrapper (compatible NextJS, etc.).
MIT License
573 stars 152 forks source link

Loop of Service Worker initialisation when local app opened and reopened with different oidc package version installed #1400

Open piotrbartnik opened 4 days ago

piotrbartnik commented 4 days ago

Issue and Steps to Reproduce

When we change the version of oidc-client and oidc-client-service-worker in local development between runs sometimes the app can't be loaded properly again.

App is reloaded couple of times, sometimes infinitely.

It seems that service worker for some reason is not activated properly on downgraded/upgraded version.

It is triggered inside initWorkerAsync.ts. When if(serviceWorkerVersion !== codeVersion) the console log about unregistering and reloading is prompted. Then the service_worker_update_require_callback kicks in with default reload of page.

It happens in my personal react app where I try similar steps but also for AxaFrance/oidc-client.git demo app with below steps. Sometimes the index.js:255 Service worker 7.22.9 version mismatch with js client version 7.22.8, unregistering and reloading happens once, sometimes twice, sometimes multiple times (together with reloading, unregistering and registering service worker again - basically whole process).

When the problem with more than one reload occurs the console logs seem to follow the pattern:

> Service worker 7.22.9 version mismatch with js client version 7.22.8, unregistering and reloading
> [OidcServiceWorker] service worker installed 1720185015
> TypeError: Failed to fetch
    at me ()
    at r ()
    at Object.startKeepAliveServiceWorker ()
    at mn ()
> [vite] connecting...
> [vite] connected.
>  Service worker 7.22.9 version mismatch with js client version 7.22.8, unregistering and reloading
... looped again

Versions

Tried with 7.22.9 -> 7.22.8 -> 7.22.9 as well as with 7.22.9 -> 7.22.7 -> 7.22.9 Browser: chrome latest (haven't tested on other browsers),

Screenshots

Axa fr demo react app single reload (proper(?) behavior):

Screenshot 2024-07-05 at 15 41 16

Axa fr demo react app double reload (probably improper behavior with service worker not being registerer properly for the first time):

Screenshot 2024-07-05 at 16 10 22

Axa fr demo react app infinite reload:

Screenshot 2024-07-05 at 15 24 15

My app with more than one reload but finally opening properly after 7th time (sometimes it's one time, sometimes infinite):

Screenshot 2024-07-05 at 16 37 36

Expected

Service worker is properly unregistered and registered in one try when version of packages changes between opening dev server locally after reinstalling packages.

Actual

Sometimes whole process gets in a loop and try to register the service worker multiple times

Additional Details

guillaume-chervet commented 4 days ago

Hi @piotrbartnik , thank yoi for your issue. I had this behavior today upgrading my current application and it is a very important problem to resolve. I think i will try a more agressive unregistration.