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

ServiceWorker observing lifecycle not working as expected #1011

Open
ingosch opened this issue Aug 2, 2021 · 0 comments
Open

ServiceWorker observing lifecycle not working as expected #1011

ingosch opened this issue Aug 2, 2021 · 0 comments

Comments

@ingosch
Copy link

ingosch commented Aug 2, 2021

Sry, forget my initial post, my configuration was somehow messed up. But while testing and digging into serviceworkers I discovered some other issues with the ServiceWorkerManager that I don't understand.

protected void observeLifecycle(ServiceWorkerRegistration registration) {
        registration.onupdatefound = event -> {

            onNewServiceWorkerFound(new ServiceEvent(), registration.waiting);

            if (registration.installing != null) {
                onInstalling(new ServiceEvent());

                onStateChange(registration.installing);
            }

            if (registration.active != null) {
                onStateChange(registration.active);
            }
            return true;
        };
    }
  1. When reloading the page a servicworker that is waiting to be activated is ignored cause onupdatefound is not triggered in this case.
  2. Does calling onNewServiceWorkerFound with registration.waiting make sense? At that point there should usually be either no waiting SW or an older one that is to be replaced with the new one that triggered the onupdatefound event. IMHO the way it is at the moment onupdatefound will always be called together with onInstalling what is unnecessary.

I think using onupdatefound like it was until v2.2 (just calling it once on setup if registration.waiting is true) would make more sense and would solve problem nr. 1.

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

1 participant