PSI API request blocks navigation
Bug Description
Since the PageSpeed Insights widget in the Site Kit dashboard can take a while for loading its data from the API (sometimes ~10 seconds), this can have a quite annoying UX impact at times.
- Ensure the PSI module is activated.
- Go to the Site Kit dashboard for the first time in an hour (i.e. all widgets will refresh their data from the APIs).
- Immediately (e.g. after 1 or 2 seconds) navigate away to another page (e.g. anywhere else in WP Admin).
- Note a significant delay in the navigation - when scrolling down to the PSI widget, you'll see that the widget is still loading, and the navigation finally happens shortly after the PSI data is fully loaded.
I'm not sure exactly why it is happening, but I have been encountering it numerous times, and it is super annoying. I would expect the browser to abort the request in favor of the navigation away, but somehow that doesn't seem to happen - maybe my understanding of how the browser treats those network requests is slightly off.
I'm also not sure whether this really happen every time, but I have been noticing it rather consistently in Chrome for a while. I don't think it's related to any recent change we've introduced, but rather something that we just never flagged as a problem before.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Navigations away from Site Kit screens in the admin (e.g. the Site Kit dashboard) should not be blocked by slow API requests.
- It would be best if we can fix this holistically, but if not, at a minimum the slow PageSpeed Insights API requests should no longer block navigations.
Implementation Brief
Test Coverage
Visual Regression Changes
QA Brief
Changelog entry
@fhollis If we have capacity beyond the Idea Hub issues, this one would be great to look into in the next sprint.
Go to the Site Kit dashboard for the first time in an hour Is there any way we can fake this? :thinking:
Otherwise, it's going to be a very long ticket to develop and test :smile:
It would be good if we could add a query string ?force-widgets-refresh-data to reset the timer (similar to with the Idea Hub features we can visit an Url to reset them)
It does sound very odd though!
maybe my understanding of how the browser treats those network requests is slightly off - I'm in agreement here. I thought that browsers just did the next request
@danielgent It can be easily enforced, you need to clear your application data for the site you're testing, specifically the session storage.
@felixarntz I can't seem to reproduce this issue. I've cleared the session storage and am still able to navigate away while the widget is loading. I wonder whether this might be browser-specific or something? 🤔
I did notice this error in the console when the page unloaded though:
Google Site Kit API Error method:GET datapoint:pagespeed type:modules identifier:pagespeed-insights error:"You are probably offline."
@johnPhillips Hmm you're right - indeed this might be something specific to my machine or my browser. On my other machine and on my phone things work correctly. Closing this for now.