Skip to content

[AMP Story] Uncaught TypeError if product has no productImages #38174

@swissspidy

Description

@swissspidy

Description

While a product in the shopping config must have a productImages key according to the JSON schema (see #36460), it is technically not required to have any images. So an empty productImages array does not fail validation.

However, it causes an uncaught TypeError in this code here that expects at least 1 image to exist:

backgroundImage: `url("${relativeToSourceUrl(
data['productImages'][0].url,
this.element
)}")`,

Reproduction Steps

  1. Add amp-story-shopping configuration with at least two products, where at least one product does not have any images, i.e. productImages = []
  2. Click on the shopping attachment
  3. See error in console and that the attachment does not open

In my testing it somehow worked on the first page, but the error was always thrown

Relevant Logs

Uncaught TypeError: Cannot read properties of undefined (reading 'url')
    at amp-story-shopping-attachment.js:517:46
    at Array.map (<anonymous>)
    at W.I8 (amp-story-shopping-attachment.js:507:32)
    at W.pW (amp-story-shopping-attachment.js:277:16)
    at W.P8 (amp-story-shopping-attachment.js:220:27)
    at W.w8 (amp-story-shopping-attachment.js:155:12)
    at amp-story-shopping-attachment.js:126:24
    at _i.fire (observable.js:63:7)
    at amp-story-store-service.js:571:30
    at Array.forEach (<anonymous>)

Browser(s) Affected

No response

OS(s) Affected

No response

Device(s) Affected

No response

AMP Version Affected

2204221712000

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions