ampproject / amp-wp

Enable AMP on your WordPress site, the WordPress way.
https://wordpress.org/plugins/amp/
GNU General Public License v2.0
1.79k stars 384 forks source link

Gutenberg's validation issues with Script Modules #7737

Closed milindmore22 closed 9 months ago

milindmore22 commented 9 months ago

Bug Description

When using a Block-based theme with Gutenberg, the script module map is being included unexpectedly, leading to validation errors when attempting to validate the page as AMP compatible.

Steps to Reproduce:

  1. Use a Block-based theme with Gutenberg.
  2. Activate the AMP plugin and attempt to validate a page as AMP.
  3. Observe the AMP validation results in the Validation tool or in Site scan

Import Map

{
    "node_name": "script",
    "parent_name": "head",
    "code": "DISALLOWED_TAG",
    "type": "js_error",
    "node_attributes": {
        "type": "importmap",
        "id": "wp-importmap"
    },
    "text": "\n{__DOUBLE_QUOTED_STRING__:{__DOUBLE_QUOTED_STRING__:__DOUBLE_QUOTED_STRING__}}\n",
    "node_type": "ELEMENT",
    "sources": [
        {
            "type": "plugin",
            "name": "gutenberg",
            "file": "lib/compat/wordpress-6.5/class-wp-script-modules.php",
            "line": 216,
            "function": "WP_Script_Modules::print_import_map",
            "hook": "wp_head",
            "priority": 10
        }
    ],
    "removed": true,
    "reviewed": false
}

Navigation Module

{
    "node_name": "script",
    "parent_name": "head",
    "code": "DISALLOWED_TAG",
    "type": "js_error",
    "node_attributes": {
        "type": "module",
        "src": "https://amp-support.rt.gw/wp-content/plugins/gutenberg/build/interactivity/navigation.min.js?ver=__normalized__",
        "id": "@wordpress/block-library/navigation-js-module"
    },
    "node_type": "ELEMENT",
    "sources": [
        {
            "type": "plugin",
            "name": "gutenberg",
            "file": "lib/compat/wordpress-6.5/class-wp-script-modules.php",
            "line": 178,
            "function": "WP_Script_Modules::print_enqueued_script_modules",
            "hook": "wp_head",
            "priority": 10
        }
    ],
    "removed": true,
    "reviewed": false
}

Invalid Link Attribute

{
    "code": "INVALID_DISALLOWED_VALUE_REGEX",
    "element_attributes": {
        "rel": "modulepreload",
        "href": "https://amp-support.rt.gw/wp-content/plugins/gutenberg/build/interactivity/index.min.js?ver=17.6.2",
        "id": "@wordpress/interactivity-js-modulepreload"
    },
    "node_name": "rel",
    "parent_name": "link",
    "type": "html_attribute_error",
    "node_type": "ATTRIBUTE",
    "sources": [
        {
            "type": "plugin",
            "name": "gutenberg",
            "file": "lib/compat/wordpress-6.5/class-wp-script-modules.php",
            "line": 198,
            "function": "WP_Script_Modules::print_script_module_preloads",
            "hook": "wp_head",
            "priority": 10
        }
    ],
    "removed": true,
    "reviewed": false
}

No rel Attribute for Link

{
    "code": "ATTR_REQUIRED_BUT_MISSING",
    "attributes": [
        "rel"
    ],
    "spec_name": "link rel=",
    "node_name": "link",
    "parent_name": "head",
    "type": "html_element_error",
    "node_attributes": {
        "href": "https://amp-support.rt.gw/wp-content/plugins/gutenberg/build/interactivity/index.min.js?ver=__normalized__",
        "id": "@wordpress/interactivity-js-modulepreload"
    },
    "node_type": "ELEMENT",
    "sources": [
        {
            "type": "plugin",
            "name": "gutenberg",
            "file": "lib/compat/wordpress-6.5/class-wp-script-modules.php",
            "line": 198,
            "function": "WP_Script_Modules::print_script_module_preloads",
            "hook": "wp_head",
            "priority": 10
        }
    ],
    "removed": true,
    "reviewed": false
}

Expected Behaviour

The script module map should not be included in pages intended for AMP validation.

Screenshots

No response

PHP Version

No response

Plugin Version

2.5.2

AMP plugin template mode

Transitional

WordPress Version

6.4.3

Site Health

### wp-core ###

version: 6.4.3
site_language: en_US
user_language: en_US
timezone: -07:00
permalink: /%category%/%postname%-%post_id%/
https_status: true
multisite: false
user_registration: 0
blog_public: 1
default_comment_status: open
environment_type: production
user_count: 3
dotorg_communication: true

### wp-paths-sizes ###

wordpress_path: /var/www/htdocs/current
wordpress_size: 241.96 MB (253709601 bytes)
uploads_path: /var/www/htdocs/current/wp-content/uploads
uploads_size: 250.35 MB (262514776 bytes)
themes_path: /var/www/htdocs/current/wp-content/themes
themes_size: 101.31 MB (106227142 bytes)
plugins_path: /var/www/htdocs/current/wp-content/plugins
plugins_size: 333.59 MB (349791258 bytes)
database_size: 366.02 MB (383795200 bytes)
total_size: 1.26 GB (1356037977 bytes)

### wp-active-theme ###

name: Twenty Twenty-Two (twentytwentytwo)
version: 1.6
author: the WordPress team
author_website: https://wordpress.org/
parent_theme: none
theme_features: core-block-patterns, post-thumbnails, responsive-embeds, editor-styles, html5, automatic-feed-links, widgets-block-editor, block-templates, wp-block-styles, editor-style
theme_path: /var/www/htdocs/current/wp-content/themes/twentytwentytwo
auto_update: Disabled

### wp-themes-inactive (18) ###

Newspaper: version: 12.4, author: tagDiv, Auto-updates disabled
Fashion Lite: version: 1.0.1, author: Blossom Themes, Auto-updates disabled
GeneratePress: version: 3.3.1, author: Tom Usborne, Auto-updates disabled
Magnitude: version: 2.1.1, author: AF themes, Auto-updates disabled
Neve: version: 3.8.1, author: ThemeIsle, Auto-updates disabled
Storefront: version: 4.5.4, author: Automattic, Auto-updates disabled
TT1 Blocks: version: 0.4.8, author: the WordPress team, Auto-updates disabled
Twenty Eleven: version: 4.5, author: the WordPress team, Auto-updates disabled
Twenty Fourteen: version: 3.8, author: the WordPress team, Auto-updates disabled
Twenty Nineteen: version: 2.7, author: the WordPress team, Auto-updates disabled
Twenty Seventeen: version: 3.5, author: the WordPress team, Auto-updates disabled
Twenty Sixteen: version: 3.1, author: the WordPress team, Auto-updates disabled
Twenty Twelve: version: 4.1, author: the WordPress team, Auto-updates disabled
Twenty Twenty: version: 2.5, author: the WordPress team, Auto-updates disabled
Twenty Twenty-Four: version: 1.0, author: the WordPress team, Auto-updates disabled
Twenty Twenty-One: version: 2.1, author: the WordPress team, Auto-updates disabled
Twenty Twenty-Three: version: 1.3, author: the WordPress team, Auto-updates disabled
Vilva: version: 1.2.3, author: Blossom Themes (latest version: 1.2.4), Auto-updates disabled

### wp-plugins-active (3) ###

AMP: version: 2.5.2, author: AMP Project Contributors, Auto-updates enabled
Gutenberg: version: 17.6.2, author: Gutenberg Team, Auto-updates enabled
Login with Google: version: 1.3.2, author: rtCamp, Auto-updates enabled

### wp-plugins-inactive (43) ###

Ad Inserter: version: 2.7.33, author: Igor Funa, Auto-updates enabled
Advanced Google reCAPTCHA: version: 1.19, author: WebFactory Ltd, Auto-updates enabled
AMP compatibility for PDF Embedder.: version: 0.1, author: milindmore22, Google, Auto-updates disabled
AMP Disable ES Modules by Default: version: 0.1, author: Weston Ruter, Auto-updates disabled
AMP Enhancer: version: 1.0.48, author: ampenhancer, Auto-updates enabled
AMP for GeneratePress: version: 0.2, author: Tom Usborne, Auto-updates disabled
AMP Generic Compat: version: 0.2, author: milindmore22, Auto-updates disabled
AMP Plugin Name Compat: version: 0.1, author: Your Name, Google, Auto-updates disabled
AMP Popup: version: 0.1, author: Your Name Here, Auto-updates disabled
AMP Tawk.to Chat: version: 0.1, author: milindmore22, rtCamp, Google, Auto-updates disabled
Anti-Spam by CleanTalk: version: 6.26, author: СleanTalk - Anti-Spam Protection <welcome@cleantalk.org>, Auto-updates enabled
Classic Editor: version: 1.6.3, author: WordPress Contributors, Auto-updates enabled
Classic Widgets: version: 0.3, author: WordPress Contributors, Auto-updates enabled
Contact Form 7: version: 5.8.7, author: Takayuki Miyoshi, Auto-updates enabled
Crowdsignal Forms: version: 1.7.0, author: Automattic, Auto-updates enabled
Crowdsignal Polls & Ratings: version: 3.1.1, author: Automattic, Inc., Auto-updates enabled
Disable AMP to AMP Linking.: version: 1.0, author: AMP Support, Auto-updates disabled
Elementor: version: 3.19.1, author: Elementor.com, Auto-updates enabled
Gravity Forms: version: 2.7.17.1, author: Gravity Forms, Auto-updates enabled
iZooto Web Push: version: 3.7.14, author: iZooto, Auto-updates enabled
Jetpack: version: 13.0, author: Automattic, Auto-updates enabled
Jetpack Boost: version: 3.0.2, author: Automattic - Jetpack Site Speed team, Auto-updates enabled
Kadence AI Starter Templates: version: 2.0.7, author: Kadence WP, Auto-updates enabled
LiteSpeed Cache: version: 6.1, author: LiteSpeed Technologies, Auto-updates enabled
Liveblog: version: 1.9.6, author: WordPress.com VIP, Big Bite Creative and contributors, Auto-updates enabled
Omnisend for Gravity Forms Add-On: version: 1.1.0, author: Omnisend, Auto-updates enabled
Omnisend for Woocommerce: version: 1.14.0, author: Omnisend (latest version: 1.14.1), Auto-updates enabled
OneSignal Push Notifications: version: 2.4.2, author: OneSignal, Auto-updates enabled
Security by CleanTalk: version: 2.127, author: CleanTalk Security, Auto-updates enabled
Site Kit by Google: version: 1.119.0, author: Google, Auto-updates enabled
tagDiv Cloud Library: version: 2.7 | built on 18.05.2023 11:25, author: tagDiv, Auto-updates disabled
tagDiv Composer: version: 4.1 | built on 18.05.2023 11:25, author: tagDiv, Auto-updates disabled
tagDiv Mobile Theme: version: 2.3 | built on 25.07.2023 12:54, author: tagDiv, Auto-updates disabled
tagDiv Social Counter: version: 5.2 | built on 15.02.2023 13:25, author: tagDiv, Auto-updates disabled
User Switching: version: 1.7.2, author: John Blackbourn & contributors, Auto-updates disabled
Web Stories: version: 1.35.0, author: Google, Auto-updates disabled
WooCommerce: version: 8.5.2, author: Automattic, Auto-updates disabled
WordPress Importer: version: 0.8.2, author: wordpressdotorg, Auto-updates disabled
WP Downgrade | Specific Core Version: version: 1.2.6, author: Reisetiger, Auto-updates disabled
WPForms Lite: version: 1.8.6.4, author: WPForms, Auto-updates disabled
WP Rollback: version: 2.0.6, author: WP Rollback, Auto-updates disabled
WP Super Cache: version: 1.11.0, author: Automattic, Auto-updates disabled
Yoast SEO: version: 22.0, author: Team Yoast, Auto-updates disabled

### wp-media ###

image_editor: WP_Image_Editor_Imagick
imagick_module_version: 1691
imagemagick_version: ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org
imagick_version: 3.7.0
file_uploads: 1
post_max_size: 100M
upload_max_filesize: 100M
max_effective_size: 100 MB
max_file_uploads: 20
imagick_limits: 
    imagick::RESOURCETYPE_AREA: 122 MB
    imagick::RESOURCETYPE_DISK: 1073741824
    imagick::RESOURCETYPE_FILE: 786432
    imagick::RESOURCETYPE_MAP: 512 MB
    imagick::RESOURCETYPE_MEMORY: 256 MB
    imagick::RESOURCETYPE_THREAD: 1
    imagick::RESOURCETYPE_TIME: 9.2233720368548E+18
imagemagick_file_formats: 3FR, 3G2, 3GP, AAI, AI, APNG, ART, ARW, AVI, AVIF, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FILE, FITS, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, H, HALD, HDR, HEIC, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAGICK, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIDEO, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV
gd_version: bundled (2.1.0 compatible)
gd_formats: GIF, JPEG, PNG, WebP, BMP
ghostscript_version: not available

### wp-server ###

server_architecture: Linux 5.4.0-96-generic x86_64
httpd_software: nginx/1.21.4
php_version: 8.0.27 64bit
php_sapi: fpm-fcgi
max_input_variables: 1000
time_limit: 300
memory_limit: 128M
admin_memory_limit: 256M
max_input_time: 60
upload_max_filesize: 100M
php_post_max_size: 100M
curl_version: 7.74.0 OpenSSL/1.1.1n
suhosin: false
imagick_availability: true
pretty_permalinks: true
htaccess_extra_rules: true
current: 2024-02-06T13:32:02+00:00
utc-time: Tuesday, 06-Feb-24 13:32:02 UTC
server-time: 2024-02-06T06:32:02-07:00

### wp-database ###

extension: mysqli
server_version: 10.11.2-MariaDB-1:10.11.2+maria~ubu2204
client_version: mysqlnd 8.0.27
max_allowed_packet: 1073741824
max_connections: 151

### wp-constants ###

WP_HOME: undefined
WP_SITEURL: undefined
WP_CONTENT_DIR: /var/www/htdocs/current/wp-content
WP_PLUGIN_DIR: /var/www/htdocs/current/wp-content/plugins
WP_MEMORY_LIMIT: 40M
WP_MAX_MEMORY_LIMIT: 256M
WP_DEBUG: true
WP_DEBUG_DISPLAY: false
WP_DEBUG_LOG: true
SCRIPT_DEBUG: true
WP_CACHE: false
CONCATENATE_SCRIPTS: undefined
COMPRESS_SCRIPTS: undefined
COMPRESS_CSS: undefined
WP_ENVIRONMENT_TYPE: Undefined
WP_DEVELOPMENT_MODE: undefined
DB_CHARSET: utf8mb4
DB_COLLATE: undefined

### wp-filesystem ###

wordpress: writable
wp-content: writable
uploads: writable
plugins: writable
themes: writable
mu-plugins: writable

### amp_wp ###

amp_slug_query_var: amp
amp_slug_defined_late: false
amp_mode_enabled: transitional
amp_reader_theme: legacy
amp_templates_enabled: post, page, is_singular, is_home, is_archive, is_author, is_date, is_search, is_404, is_category, is_tag
amp_serve_all_templates: true
amp_css_transient_caching_disabled: false
amp_css_transient_caching_threshold: 5000 transients per day
amp_css_transient_caching_sampling_range: 14 days
amp_css_transient_caching_transient_count: 4883
amp_css_transient_caching_time_series: 
    20240121: 752
    20240122: 805
    20240123: 822
    20240124: 871
    20240125: 878
    20240129: 889
    20240130: 923
    20240131: 995
    20240201: 1356
    20240202: 1906
    20240203: 2845
    20240204: 4731
    20240205: 4796
    20240206: 4871
amp_libxml_version: 2.9.10

Gutenberg Version

17.6.2

OS(s) Affected

No response

Browser(s) Affected

No response

Device(s) Affected

No response

Acceptance Criteria

No response

Implementation Brief

No response

QA Testing Instructions

No response

Demo

No response

Changelog Entry

No response

westonruter commented 9 months ago

@milindmore22 I believe I fixed this as part of #7736 since tests were breaking. Could you verify?

milindmore22 commented 9 months ago

I tested develop build, verified ✅ that it's fixed with https://github.com/ampproject/amp-wp/pull/7736

pavanpatil1 commented 8 months ago

QA Passed ✅

Verified the fix and it is working fine.

Actual result Expected result
gbdevmodeactual disallowexpt