Skip to content
New issue

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

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

Already on GitHub? # to your account

Website keeps reloading after installing PWA #166

Closed
martinovmejl opened this issue Jun 5, 2019 · 4 comments · Fixed by #279
Closed

Website keeps reloading after installing PWA #166

martinovmejl opened this issue Jun 5, 2019 · 4 comments · Fixed by #279
Milestone

Comments

@martinovmejl
Copy link

martinovmejl commented Jun 5, 2019

After installing PWA my website keeps on reloading in some cases.

I'm using OneSignal but is currently deactivated.

I also just installed Autoptimize & autoptimize criticalCSS and converted all images to WebP. But I think this isn't an issue.

@westonruter
Copy link
Collaborator

@martinovmejl Do you notice it reload after logging in or logging out, for example?

The reason for this is the service worker changes based on the authenticated user, and the default behavior is for the page to reload when the service worker updates:

https://github.com/xwp/pwa-wp/blob/fee496164dc1028b8248640bc24b291b9397678d/wp-includes/service-workers.php#L190-L195

You can prevent this behavior by adding this to a custom plugin or theme:

add_filter( 'wp_service_worker_skip_waiting', '__return_false' );

When you do this, an update button will be displayed in the admin bar if present:

https://github.com/xwp/pwa-wp/blob/fee496164dc1028b8248640bc24b291b9397678d/wp-includes/service-workers.php#L154-L171

Honestly, I'm not totally satisfied with how the plugin handles the update scenario. The reload behavior is annoying, but the admin bar is not always displayed and there is no standard place to put the update button otherwise. The best third way would be to incorporate this button in your theme:

https://github.com/xwp/pwa-wp/blob/fee496164dc1028b8248640bc24b291b9397678d/wp-includes/service-workers.php#L175-L184

@martinovmejl
Copy link
Author

Works, thanks!
(I used only this: add_filter( 'wp_service_worker_skip_waiting', '__return_false' );!

@westonruter
Copy link
Collaborator

This has also been reported in #202, where two separate service workers were being installed. Can you check if the situation is similar?

@westonruter
Copy link
Collaborator

I've opened a PR to fix this and have a build for testing: #279 (comment).

@westonruter westonruter added this to the 0.5 milestone May 14, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
2 participants