Shopify / Shopify/theme-tools

Template JSON needs check for missing static block in Liquid file

Open
#941 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
234
Forks
92
Avg merge
1d 3h
Merged PRs (30d)
6

Description

Describe the bug

There's no error in a template JSON when a static block is referenced that the section/block never includes.

This type of check does exist in the SchemaPresetsStaticBlocks and ValidBlockTarget check; however, if a dev is not using presets, the issue won't be known.

Reproduction

Have a block that includes a static block with content_for 'block'; e.g. a _collection-card-image. And use it in a preset.

# blocks/collection-card.liquid

{% content_for 'block', type: '_collection-card-image', id: 'collection-card-image', %}

{% schema %}
{
  "name": "t:names.collection_card",
  "blocks": [...],
  "settings": [...]
  ],
  "presets": [
    {
      "name": "t:names.collection_card",
      "blocks": {
        "collection-card-image": {
          "type": "_collection-card-image",
          "static": true,
        }
    }
  ]
}
{% endschema %}

  • Have this block referenced in a template JSON, like index.json.

  • Delete the content_for 'block' referenc

Expected behaviour

The SchemaPresetsStaticBlocks check successfully runs and warns me.

Static block collection-card-image is missing a corresponding content_for "block" tag.

The ValidBlockTarget is also helpful

Could not find a static block of type "_collection-card-image" with id "collection-card-image" in this file.theme-checkValidBlockTarget

I expect a similar warning in index.json

Actual behaviour

No warning in index.json

Image

Having no presets illustrates that theme dev isn't given any warnings the contents of index.json are a problem.

Image

Debugging information

  • OS Mac
  • Theme Check Version 3.16.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the existing SchemaPresetsStaticBlocks and ValidBlockTarget checks, then trace how template JSON files such as index.json are validated. Add equivalent detection for static blocks referenced from template JSON and verify that the missing content_for "block" case produces the expected warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.