question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Programmatic navigation doesn't trigger service worker update

See original GitHub issue

Programmatic navigation doesn’t trigger a service worker update; new content isn’t shown when I use navigate.

Further information I’m using Strapi as my CMS to pull in data at build time, gatsby-plugin-offline and the onServiceWorkerUpdateReady method with a prompt to reload window.

When I enter my site and then click on a ‘link’ that uses navigate, new content isn’t shown on the page I’m navigating to unless I manually refresh the page. I’m using programmatic navigation (with navigate) because I want to animate on leaving the page.

Using Gatsby’s Link or the gatsby plugin transition link package, new content shows when I navigate to the page in question without a refresh.

I can just use gatsby plugin transition link for my purposes, but thought it’s worth reporting this anyway.

The website: https://amyrodriguez.netlify.app

Expected result

I expect programmatic navigation using navigate to trigger a service worker update and show the new content.

Actual result

New content isn’t shown (without a refresh).

Environment

System: OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa) CPU: (4) x64 Intel® Core™ i5-7400 CPU @ 3.00GHz Shell: 5.8 - /usr/bin/zsh Binaries: Node: 12.18.3 - ~/.nvm/versions/node/v12.18.3/bin/node npm: 6.14.6 - ~/.nvm/versions/node/v12.18.3/bin/npm Browsers: Chrome: 85.0.4183.102 Firefox: 81.0 npmPackages: gatsby: ^2.24.76 => 2.24.76 gatsby-image: ^2.4.21 => 2.4.21 gatsby-plugin-client-side-redirect: ^1.1.0 => 1.1.0 gatsby-plugin-emotion: ^4.3.13 => 4.3.13 gatsby-plugin-google-analytics: ^2.3.18 => 2.3.18 gatsby-plugin-manifest: ^2.4.34 => 2.4.34 gatsby-plugin-netlify: ^2.3.17 => 2.3.17 gatsby-plugin-offline: ^3.2.31 => 3.2.31 gatsby-plugin-react-helmet: ^3.3.14 => 3.3.14 gatsby-plugin-remove-fingerprints: 0.0.2 => 0.0.2 gatsby-plugin-remove-trailing-slashes: ^2.3.13 => 2.3.13 gatsby-plugin-sharp: ^2.6.42 => 2.6.42 gatsby-source-shopify: ^3.2.36 => 3.2.36 gatsby-source-strapi: 0.0.12 => 0.0.12 gatsby-transformer-sharp: ^2.5.17 => 2.5.17 npmGlobalPackages: gatsby-cli: 2.12.87

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
TylerBarnescommented, Oct 22, 2020

👍 one thing to note is that transition-link actually uses both gatsby-link and navigate. Gatsby links are added to the page to enable prefetching, but there’s an onClick that prevents it from navigating, then it sets up it’s own state and calls navigate at the right time. So in this case it could be that the presence of gatsby-link is what’s making it work, but just using navigate alone doesn’t work.

1reaction
ascorbiccommented, Oct 22, 2020

Thanks. This is surprising, because gatsby plugin transition link uses navigate under the hood. I’ll tag @TylerBarnes who wrote that plugin to see if he has any insight

Read more comments on GitHub >

github_iconTop Results From Across the Web

Programmatically update service worker if update() is not ...
How can I programmatically update service worker since ServiceWorkerRegistration.update() has not been implemented in Chrome yet?
Read more >
Handling Service Worker updates – how to keep the app ...
By ensuring our update UX is only triggered when we're sure there's a Service Worker instance visible under registration.waiting (successfully installed, ...
Read more >
ServiceWorker doesn't always trigger .available method
The service worker doesn't always trigger .available() method after when it downloads new files in the background.
Read more >
How to Fix the Refresh Button When Using Service Workers
To listen for a new Service Worker, we'll need to use a ServiceWorkerRegistration object. In our “naive” attempt to hook up a Service...
Read more >
Let Users Know When You Have Updated Your Service ...
This piece is going to show you how to trigger an alert (or toast or actually whatever component you want) when you have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found