On this page
Why this happens
The theme editor can replace section markup without reloading the document. A listener attached only at DOMContentLoaded will miss replacement elements.
Implementation
Scope initialization to the section element. Use an idempotent initializer and remove listeners or disconnect observers when the section is unloaded. Keep the event registration in a shared theme asset rather than repeating it in every section instance.
Example
document.addEventListener('shopify:section:load', event => {
initializeSection(event.target);
});
document.addEventListener('shopify:section:unload', event => {
destroySection(event.target);
});
Implement these functions for your component and also initialize existing sections on initial page load. A WeakMap can track instances without relying on globally unique selectors.
- Open the editor
- add two instances
- change a setting
- reorder and remove a section
- verify controls still work and one click fires only one handler
- repeat on the published storefront preview.

