payaza-storefront-layouts 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShadowDOMWrapper.d.ts","sourceRoot":"","sources":["../../src/preview/ShadowDOMWrapper.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAC;AAGrD,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"ShadowDOMWrapper.d.ts","sourceRoot":"","sources":["../../src/preview/ShadowDOMWrapper.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAC;AAGrD,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,qBAAqB,2CAgO/G"}
|
|
@@ -24,6 +24,7 @@ export function ShadowDOMWrapper({ children, className, onReady, onLinkClick, st
|
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
childrenRef.current = children;
|
|
26
26
|
}, [children]);
|
|
27
|
+
// Main effect: Create shadow root and React root on mount
|
|
27
28
|
useEffect(() => {
|
|
28
29
|
if (!shadowHostRef.current)
|
|
29
30
|
return;
|
|
@@ -34,9 +35,16 @@ export function ShadowDOMWrapper({ children, className, onReady, onLinkClick, st
|
|
|
34
35
|
const existingShadowRoot = shadowHostRef.current.shadowRoot;
|
|
35
36
|
if (existingShadowRoot) {
|
|
36
37
|
shadowRootRef.current = existingShadowRoot;
|
|
37
|
-
// Update content if shadow root already exists
|
|
38
38
|
const container = existingShadowRoot.getElementById('shadow-preview-container');
|
|
39
|
-
|
|
39
|
+
containerRef.current = container;
|
|
40
|
+
// If React root doesn't exist, create it
|
|
41
|
+
if (!reactRootRef.current && container) {
|
|
42
|
+
const root = createRoot(container);
|
|
43
|
+
reactRootRef.current = root;
|
|
44
|
+
root.render(childrenRef.current);
|
|
45
|
+
}
|
|
46
|
+
else if (reactRootRef.current && container && !isUnmountingRef.current) {
|
|
47
|
+
// Update content if root exists
|
|
40
48
|
reactRootRef.current.render(childrenRef.current);
|
|
41
49
|
}
|
|
42
50
|
onReady?.();
|
|
@@ -73,10 +81,8 @@ export function ShadowDOMWrapper({ children, className, onReady, onLinkClick, st
|
|
|
73
81
|
// Create React root and render children
|
|
74
82
|
const root = createRoot(container);
|
|
75
83
|
reactRootRef.current = root;
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
root.render(childrenRef.current);
|
|
79
|
-
}
|
|
84
|
+
// Always render on initial mount
|
|
85
|
+
root.render(childrenRef.current);
|
|
80
86
|
onReady?.();
|
|
81
87
|
}
|
|
82
88
|
catch (err) {
|
|
@@ -102,13 +108,15 @@ export function ShadowDOMWrapper({ children, className, onReady, onLinkClick, st
|
|
|
102
108
|
}, 0);
|
|
103
109
|
}
|
|
104
110
|
};
|
|
105
|
-
|
|
111
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
|
+
}, []); // Run only on mount - shadow root should persist across re-renders
|
|
106
113
|
// Update content when children change
|
|
107
114
|
useEffect(() => {
|
|
108
|
-
// Guard: Don't render if unmounting
|
|
109
|
-
if (isUnmountingRef.current
|
|
115
|
+
// Guard: Don't render if unmounting
|
|
116
|
+
if (isUnmountingRef.current) {
|
|
110
117
|
return;
|
|
111
118
|
}
|
|
119
|
+
// Only render if React root and container exist
|
|
112
120
|
if (reactRootRef.current && containerRef.current) {
|
|
113
121
|
try {
|
|
114
122
|
reactRootRef.current.render(childrenRef.current);
|
|
@@ -120,6 +128,21 @@ export function ShadowDOMWrapper({ children, className, onReady, onLinkClick, st
|
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
130
|
}
|
|
131
|
+
else if (shadowRootRef.current && !reactRootRef.current) {
|
|
132
|
+
// If shadow root exists but React root doesn't, try to recreate it
|
|
133
|
+
const container = shadowRootRef.current.getElementById('shadow-preview-container');
|
|
134
|
+
if (container) {
|
|
135
|
+
try {
|
|
136
|
+
const root = createRoot(container);
|
|
137
|
+
reactRootRef.current = root;
|
|
138
|
+
containerRef.current = container;
|
|
139
|
+
root.render(childrenRef.current);
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
console.warn('[ShadowDOMWrapper] Failed to recreate React root:', e);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
123
146
|
}, [children]);
|
|
124
147
|
// Set up link click handler when shadow root and props are ready
|
|
125
148
|
useEffect(() => {
|