wu-framework 1.1.12 → 1.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wu-framework",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "Universal Microfrontends Framework - 8 frameworks, zero config, Shadow DOM isolation",
5
5
  "main": "dist/wu-framework.cjs.js",
6
6
  "module": "src/index.js",
@@ -167,6 +167,25 @@ async function register(appName, Component, options = {}) {
167
167
 
168
168
  const { React, createRoot } = adapterState;
169
169
 
170
+ // Timer para diferir el unmount — permite que StrictMode remount lo cancele
171
+ let unmountTimer = null;
172
+
173
+ // Unmount real (sin defer)
174
+ const doUnmount = (container) => {
175
+ const instance = adapterState.roots.get(appName);
176
+ if (instance) {
177
+ try {
178
+ if (onUnmount) onUnmount(instance.container);
179
+ instance.root.unmount();
180
+ adapterState.roots.delete(appName);
181
+ } catch (error) {
182
+ console.error(`[WuReact] Unmount error for ${appName}:`, error);
183
+ }
184
+ }
185
+ const target = container || instance?.container;
186
+ if (target) target.innerHTML = '';
187
+ };
188
+
170
189
  // Función de mount interna
171
190
  const mountApp = (container) => {
172
191
  if (!container) {
@@ -174,26 +193,29 @@ async function register(appName, Component, options = {}) {
174
193
  return;
175
194
  }
176
195
 
177
- // Si ya está montado en el MISMO container, ignorar (StrictMode double-mount)
196
+ // Cancelar cualquier unmount diferido (patrón StrictMode: mount unmount remount)
197
+ if (unmountTimer) {
198
+ clearTimeout(unmountTimer);
199
+ unmountTimer = null;
200
+ }
201
+
202
+ // Si ya está montado en el MISMO container, ignorar
178
203
  const existing = adapterState.roots.get(appName);
179
204
  if (existing) {
180
205
  if (existing.container === container) {
181
206
  return; // Ya montado aquí, nada que hacer
182
207
  }
183
- // Diferente container → desmontar primero
184
- unmountApp();
208
+ // Diferente container → desmontar inmediatamente (no diferido)
209
+ doUnmount();
185
210
  }
186
211
 
187
212
  try {
188
- // Limpiar el DOM del container antes de crear un nuevo root.
189
- // En React 18+, root.unmount() es async — si se llama createRoot()
190
- // en el mismo container antes de que termine, falla silenciosamente.
191
- // Limpiar innerHTML fuerza un DOM limpio para el nuevo root.
213
+ // Limpiar el DOM antes de crear un nuevo root.
214
+ // root.unmount() de React 18+ es async — innerHTML = '' fuerza DOM limpio.
192
215
  container.innerHTML = '';
193
216
 
194
217
  const root = createRoot(container);
195
218
 
196
- // Crear elemento con o sin StrictMode
197
219
  let element = React.createElement(Component, props);
198
220
  if (strictMode && React.StrictMode) {
199
221
  element = React.createElement(React.StrictMode, null, element);
@@ -211,28 +233,16 @@ async function register(appName, Component, options = {}) {
211
233
  }
212
234
  };
213
235
 
214
- // Función de unmount interna
236
+ // Función de unmount diferida — espera 60ms antes de desmontar.
237
+ // Si mountApp se llama antes de que expire el timer, el unmount se cancela.
238
+ // Esto resuelve el ciclo StrictMode: effect(mount) → cleanup(unmount) → effect(mount)
239
+ // donde el cleanup ocurre ENTRE los dos mounts async.
215
240
  const unmountApp = (container) => {
216
- const instance = adapterState.roots.get(appName);
217
-
218
- if (instance) {
219
- try {
220
- if (onUnmount) {
221
- onUnmount(instance.container);
222
- }
223
-
224
- instance.root.unmount();
225
- adapterState.roots.delete(appName);
226
- } catch (error) {
227
- console.error(`[WuReact] Unmount error for ${appName}:`, error);
228
- }
229
- }
230
-
231
- // Limpiar container
232
- const target = container || instance?.container;
233
- if (target) {
234
- target.innerHTML = '';
235
- }
241
+ if (unmountTimer) clearTimeout(unmountTimer);
242
+ unmountTimer = setTimeout(() => {
243
+ unmountTimer = null;
244
+ doUnmount(container);
245
+ }, 60);
236
246
  };
237
247
 
238
248
  // Intentar registrar con Wu Framework