Skip to content

Commit b086d8f

Browse files
committed
fix: case to handle async inserted vue sections
1 parent 20709ad commit b086d8f

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/main.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,31 @@ const createVueApp = () => {
8383
createVueApp().mount('#app')
8484

8585
/**
86-
* fix: properly render vue components inside sections on user insert in the theme editor
87-
* add the 'vue' keyword to the section's wrapper classes e.g.:
86+
* fixes for Shopify sections
87+
* 1. properly render vue components on user insert in the theme editor
88+
* 2. reload the current page to rerender async inserted sections with vue components
89+
*
90+
* add the 'vue' keyword to the section's wrapper classes if the section uses any vue functionality e.g.:
8891
* {% schema %}
8992
* {
9093
* "class": "vue-section"
9194
* }
9295
* {% endschema %}
9396
*/
94-
Shopify.designMode && document.addEventListener('shopify:section:load', (event) => {
95-
if (event.target.classList.value.includes('vue')) {
96-
createVueApp().mount(event.target)
97-
}
98-
})
97+
if (Shopify.designMode) {
98+
document.addEventListener('shopify:section:load', (event) => {
99+
if (event.target.classList.value.includes('vue')) {
100+
createVueApp().mount(event.target)
101+
}
102+
})
103+
} else if (!Shopify.designMode && process.env.NODE_ENV === 'development') {
104+
new MutationObserver((mutationsList) => {
105+
mutationsList.forEach(record => {
106+
const vue = Array.from(record.addedNodes).find(node => node.classList && node.classList.value.includes('vue'))
107+
if (vue) window.location.reload()
108+
})
109+
}).observe(document.body, {
110+
childList: true,
111+
subtree: true
112+
})
113+
}

0 commit comments

Comments
 (0)