File tree 1 file changed +22
-7
lines changed
1 file changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -83,16 +83,31 @@ const createVueApp = () => {
83
83
createVueApp ( ) . mount ( '#app' )
84
84
85
85
/**
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.:
88
91
* {% schema %}
89
92
* {
90
93
* "class": "vue-section"
91
94
* }
92
95
* {% endschema %}
93
96
*/
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
+ }
You can’t perform that action at this time.
0 commit comments