• Resolved xxxLesy

    (@xxxlesy)


    On Amp 2.2.3 I get the following error on amp articles. Downgrading to 2.2.1 fixes it (haven’t tested 2.2.2).

    Php 8.0.7
    Theme: Newspaper 11.4.2

    Couldn't fetch AmpProject\Dom\Element (0) [Error]
    /var/www/vhosts/mojprihranek.si/httpdocs/wp-content/plugins/amp/vendor/ampproject/amp-toolbox/src/Optimizer/Transformer/OptimizeHeroImages.php:474
    
    #0 /var/www/vhosts/mojprihranek.si/httpdocs/wp-content/plugins/amp/vendor/ampproject/amp-toolbox/src/Optimizer/Transformer/OptimizeHeroImages.php(474): DOMElement->getAttribute()
    #1 /var/www/vhosts/mojprihranek.si/httpdocs/wp-content/plugins/amp/vendor/ampproject/amp-toolbox/src/Optimizer/Transformer/OptimizeHeroImages.php(183): AmpProject\Optimizer\Transformer\OptimizeHeroImages->removeLazyLoading()
    #2 /var/www/vhosts/mojprihranek.si/httpdocs/wp-content/plugins/amp/vendor/ampproject/amp-toolbox/src/Optimizer/TransformationEngine.php(78): AmpProject\Optimizer\Transformer\OptimizeHeroImages->transform()
    #3 /var/www/vhosts/mojprihranek.si/httpdocs/wp-content/plugins/amp/src/Optimizer/OptimizerService.php(46): AmpProject\Optimizer\TransformationEngine->optimizeDom()
    #4 /var/www/vhosts/mojprihranek.si/httpdocs/wp-content/plugins/amp/includes/class-amp-theme-support.php(2131): AmpProject\AmpWP\Optimizer\OptimizerService->optimizeDom()
    #5 /var/www/vhosts/mojprihranek.si/httpdocs/wp-content/plugins/amp/includes/class-amp-theme-support.php(1750): AMP_Theme_Support::prepare_response()
    #6 [internal function]: AMP_Theme_Support::finish_output_buffering()
    #7 /var/www/vhosts/mojprihranek.si/httpdocs/wp-includes/functions.php(5219): ob_end_flush()
    #8 /var/www/vhosts/mojprihranek.si/httpdocs/wp-includes/class-wp-hook.php(307): wp_ob_end_flush_all()
    #9 /var/www/vhosts/mojprihranek.si/httpdocs/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
    #10 /var/www/vhosts/mojprihranek.si/httpdocs/wp-includes/plugin.php(474): WP_Hook->do_action()
    #11 /var/www/vhosts/mojprihranek.si/httpdocs/wp-includes/load.php(1100): do_action()
    #12 [internal function]: shutdown_action_hook()
    #13 {main}
Viewing 15 replies - 1 through 15 (of 20 total)
  • Hi @xxxlesy,

    Thanks for contacting us, version 2.2.2 is the last stable release, the 2.3 is still under development. Please, check version 2.2.2

    Thread Starter xxxLesy

    (@xxxlesy)

    Checked it. Same errors. 2.2.1 is fine.

    Hi @xxxlesy,

    Could you share the URL with the error?

    Plugin Author Weston Ruter

    (@westonruter)

    Thanks for contacting us, version 2.2.2 is the last stable release, the 2.3 is still under development. Please, check version 2.2.2

    @fellyph Version 2.2.3 is the latest stable, actually. It was a hotfix for a PHP 5.6 compatibility issue with 2.2.2. So 2.3 vs 2.2.3, which do look similar.

    Plugin Author Weston Ruter

    (@westonruter)

    Maybe try re-installing 2.2.3.

    Thanks @westonruter,

    I was confused by 2.3 and 2.2.3

    Plugin Author Weston Ruter

    (@westonruter)

    This may be resolved by clearing the PHP OPcache as well.

    Thread Starter xxxLesy

    (@xxxlesy)

    Re-updated to 2.2.3. Same error on all /?amp posts.

    Deleted FVM cache, deleted WP super cache, fulshed redis object cache, disabled php opcache (don’t know how to flush it).

    I can’t provide a link, as it is a live news site, so I can’t afford to have all articles not working on mobile. I’ll provide a screenshot: https://pasteboard.co/hYxzqHf6Yyg7.png Enabling debug prints the error from first post.

    Plugin Author Weston Ruter

    (@westonruter)

    Sorry, I’m not sure. I just re-tested on PHP 8.0 and I get no such error.

    Plugin Support Milind More

    (@milindmore22)

    @xxxlesy

    Please send your site health info using this form privately, also please send us the URL which is causing the error in Other Support information field

    Thread Starter xxxLesy

    (@xxxlesy)

    Sent. I also setup a staging copy of the site and send an admin login with the form.

    This is an example of the issue on the staging site: https://test.mojprihranek.si/bivanje/komarji-so-ze-tu-izdelava-komarnikov-je-preprosta/?amp
    It happens with all amp posts.

    I tried downgrading php to 7.4.28 and that also fixed the issue. So it’s definitely something with php 8. I do have a ton of other plugins so it might be some cross compatiblity.

    Plugin Author Weston Ruter

    (@westonruter)

    I’m narrowing down the issue.

    First of all, there is a bug in the amp-toolbox-php library in how it is processing elements that have the data-hero attribute. Namely, it is including the amp-img[data-hero] > noscript > img[data-hero] in the list. So given one img that originally had data-hero, this is being converted into an AMP page that includes amp-img[data-hero] > noscript > img[data-hero]. This is resulting in amp-img[data-hero] and amp-img[data-hero] > noscript > img[data-hero] both being found as hero images. However, when the first one is processed it removes the noscript child which results in the second hero image no longer being in the DOM. It appears then in PHP 8 that this now causes an exception where previously it would not.

    What I’m still investigating is what specifically changed between 2.2.1 and 2.2.3 that caused this error to start happening. I haven’t identified the specific change, but once I do that I’ll open a PR to fix amp-toolbox-php and include those fixes in a 2.2.4 hotfix.

    Plugin Author Weston Ruter

    (@westonruter)

    OK, I found why this error started happening in 2.2.3: with the validator spec update, the data-hero attribute is now listed among the attributes that are allowed on img. Because of that, the initialize_noscript_allowed_attributes method in AMP_Img_Sanitizer will now preserve it when moving the img to the amp-img > noscript > img fallback.

    The quickest way around this issue is to disable the noscript fallbacks. You can do so via the following plugin code:

    add_filter(
    	'amp_content_sanitizers',
    	static function ( $sanitizers ) {
    		$sanitizers[ AMP_Img_Sanitizer::class ]['add_noscript_fallback'] = false;
    		return $sanitizers;
    	}
    );

    Alternatively, you could disable server-side rendering with this code:

    add_filter( 'amp_enable_ssr', '__return_false' );

    The former method is preferable as only a very small percentage of visitors would have JavaScript turned off.

    We’ll get this underlying issue fixed in 2.2.4.

    Plugin Author Weston Ruter

    (@westonruter)

    Actually, the former method must be used because if an amp-img has data-hero then it cannot also have a noscript > img according to the AMP validator spec.

    Plugin Author Weston Ruter

    (@westonruter)

    Alternatively, you can use data-hero-candidate instead of data-hero on such images. This would allow for the AMP plugin to also include its own hero candidates and then the amp-toolbox-php package would add data-hero to the appropriate images.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Couldn’t fetch AmpProject\Dom\Element (0) [Error]’ is closed to new replies.