google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.25k stars 291 forks source link

Fix AMP violations caused by AMP dev mode regression #1142

Closed felixarntz closed 4 years ago

felixarntz commented 4 years ago

Bug Description

505 introduced support for AMP dev mode so that Site Kit scripts and stylesheets are not considered AMP violations by the plugin, since they are only loaded when the user is logged in anyway and should continue to work in these circumstances.

There was a regression recently (reported multiple times) by no longer using wp_add_inline_script() to print the window.googlesitekit object definition and instead relying on WP_Scripts::add_data() (because this is the only way to make it work as a standalone script). Since this script is standalone, we need to add back a mechanism to highlight it as compatible with AMP dev mode. We can use a /*googlesitekit*/ comment for that like before (unfortunately modifying the rendered script tag is not possible).

Another issue is that the AMP plugin filter for that, amp_dev_mode_element_xpaths, fires rather early, but we only hook it in during wp_enqueue_scripts which is too late. It can be generally hooked in during init, there is nothing expensive in there anyway.


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

Acceptance criteria

Implementation Brief

QA Brief

Changelog entry

aaemnnosttv commented 4 years ago

IB + CR ✅

aaemnnosttv commented 4 years ago

✅ QA

Using AMP v1.4.0 and Site Kit 1.3.0

  1. Confirmed validation errors on home page
    image
  2. Hover intent and Site Kit global data
    image
  3. ✅ Rechecking shows no validation errors using Site Kit 3b532c9797d1d5c5975f283bada4e6ba35c888e9
    image

Using AMP v1.4.4 (current latest) and Site Kit 1.3.0

  1. Confirmed validation errors on home page
    image
  2. Site Kit global data only
    image
  3. ✅ Rechecking shows no validation errors using Site Kit 3b532c9797d1d5c5975f283bada4e6ba35c888e9
    image

✅ Menu opens as expected on hover image

Moving to approval