@@ -5,6 +5,7 @@ import "jquery";
55
66import { getStore } from "@smart-cloud/gatey-core" ;
77
8+ import { beginMount , endMount , resetMount } from "../shared/mountGuard" ;
89import { Theme } from "./theme" ;
910
1011const cache = new Map < string , string > ( ) ;
@@ -13,51 +14,55 @@ try {
1314 const call = async ( id : string ) => {
1415 const el = document . querySelector ( "#" + id ) ;
1516 if ( el ) {
16- jQuery ( el ) . data ( "rendered" , "true" ) ;
17+ if ( ! beginMount ( id , el ) ) {
18+ return ;
19+ }
1720
18- // Simple decode of single data-config attribute
19- const configAttr = el . getAttribute ( "data-config" ) ;
20- const config = configAttr ? JSON . parse ( atob ( configAttr ) ) : { } ;
21+ try {
22+ // Simple decode of single data-config attribute
23+ const configAttr = el . getAttribute ( "data-config" ) ;
24+ const config = configAttr ? JSON . parse ( atob ( configAttr ) ) : { } ;
2125
22- const isPreview = el . getAttribute ( "data-is-preview" ) === "true" ;
26+ const isPreview = el . getAttribute ( "data-is-preview" ) === "true" ;
2327
24- // Parse link if it's a JSON string
25- if ( config . link && typeof config . link === "string" ) {
26- try {
27- config . link = JSON . parse ( config . link ) ;
28- } catch {
29- /** */
28+ // Parse link if it's a JSON string
29+ if ( config . link && typeof config . link === "string" ) {
30+ try {
31+ config . link = JSON . parse ( config . link ) ;
32+ } catch {
33+ /** */
34+ }
3035 }
31- }
3236
33- const root = createRoot ( el ) ;
34- const fulfilledStore = await getStore ( ) ;
35- if ( cache . has ( id ) ) {
36- el . innerHTML = cache . get ( id ) || "" ;
37- } else {
38- cache . set ( id , el . innerHTML || "" ) ;
37+ const root = createRoot ( el ) ;
38+ const fulfilledStore = await getStore ( ) ;
39+ if ( cache . has ( id ) ) {
40+ el . innerHTML = cache . get ( id ) || "" ;
41+ } else {
42+ cache . set ( id , el . innerHTML || "" ) ;
43+ }
44+ root . render (
45+ < StrictMode >
46+ < Theme
47+ id = { id }
48+ isPreview = { isPreview }
49+ store = { fulfilledStore }
50+ { ...config }
51+ />
52+ </ StrictMode > ,
53+ ) ;
54+ } catch ( error ) {
55+ resetMount ( el ) ;
56+ throw error ;
57+ } finally {
58+ endMount ( id ) ;
3959 }
40- root . render (
41- < StrictMode >
42- < Theme
43- id = { id }
44- isPreview = { isPreview }
45- store = { fulfilledStore }
46- { ...config }
47- />
48- </ StrictMode > ,
49- ) ;
5060 }
5161 } ;
5262
5363 jQuery ( document ) . on ( "smartcloud-gatey-account-attribute-block" , ( _ , id ) =>
5464 call ( id ) ,
5565 ) ;
56- jQuery ( window ) . on ( "elementor/frontend/init" , function ( ) {
57- jQuery ( document ) . on ( "smartcloud-gatey-account-attribute-block" , ( _ , id ) =>
58- call ( id ) ,
59- ) ;
60- } ) ;
6166} catch ( err ) {
6267 console . error ( err ) ;
6368}
0 commit comments