Section scripts aren't run on "add section"

When adding a section to the page in the theme editor, scripts are not run until the page is saved. For example, the follow code will not log anything until the page has been saved. It then works great and the listener handles updates etc. But on section add - nothing.


{%- schema -%}
  {
    "name": { "en": "Test" },
    "presets": [{
      "name": { "en": "Test" },
      "category": { "en": "Video" },
      "blocks": []
     }]
  }
{%- endschema -%}

What can I do to get code to run on “add” - otherwise I can’t let users preview what a section will look like without them pressing save first, which seems wrong

Hi @Branks ,

You can add this code directly in JS file, no need per section. Refer https://shopify.dev/themes/architecture/sections/integrate-sections-with-the-theme-editor#javascript-events

You can also refer to the following article for more information: https://community.shopify.com/post/1543971

Hope it helps!

How would I get the JS file onto the editor page if not via a section? I do not control the theme - I just have a section within the theme

Hi @Branks ,

You want to add conditions for only one section?

Have you tried following instructions to add check conditions? https://community.shopify.com/post/1543971

Please explain more about it, I will help you check it