site-kit-wp: IntersectionObserver is not defined dashboard error when accessing Analytics tab
Bug Description
There have been reports of the below dashboard error, both occurring from Site Kit 1.31.0 users. This seems to occur only when clicking on the Analytics tab for one user while it only occurs on the primary dashboard tab for another.
One user reported that disconnecting Analytics results in no dashboard notice.
Awaiting further insights.
Can't find variable: IntersectionObserver
in header
in DashboardPageSpeed
in div
in Layout
in div
in LegacyDashboardSpeed
in FilteredComponent
in WithFilters(LegacyDashboardModule)
in div
in Row
in div
in Grid
in div
in DashboardApp
in GoogleSitekitDashboard
in RestoreSnapshots
in ErrorHandler
in Root
https://wordpress.org/support/topic/cant-find-variable-intersectionobserver/ | Open | Awaiting SH info https://wordpress.org/support/topic/site-kit-encountered-an-error-32 | Resolved (by user, unknown cause) | SH info filled in although not complete https://wordpress.org/support/topic/intersectionobserver-is-not-defined/#post-14401649 | Open | awaiting SH info https://wordpress.org/support/topic/site-kit-encountered-an-error-34/ | Open | Awaiting SH info https://wordpress.org/support/topic/fatal-error-3876/ | Open | SH info https://wordpress.org/support/topic/fatal-error-3876/#post-14475607 | Resolved | SH info - Safari specific - MacOS Big Sur, version 11.4.
Additional Context
- SK 1.31.0
- From the impacted URL we have from one reporter only the Yoast plugin is evident, no obvious caching, optimization or other plugins
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Site Kit should provide a polyfill for the
IntersectionObserver
, which is loaded in case it isn’t available. See these docs for reference.
Implementation Brief
- Add
intersection-observer
to our npm dependencies - Add a new
googlesitekit-polyfills.js
entry- This module will only include feature tests and dynamically require polyfills as needed
- Checks for intersection observer and load the polyfill asynchronously if the feature is not available
- Add this new entry as a dependency of our vendor asset so that it is automatically loaded with our dependencies
- Merge #3965
Test Coverage
- N/A
Visual Regression Changes
- N/A
QA Brief
Testing Site Kit
- Test intersection observer specific functionality – enable usage tracking, enable PSI and scroll down to view the widget – no error should occur
Browsers
- Test Site Kit using a modern browser (check for errors in the console related to polyfills or intersection observer)
- Test Site Kit using an older browser that does not support intersection observer (e.g. Safari 12.0 or below) – there should be no errors related to intersection observer
Changelog entry
- Fix potential error in older browsers that don’t support IntersectionObserver.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (1 by maintainers)
We’ve had another report of this today, troubleshooting ongoing. Added to the list of impacted users in original post.
@wpdarren on the current release, if you activate PSI in Safari 11.1 you should see this error
On the develop branch, no such error occurs
Feel free to try other pages too, but you can test it right on the main dashboard as long as PSI is active.
@aaemnnosttv could you please add QAB?
@eugene-manuilov I agree that a browser upgrade is the best solution for us here but is still a poor experience for the user who will end up with a fatal React error screen when using PageSpeed Insights where things are otherwise working fine. Users encountering this error will have no indication that upgrading the browser will fix the problem so Site Kit will get the blame.
This isn’t affecting a large number of users, but we should aim to provide a better experience where possible. In the future, we may want to use Intersection Observer in other places as well which could make this more severe though so it’s not only about the one module.
I think adding the polyfill is okay as a temporary fix, but we should revisit improving UX for unsupported browsers in another issue.
@aaemnnosttv Sounds good, let’s include the polyfill.
This user reports that they’re using Mac 10.11.6 OS X El Capitan and Safari version 11.1.2. I tried testing in Safari 11 in BrowserStack and am not able to replicate. Site Health is available.