Skip to content

Loading Attribute Not Allowed in amp-img #80

@wesleylhandy

Description

@wesleylhandy

I'm using the gatsby-plugin-html2amp plugin that is dependent upon this package. My site started getting AMP errors in a recent update because Gatsby is adding the 'loading' attribute to images.

This package ensures the required amp-img attributes are present but also adds any other attributes to the transformed image via the spread operator.

utils.js // line 62
const _attrs = { src: url, alt, width: size.width, height: size.height, layout: 'responsive', ...attrs }

Could the following be added on the next line before mapping the keys to the new attributes object:

try {
  delete _attrs['loading'] 
} catch (err) {
  console.error('Loading property is an "own non-configurable property"')
}

The try/catch is probably unnecessary. Delete should only throw an exception in strict mode if the property was set to non-configurable, which shouldn't apply here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions