theme-check icon indicating copy to clipboard operation
theme-check copied to clipboard

Identify missing calls to block.shopify_attributes

Open samdoiron opened this issue 3 years ago • 2 comments

All rendered blocks should to use block.shopify_attributes like this

{% for block in sections.blocks %}
  <div {{ block.shopify_attributes }}></div>
{% endfor %}

This might be tricky to identify. Some cases would be caught by checking the contents of any for loops over section.blocks, but there are subtleties like the {% render .. for %} syntax.

samdoiron avatar Dec 16 '20 19:12 samdoiron

This came up as an actually issue in one of our internal themes recently. We use these attributes to live-patch the DOM when settings like a linked image are updated.

samdoiron avatar Dec 16 '20 19:12 samdoiron

👍 Appears to be documented here: https://shopify.dev/docs/themes/liquid/reference/objects/block#block-shopify_attributes.

Maybe we could check that as soon as sections.blocks is referenced in a template block.shopify_attributes is always present.

macournoyer avatar Dec 16 '20 21:12 macournoyer