Skip to content

Fix AMP violations caused by AMP dev mode regression #1142

@felixarntz

Description

@felixarntz

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

  • There should not be any AMP violations flagged by the AMP plugin when the Site Kit admin bar menu is loaded.

Implementation Brief

QA Brief

  • Activate AMP plugin and set to AMP standard mode.
  • Go to a page in the frontend for which the Site Kit admin bar menu shows.
  • Ensure the plugin does not report any validation errors, and that the menu opens as expected when hovering over it.

Changelog entry

  • Fix AMP violations when user is logged in and Site Kit admin bar menu is active.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0High priorityType: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions