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

Allow control of the page that gets reloaded #498

Open
mehcode opened this issue Apr 2, 2023 · 3 comments
Open

Allow control of the page that gets reloaded #498

mehcode opened this issue Apr 2, 2023 · 3 comments

Comments

@mehcode
Copy link

mehcode commented Apr 2, 2023

Currently on a new service worker control, location.reload() is called. Can we configure this so instead we can do location.href = "/" or the equivalent? I'd much rather have an application reload back to the "home" on an update where the user has explicitly said "yes, I want to update" from the prompt.

@common-link-dev
Copy link

I also prefer to redirect to index page as the page where the update was installed could have been removed with the update.

@sir-script
Copy link

It would be nice to have a hook function for overriding the default reload behaviour.
(Some use cases: modify location url or prevent reloading in some special situations)

@piotr-cz
Copy link

piotr-cz commented Nov 15, 2024

I was trying to set location after updating service worker, but this resulted in strange behavior in recent Chrome versions - page was stuck at being reloaded (favicon spinning):

const updateServiceWorker = registerSW({
  immediate: true,
})

async function update() {
  await updateServiceWorker()
  window.location.replace(startUrl)
}

I guess for now better way is to use History: pushState or replaceState before updating.

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

4 participants