site-kit-wp: JavaScript error: An error occurred while running 'mapSelect': Cannot read property 'isModuleActive' of null

Bug Description

Reported in a support topic, a user encountered this error after install and navigating to the dashboard (screenshot):

An error occurred while running 'mapSelect': Cannot read property 'isModuleActive' of null
The error may be correlated with this previous error:
TypeError: Cannot read property 'isModuleActive' of null
    at Object.current (https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-dashboard.41176eb144adcaf84380.js:64:39347)
    at e (https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js:1:230780)
    at https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js:1:230889
    at Ui (https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js:1:538697)
    at ba (https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js:1:561620)
    at t.unstable_runWithPriority (https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js:1:581243)
    at Nr (https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js:1:506349)
    at Yj (https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js:1:558049)
    at Lj (https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js:1:548409)
    at https://www.socomtactical.net/wp-content/plugins/google-site-kit/dist/assets/js/googlesitekit-vendor.7f2f98d6cb7f1a6a3ca1.js:1:506640

Original stack trace:

    in PostSearcher
    in FilteredComponent
    in WithFilters(LegacyDashboardPopularityInner)
    in LegacyDashboardPopularity
    in FilteredComponent
    in WithFilters(DashboardModule)
    in DashboardModules
    in DashboardMain
    in div
    in div
    in div
    in div
    in DashboardApp
    in GoogleSitekitDashboard
    in RestoreSnapshots
    in ErrorHandler
    in Root

Additional Context

  • PHP Version:
  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Plugin Version [e.g. 22]
  • Device: [e.g. iPhone6]

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

Test Coverage

Visual Regression Changes

QA Brief

Changelog entry

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 30

Most upvoted comments

@bethanylang We discussed this in a previous internal sync, at what point it was assigned. As these minification conflicts are not specific to WP Rocket we’ve also done some internal testing for other popular plugins. Happy to triage for further team discussion.

The most recent report of this issue is now resolved, with the error appearing in this users case via the admin toolbar, as a result of WP Rocket optimisations applied.

The user defined the below exclusion to ensure the Site Kit admin toolbar is not impacted by WP Rocket optimizations (JS asset combination or minification): /wp-content/plugins/google-site-kit/dist/assets/js/(.*).js

@bethanylang What are your thoughts on testing various popular optimisation plugins and testing admin bar functionality compatibility with the various optimizations enabled. Maybe we can come up with troubleshooting guides or exclusions.

Opened #4436 to support this, after which this issue may no longer be relevant but I suppose we’ll have to wait and see 😄

cc: @felixarntz

Reopening this as it looks like it may be possible to programmatically deactivate the minify option for WP Rocket (for logged in users), specifically using pre_get_rocket_option_minify_js.

For additional context in order to recreate this JS error follow the steps below:

  1. Install and setup SK with WP Rocket
  2. Activate the Minify JS option within WP Rocket (File Optimization > Minify JavaScript files)
  3. enable caching for logged in users.
  4. Visit your site as a logged in user and view statistics from the admin toolbar

Likewise with a combination of options enabled the Site Kit tab doesn’t load. I have been able to recreate the original issue with only the minify JS option enabled in WP Rocket, all other configurations default.

2021-05-20-12-20-13

Adding the below exclusion allows the Site Kit tab to operate successfully: /wp-content/plugins/google-site-kit/dist/assets/js/(.*).js

There is a warning when these features are operated within WP Rocket.

@abdullah1908 Reassigning to you for testing WP Rocket as noted in Slack.

@tofumatt I’ve been unable to reproduce this after performing checks using various ad blockers, tests below. For those who’ve encountered this via the admin toolbar it may be related to JS minification or asset combining.

Ad Blocker Tests Complete

  • Firefox with Ultimate Ad Blocker - default config - Unreproducible, “You are offline” errors appear on 2/3 sites, 1 that “needs attention” before ads are served and another that has AdSense traffic - Screenshot & console errors. The other sites have a standard Ad Blocker detected message
  • Opera Browser (with in built Ad Blocker) - Unreproducible, “You are offline” appears as above for 1 site.
  • Chrome with AdBlock - Unreproducible, “You are offline” appears as above for 2 sites, with 1 site encountering a “Gathering data” notice despite this site already having an approved AdSense account and site (with ads) - console errors.

All checks above done on 3 different sites, all with SC, Analytics & AdSense connected with traffic. 2 of those have AdSense data, with 1 site not approved. SK main dashboard, Analytics, AdSense & Admin toolbar checked on each.

Impacted users: 2/9 unresolved. Various fixed for those who confirmed a resolution (Ad Blocker & Optimisation plugin - where the issue occurred on the front end via the admin toolbar)

I am still trying to 100% reliably reproduce this, but after looking through the issue and trying some custom adblocker scripts I think the issue is our googlesitekit-modules-adsense.js file.

I think our public JS file googlesitekit-modules-adsense is likely being blocked by ad blockers, as they frequently will have rules that block all scripts containing ad or adsense. If that file doesn’t load, it can cause the errors users are reporting.

But ad blockers are always tough to diagnose because users can have custom filter sets, rules, etc. that cause it. So I’m trying to see if there are common blockers/lists/etc. that cause it. The easy solution might be to rename that file. 🙂