Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
piotrbartnik opened this issue Jul 5, 2024 · 1 comment

Comments

@piotrbartnik
Copy link

piotrbartnik commented Jul 5, 2024

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).

  • clone and install git clone https://github.com/AxaFrance/oidc-client.git,
  • uncomment service worker mode (both service_worker_relative_url: '/OidcServiceWorker.js', in examples/react-oidc-demo/src/configurations.ts),
  • run the react app locally with pnpm start,
  • close dev server,
  • change oidc versions in packages/oidc-client/src/version.ts and packages/oidc-client-service-worker/src/version.ts to some lower version (in my case to 7.22.8 ,
  • install packages again,
  • run the dev server again,
  • see the console

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

  • actually it's hard to reproduce - tried multiple times to get the infinite loop but nonetheless the issue occurs sometmes,
  • in chrome://serviceworker-internals/ it is possible to see the service worker for localhost being removed and added again when the loop happens,
  • spotted only on local env. Not visible on any deployed site,
  • for my personal app the step with adding proper service worker in postinstall step is applied (thought it may be the reason for the loops at the beginning)
  • Installed packages:
    for demo axa app as in the repo,
    for my personal app "@axa-fr/oidc-client": "7.22.9",
@guillaume-chervet
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants