Shopify / theme-tools

Everything developer experience for Shopify themes
https://shopify.dev/docs/themes
MIT License
80 stars 24 forks source link

Check preset blocks_order #604

Open miazbikowski opened 3 days ago

miazbikowski commented 3 days ago

What are you adding in this PR?

Solves https://github.com/Shopify/theme-tools/issues/590

When presets have blocks as a hash, they must also be included in the block_order array... Unless they are a static block (a block with static: true), then they have to NOT be included in the block_order.

Note: this check doesn't validate the existence of block_order, it assumes it's there to run this check.

To test:

{% schema %}
{
  "class": "container-background-image",
  "name": "A test section",
  "blocks": [{ "type": "@theme" }],
  "presets": [
    {
      "name": "Preset One",
      "blocks": {
        "block_1": {
          "type": "text",
          "static": true
        },
        "block_2": {
          "type": "text"
        }
      },
      "block_order": ["block_1"]
    }
  ]
}
{% endschema %}

What's next? Any followup issues?

Does JSON Schema enforce that block_order is present when dealing with preset blocks as a hash? If not, this should be added.

What did you learn?

To use CP's new building blocks :)

Before you deploy

miazbikowski commented 1 day ago

@navdeep5 just warned me that copy+pasting the same schema code from my tests didn't work in the f5 vs code instance (which is weird, since, tests pass with the same schema) so I'm definitely going to look into that shortly

navdeep5 commented 1 day ago

@navdeep5 just warned me that copy+pasting the same schema code from my tests didn't work in the f5 vs code instance (which is weird, since, tests pass with the same schema) so I'm definitely going to look into that shortly

Yeah, it early returns since validSchema is false and contains an error -- so the check does not run. It thinks block_order is not a valid property within nested blocks. image