From 259252b581757df2d4c0ae977ffc81c52452ff8c Mon Sep 17 00:00:00 2001 From: Tyler Alsbury <60230011+tyleralsbury@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:54:19 -0400 Subject: [PATCH] Fixed modals sticking around for Featured Product whens section is removed in the editor (#3609) --- assets/global.js | 1 + assets/theme-editor.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/assets/global.js b/assets/global.js index ce13bf6514a..657227444f3 100644 --- a/assets/global.js +++ b/assets/global.js @@ -619,6 +619,7 @@ class ModalDialog extends HTMLElement { connectedCallback() { if (this.moved) return; this.moved = true; + this.dataset.section = this.closest('.shopify-section').id.replace('shopify-section-', ''); document.body.appendChild(this); } diff --git a/assets/theme-editor.js b/assets/theme-editor.js index 557c908a3b3..62f96c073e8 100644 --- a/assets/theme-editor.js +++ b/assets/theme-editor.js @@ -36,6 +36,12 @@ document.addEventListener('shopify:section:load', () => { } }); +document.addEventListener('shopify:section:unload', (event) => { + document.querySelectorAll(`[data-section="${event.detail.sectionId}"]`).forEach((element) => { + element.remove(); + }); +}); + document.addEventListener('shopify:section:reorder', () => hideProductModal()); document.addEventListener('shopify:section:select', () => hideProductModal());