@zeus-js/web-c-runtime 0.1.1-beta.16 → 0.1.1-beta.18

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,5 +1,5 @@
1
1
  /**
2
- * web-c-runtime v0.1.1-beta.16
2
+ * web-c-runtime v0.1.1-beta.18
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -218,9 +218,14 @@ function _asyncToGenerator(n) {
218
218
  //#endregion
219
219
  //#region packages/web-c/web-c-runtime/src/lifecycle.ts
220
220
  const moduleCache = /* @__PURE__ */ new WeakMap();
221
+ const ancestorWaitCancellations = /* @__PURE__ */ new WeakMap();
222
+ function cancelAncestorWait(hostRef) {
223
+ var _ancestorWaitCancella;
224
+ (_ancestorWaitCancella = ancestorWaitCancellations.get(hostRef)) === null || _ancestorWaitCancella === void 0 || _ancestorWaitCancella();
225
+ }
221
226
  function waitForComponentReady(hostRef) {
222
- if (hostRef.loaded) return Promise.resolve(hostRef.host);
223
227
  if (hostRef.readinessError) return Promise.reject(hostRef.readinessError);
228
+ if (hostRef.loaded && !hostRef.loading) return Promise.resolve(hostRef.host);
224
229
  return new Promise((resolve, reject) => {
225
230
  hostRef.readyWaiters.push({
226
231
  resolve,
@@ -238,18 +243,18 @@ function initializeComponent(_x) {
238
243
  }
239
244
  function _initializeComponent() {
240
245
  _initializeComponent = _asyncToGenerator(function* (hostRef) {
241
- if (hostRef.loaded) {
242
- var _hostRef$instance, _hostRef$instance$con;
243
- (_hostRef$instance = hostRef.instance) === null || _hostRef$instance === void 0 || (_hostRef$instance$con = _hostRef$instance.connected) === null || _hostRef$instance$con === void 0 || _hostRef$instance$con.call(_hostRef$instance);
244
- flushPendingFormCallbacks(hostRef);
245
- return;
246
- }
247
246
  if (hostRef.loading) {
248
247
  yield hostRef.loading;
249
248
  if (hostRef.connected && !hostRef.loaded) yield initializeComponent(hostRef);
250
249
  return;
251
250
  }
252
- const loading = doInitializeComponent(hostRef);
251
+ if (hostRef.loaded && !findPendingAncestor(hostRef.host)) {
252
+ var _hostRef$instance, _hostRef$instance$con;
253
+ (_hostRef$instance = hostRef.instance) === null || _hostRef$instance === void 0 || (_hostRef$instance$con = _hostRef$instance.connected) === null || _hostRef$instance$con === void 0 || _hostRef$instance$con.call(_hostRef$instance);
254
+ flushPendingFormCallbacks(hostRef);
255
+ return;
256
+ }
257
+ const loading = hostRef.loaded ? reconnectComponent(hostRef) : doInitializeComponent(hostRef);
253
258
  hostRef.loading = loading;
254
259
  try {
255
260
  yield loading;
@@ -259,6 +264,7 @@ function _initializeComponent() {
259
264
  } finally {
260
265
  if (hostRef.loading === loading) hostRef.loading = void 0;
261
266
  }
267
+ if (hostRef.connected && hostRef.loaded) resolveReadyWaiters(hostRef);
262
268
  });
263
269
  return _initializeComponent.apply(this, arguments);
264
270
  }
@@ -269,6 +275,7 @@ function _doInitializeComponent() {
269
275
  _doInitializeComponent = _asyncToGenerator(function* (hostRef) {
270
276
  applyInitialValues(hostRef);
271
277
  const mod = yield loadComponentModule(hostRef);
278
+ yield waitForAncestors(hostRef);
272
279
  if (!hostRef.connected) return;
273
280
  const instance = mod.createComponent(hostRef);
274
281
  hostRef.instance = instance;
@@ -279,7 +286,6 @@ function _doInitializeComponent() {
279
286
  const rendered = (_instance$render = instance.render) === null || _instance$render === void 0 ? void 0 : _instance$render.call(instance);
280
287
  if (rendered !== void 0) mountRenderedOutput(hostRef, rendered);
281
288
  hostRef.loaded = true;
282
- resolveReadyWaiters(hostRef);
283
289
  } catch (error) {
284
290
  var _instance$dispose;
285
291
  hostRef.instance = void 0;
@@ -290,13 +296,81 @@ function _doInitializeComponent() {
290
296
  });
291
297
  return _doInitializeComponent.apply(this, arguments);
292
298
  }
299
+ function reconnectComponent(_x3) {
300
+ return _reconnectComponent.apply(this, arguments);
301
+ }
302
+ function _reconnectComponent() {
303
+ _reconnectComponent = _asyncToGenerator(function* (hostRef) {
304
+ var _hostRef$instance2, _hostRef$instance2$co;
305
+ yield waitForAncestors(hostRef);
306
+ if (!hostRef.connected) return;
307
+ (_hostRef$instance2 = hostRef.instance) === null || _hostRef$instance2 === void 0 || (_hostRef$instance2$co = _hostRef$instance2.connected) === null || _hostRef$instance2$co === void 0 || _hostRef$instance2$co.call(_hostRef$instance2);
308
+ flushPendingFormCallbacks(hostRef);
309
+ });
310
+ return _reconnectComponent.apply(this, arguments);
311
+ }
312
+ function waitForAncestors(_x4) {
313
+ return _waitForAncestors.apply(this, arguments);
314
+ }
315
+ function _waitForAncestors() {
316
+ _waitForAncestors = _asyncToGenerator(function* (hostRef) {
317
+ let ancestor = findPendingAncestor(hostRef.host);
318
+ while (hostRef.connected && ancestor) {
319
+ try {
320
+ yield waitForAncestorReady(hostRef, ancestor);
321
+ } catch (error) {
322
+ if (hostRef.connected && ancestor.connected && ancestor.readinessError === error && findPendingAncestor(hostRef.host) === ancestor) throw error;
323
+ }
324
+ ancestor = findPendingAncestor(hostRef.host);
325
+ }
326
+ });
327
+ return _waitForAncestors.apply(this, arguments);
328
+ }
329
+ function waitForAncestorReady(hostRef, ancestor) {
330
+ if (ancestor.readinessError) return Promise.reject(ancestor.readinessError);
331
+ if (ancestor.loaded && !ancestor.loading) return Promise.resolve();
332
+ return new Promise((resolve, reject) => {
333
+ const cleanup = () => {
334
+ const index = ancestor.readyWaiters.indexOf(waiter);
335
+ if (index >= 0) ancestor.readyWaiters.splice(index, 1);
336
+ if (ancestorWaitCancellations.get(hostRef) === cancel) ancestorWaitCancellations.delete(hostRef);
337
+ };
338
+ const cancel = () => {
339
+ cleanup();
340
+ resolve();
341
+ };
342
+ const waiter = {
343
+ resolve() {
344
+ cleanup();
345
+ resolve();
346
+ },
347
+ reject(error) {
348
+ cleanup();
349
+ reject(error);
350
+ }
351
+ };
352
+ ancestorWaitCancellations.set(hostRef, cancel);
353
+ ancestor.readyWaiters.push(waiter);
354
+ });
355
+ }
356
+ function findPendingAncestor(host) {
357
+ let node = host.parentNode;
358
+ while (node) {
359
+ var _node$parentNode;
360
+ if (node.nodeType === 1) {
361
+ const ancestor = getHostRef(node);
362
+ if ((ancestor === null || ancestor === void 0 ? void 0 : ancestor.connected) && (!ancestor.loaded || ancestor.loading || ancestor.readinessError)) return ancestor;
363
+ }
364
+ node = (_node$parentNode = node.parentNode) !== null && _node$parentNode !== void 0 ? _node$parentNode : node.nodeType === 11 ? node.host : null;
365
+ }
366
+ }
293
367
  function flushPendingFormCallbacks(hostRef) {
294
368
  while (hostRef.pendingFormCallbacks.length > 0) {
295
369
  invokeFormCallback(hostRef, hostRef.pendingFormCallbacks[0]);
296
370
  hostRef.pendingFormCallbacks.shift();
297
371
  }
298
372
  }
299
- function loadComponentModule(_x3) {
373
+ function loadComponentModule(_x5) {
300
374
  return _loadComponentModule.apply(this, arguments);
301
375
  }
302
376
  function _loadComponentModule() {
@@ -357,6 +431,7 @@ function createLazyElementClass(meta) {
357
431
  upgradePreDefinedProperties(this, hostRef);
358
432
  }
359
433
  connectedCallback() {
434
+ if (this.isConnected === false) return;
360
435
  const hostRef = requireHostRef(this);
361
436
  hostRef.connected = true;
362
437
  hostRef.readinessError = void 0;
@@ -365,10 +440,11 @@ function createLazyElementClass(meta) {
365
440
  });
366
441
  }
367
442
  disconnectedCallback() {
368
- if (isWithinRuntimeDomMove(this)) return;
369
443
  const hostRef = requireHostRef(this);
444
+ cancelAncestorWait(hostRef);
445
+ if (isWithinRuntimeDomMove(this)) return;
370
446
  hostRef.connected = false;
371
- if (!hostRef.loaded) rejectComponentReady(hostRef, /* @__PURE__ */ new Error(`[ZEUS_WC_DISCONNECTED_BEFORE_READY] <${meta.tagName}> disconnected before initialization completed.`));
447
+ if (!hostRef.loaded || hostRef.loading) rejectComponentReady(hostRef, /* @__PURE__ */ new Error(`[ZEUS_WC_DISCONNECTED_BEFORE_READY] <${meta.tagName}> disconnected before initialization completed.`));
372
448
  if (hostRef.loaded) try {
373
449
  var _hostRef$instance, _hostRef$instance$dis;
374
450
  (_hostRef$instance = hostRef.instance) === null || _hostRef$instance === void 0 || (_hostRef$instance$dis = _hostRef$instance.disconnected) === null || _hostRef$instance$dis === void 0 || _hostRef$instance$dis.call(_hostRef$instance);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zeus-js/web-c-runtime",
3
3
  "type": "module",
4
- "version": "0.1.1-beta.16",
4
+ "version": "0.1.1-beta.18",
5
5
  "description": "Zeus Web-C lazy-loading runtime",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -26,7 +26,7 @@
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
29
- "@zeus-js/runtime-dom": "0.1.1-beta.16"
29
+ "@zeus-js/runtime-dom": "0.1.1-beta.18"
30
30
  },
31
31
  "author": "Baicie",
32
32
  "buildOptions": {