Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
[docs] Workbox & service workers are causing infinite loading of site #23874
Comments
|
How did you conclude that it's related to the service workers? |
|
Im guessing there is a connection as if you unregister the service worker line 8 in sw.js what is part of the loop: I did not investigate further, Im now. But please look into it as well. |
|
Also by first impression it seems to be an issue mostly if you have dev tools open from some reason. |
|
But I have a clear way how to reproduce this (assuming that version of os doesnt matter), latest chrome (Version 87.0.4280.88 (Official Build) (x86_64)):
|
|
I can't reproduce. What are your accepted languages ( |
|
languages: |
|
@huttarichard Ok thanks. I was wondering if it could come from a locale issue, it seems unlikely. |
|
Can somebody else reproduce? |
|
I've experienced similar problems related to docs and multiple tabs. Notably in development or when dealing with devtools. Though I wasn't able to reproduce them reliably. Considering the service worker also acts up in prod we should probably have an eye on it. |
|
@eps1lon I believe the service worker is only registered in production, could the reload be coming from somewhere else? material-ui/docs/pages/_app.js Line 214 in 25a6bab I believe the reload can only come from two places:
I have managed to reproduce in my env by checking this box (which isn't by default): |
|
@oliviertassinari I think the update on reload is somewhat global option (not depending on site you currently have open). |
|
I could solve most of the issue with: diff --git a/docs/pages/_app.js b/docs/pages/_app.js
index 984d209fca..6b4453b3ae 100644
--- a/docs/pages/_app.js
+++ b/docs/pages/_app.js
@@ -166,6 +166,17 @@ function Analytics() {
return null;
}
+let reloadInterval;
+
+// Avoid infinite loop when "Upload on reload" is set in the Chrome sw dev tools.
+function lazyReload() {
+ clearInterval(reloadInterval);
+ reloadInterval = setInterval(() => {
+ if (document.hasFocus()) {
+ window.location.reload();
+ }
+ }, 100);
+}
+
// Inspired by
// https://developers.google.com/web/tools/workbox/guides/advanced-recipes#offer_a_page_reload_for_users
function forcePageReload(registration) {
@@ -193,7 +204,7 @@ function forcePageReload(registration) {
registration.waiting.postMessage('skipWaiting');
} else if (event.target.state === 'activated') {
// Force the control of the page by the activated service worker.
- window.location.reload();
+ lazyReload();
}
});
}It might be good enough for the problem at hand. At this point, we leverage the sw.js to have the documentation work a bit better offline. It can be handy when we have issues with our hosting provider. We used to store the whole documentation in the cache but it was too eager in bandwidth so we have moved to lazy caching. @huttarichard Do you want to try the changes for |

This might be related #15666. This only happens if you open two tabs. Once you do, material ui site will start loading workbox in infinite loop.
It is consuming insane amount of CPU.
It is really annoying as you are looking at docs a lot.
Unregistering service worker in chrome will solve the issue until you refresh the page.
Your Environment🌎
OSX catalina, chrome