@qwik.dev/core 2.0.0-beta.8 → 2.0.0-beta.9

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,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core 2.0.0-beta.8-dev+434cd18
3
+ * @qwik.dev/core 2.0.0-beta.9-dev+6b582c7
4
4
  * Copyright QwikDev. All Rights Reserved.
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://github.com/QwikDev/qwik/blob/main/LICENSE
@@ -9,6 +9,7 @@
9
9
  "object" == typeof exports && "undefined" != typeof module ? factory(exports, require("@qwik.dev/core/build"), require("@qwik.dev/core/preloader")) : "function" == typeof define && define.amd ? define([ "exports", "@qwik.dev/core/build", "@qwik.dev/core/preloader" ], factory) : factory((global = "undefined" != typeof globalThis ? globalThis : global || self).qwikCore = {}, global.qwikBuild, global.qwikPreloader);
10
10
  }(this, function(exports, build, preloader) {
11
11
  "use strict";
12
+ const version = "2.0.0-beta.9-dev+6b582c7";
12
13
  const qDev = !1;
13
14
  const seal = () => {
14
15
  qDev;
@@ -38,6 +39,7 @@
38
39
  const text = (code => `Code(Q${code}) https://github.com/QwikDev/qwik/blob/main/packages/qwik/src/core/error/error.ts#L${8 + code}`)(code, ...errorMessageArgs);
39
40
  return ((message, ...optionalParams) => createAndLogError(qDev, message, ...optionalParams))(text, ...errorMessageArgs);
40
41
  };
42
+ const isSyncQrl = value => isQrl(value) && "<sync>" == value.$symbol$;
41
43
  const isQrl = value => "function" == typeof value && "function" == typeof value.getSymbol;
42
44
  function assertQrl(qrl) {
43
45
  if (build.isDev && !isQrl(qrl)) {
@@ -80,11 +82,6 @@
80
82
  resolve(fn());
81
83
  });
82
84
  }),
83
- nextTick: fn => new Promise(resolve => {
84
- setTimeout(() => {
85
- resolve(fn());
86
- });
87
- }),
88
85
  chunkForSymbol: (symbolName, chunk) => [ symbolName, chunk ?? "_" ]
89
86
  });
90
87
  const toUrl = (doc, containerEl, url) => {
@@ -156,6 +153,9 @@
156
153
  constructor(container, value) {
157
154
  this.$container$ = container, this.$untrackedValue$ = value;
158
155
  }
156
+ force() {
157
+ this.$container$?.$scheduler$(7, null, this, this.$effects$);
158
+ }
159
159
  get untrackedValue() {
160
160
  return this.$untrackedValue$;
161
161
  }
@@ -166,7 +166,7 @@
166
166
  return setupSignalValueAccess(this, () => this.$effects$ ||= new Set, () => this.untrackedValue);
167
167
  }
168
168
  set value(value) {
169
- value !== this.$untrackedValue$ && (this.$untrackedValue$ = value, triggerEffects(this.$container$, this, this.$effects$));
169
+ value !== this.$untrackedValue$ && (this.$untrackedValue$ = value, this.$container$?.$scheduler$(7, null, this, this.$effects$));
170
170
  }
171
171
  valueOf() {
172
172
  qDev;
@@ -205,29 +205,26 @@
205
205
  $funcStr$;
206
206
  $flags$;
207
207
  $hostElement$=null;
208
- $forceRunEffects$=!1;
209
208
  [_EFFECT_BACK_REF]=null;
210
- constructor(container, fn, args, fnStr, flags = 3) {
209
+ constructor(container, fn, args, fnStr, flags = 5) {
211
210
  super(container, NEEDS_COMPUTATION), this.$args$ = args, this.$func$ = fn, this.$funcStr$ = fnStr,
212
211
  this.$flags$ = flags;
213
212
  }
214
213
  invalidate() {
215
- this.$flags$ |= 1, this.$forceRunEffects$ = !1, this.$container$?.$scheduler$(7, this.$hostElement$, this, this.$effects$);
214
+ this.$flags$ |= 1, this.$container$?.$scheduler$(7, this.$hostElement$, this, this.$effects$);
216
215
  }
217
216
  force() {
218
- this.$forceRunEffects$ = !0, this.$container$?.$scheduler$(7, this.$hostElement$, this, this.$effects$);
217
+ this.$flags$ |= 2, this.$container$?.$scheduler$(7, this.$hostElement$, this, this.$effects$);
219
218
  }
220
219
  get untrackedValue() {
221
- const didChange = this.$computeIfNeeded$();
222
- return didChange && (this.$forceRunEffects$ = didChange), assertFalse(), this.$untrackedValue$;
220
+ return this.$computeIfNeeded$(), assertFalse(), this.$untrackedValue$;
223
221
  }
224
222
  $computeIfNeeded$() {
225
223
  if (!(1 & this.$flags$)) {
226
- return !1;
224
+ return;
227
225
  }
228
226
  const untrackedValue = trackSignal(() => this.$func$(...this.$args$), this, ".", this.$container$);
229
- const didChange = untrackedValue !== this.$untrackedValue$;
230
- return didChange && (this.$untrackedValue$ = untrackedValue), didChange;
227
+ untrackedValue !== this.$untrackedValue$ && (this.$flags$ |= 2, this.$untrackedValue$ = untrackedValue);
231
228
  }
232
229
  set value(_) {
233
230
  throw qError(31);
@@ -237,13 +234,15 @@
237
234
  }
238
235
  }
239
236
  function getSubscriber(effect, prop, data) {
240
- var value;
241
- effect[_EFFECT_BACK_REF] || (build.isServer && ("__brand__" in (value = effect) && "SsrNode" === value.__brand__) ? effect.setProp("q:brefs", new Map) : effect[_EFFECT_BACK_REF] = new Map);
237
+ effect[_EFFECT_BACK_REF] || (build.isServer && isSsrNode(effect) ? effect.setProp("q:brefs", new Map) : effect[_EFFECT_BACK_REF] = new Map);
242
238
  const subMap = effect[_EFFECT_BACK_REF];
243
239
  let sub = subMap.get(prop);
244
240
  return sub || (sub = [ effect, prop ], subMap.set(prop, sub)), data && (sub[3] = data),
245
241
  sub;
246
242
  }
243
+ function isSsrNode(value) {
244
+ return "__brand__" in value && "SsrNode" === value.__brand__;
245
+ }
247
246
  let _context;
248
247
  const tryGetInvokeContext = () => {
249
248
  if (!_context) {
@@ -400,7 +399,6 @@
400
399
  set(1));
401
400
  };
402
401
  const ERROR_CONTEXT = /*#__PURE__*/ createContextId("qk-error");
403
- const version = "2.0.0-beta.8-dev+434cd18";
404
402
  const EMPTY_ARRAY = [];
405
403
  const EMPTY_OBJ = {};
406
404
  Object.freeze(EMPTY_ARRAY), Object.freeze(EMPTY_OBJ);
@@ -453,7 +451,7 @@
453
451
  }
454
452
  return qrl.$captureRef$;
455
453
  };
456
- const queueQRL = (...args) => {
454
+ const _run = (...args) => {
457
455
  const [runQrl] = useLexicalScope();
458
456
  const context = getInvokeContext();
459
457
  const hostElement = context.$hostElement$;
@@ -464,7 +462,8 @@
464
462
  if (!scheduler) {
465
463
  throw qError(1);
466
464
  }
467
- return scheduler(2, hostElement, runQrl, args);
465
+ const chore = scheduler(2, hostElement, runQrl, args);
466
+ return getChorePromise(chore);
468
467
  };
469
468
  const mapApp_findIndx = (array, key, start) => {
470
469
  assertTrue();
@@ -499,24 +498,22 @@
499
498
  class ComputedSignalImpl extends SignalImpl {
500
499
  $computeQrl$;
501
500
  $flags$;
502
- $forceRunEffects$=!1;
503
501
  [_EFFECT_BACK_REF]=null;
504
- constructor(container, fn, flags = 17) {
502
+ constructor(container, fn, flags = 33) {
505
503
  super(container, NEEDS_COMPUTATION), this.$computeQrl$ = fn, this.$flags$ = flags;
506
504
  }
507
505
  invalidate() {
508
- this.$flags$ |= 1, this.$forceRunEffects$ = !1, this.$container$?.$scheduler$(7, null, this, this.$effects$);
506
+ this.$flags$ |= 1, this.$container$?.$scheduler$(7, null, this, this.$effects$);
509
507
  }
510
508
  force() {
511
- this.$forceRunEffects$ = !0, this.$container$?.$scheduler$(7, null, this, this.$effects$);
509
+ this.$flags$ |= 2, super.force();
512
510
  }
513
511
  get untrackedValue() {
514
- const didChange = this.$computeIfNeeded$();
515
- return didChange && (this.$forceRunEffects$ = didChange), assertFalse(), this.$untrackedValue$;
512
+ return this.$computeIfNeeded$(), assertFalse(), this.$untrackedValue$;
516
513
  }
517
514
  $computeIfNeeded$() {
518
515
  if (!(1 & this.$flags$)) {
519
- return !1;
516
+ return;
520
517
  }
521
518
  const computeQrl = this.$computeQrl$;
522
519
  throwIfQRLNotResolved(computeQrl);
@@ -529,8 +526,8 @@
529
526
  throw qError(29, [ computeQrl.dev ? computeQrl.dev.file : "", computeQrl.$hash$ ]);
530
527
  }
531
528
  this.$flags$ &= -2;
532
- const didChange = untrackedValue !== this.$untrackedValue$;
533
- return didChange && (this.$untrackedValue$ = untrackedValue), didChange;
529
+ untrackedValue !== this.$untrackedValue$ && (this.$untrackedValue$ !== NEEDS_COMPUTATION && (this.$flags$ |= 2),
530
+ this.$untrackedValue$ = untrackedValue);
534
531
  } finally {
535
532
  ctx && (ctx.$effectSubscriber$ = previousEffectSubscription);
536
533
  }
@@ -544,12 +541,12 @@
544
541
  }
545
542
  class SerializerSignalImpl extends ComputedSignalImpl {
546
543
  constructor(container, argQrl) {
547
- super(container, argQrl, 17);
544
+ super(container, argQrl, 33);
548
545
  }
549
546
  $didInitialize$=!1;
550
547
  $computeIfNeeded$() {
551
548
  if (!(1 & this.$flags$)) {
552
- return !1;
549
+ return;
553
550
  }
554
551
  throwIfQRLNotResolved(this.$computeQrl$);
555
552
  let arg = this.$computeQrl$.resolved;
@@ -559,12 +556,16 @@
559
556
  const currentValue = this.$untrackedValue$ === NEEDS_COMPUTATION ? initial : this.$untrackedValue$;
560
557
  const untrackedValue = trackSignal(() => this.$didInitialize$ ? update?.(currentValue) || currentValue : deserialize(currentValue), this, ".", this.$container$);
561
558
  const didChange = this.$didInitialize$ && "undefined" !== untrackedValue || untrackedValue !== this.$untrackedValue$;
562
- return this.$flags$ &= -2, this.$didInitialize$ = !0, didChange && (this.$untrackedValue$ = untrackedValue),
563
- didChange;
559
+ this.$flags$ &= -2, this.$didInitialize$ = !0, didChange && (this.$flags$ |= 2,
560
+ this.$untrackedValue$ = untrackedValue);
564
561
  }
565
562
  }
566
563
  const getStoreHandler = value => value[STORE_HANDLER];
567
564
  const getStoreTarget = value => value?.[STORE_TARGET] || null;
565
+ const forceStoreEffects = (value, prop) => {
566
+ const handler = getStoreHandler(value);
567
+ handler && handler.force(prop);
568
+ };
568
569
  const unwrapStore = value => getStoreTarget(value) || value;
569
570
  const isStore = value => STORE_TARGET in value;
570
571
  function createStore(container, obj, flags) {
@@ -588,6 +589,10 @@
588
589
  toString() {
589
590
  return "[Store]";
590
591
  }
592
+ force(prop) {
593
+ const target = getStoreTarget(this);
594
+ this.$container$?.$scheduler$(7, null, this, getEffects(target, prop, this.$effects$));
595
+ }
591
596
  get(target, prop) {
592
597
  if ("symbol" == typeof prop) {
593
598
  return prop === STORE_TARGET ? target : prop === STORE_HANDLER ? this : target[prop];
@@ -624,7 +629,7 @@
624
629
  return !0;
625
630
  }
626
631
  deleteProperty(target, prop) {
627
- return "string" == typeof prop && delete target[prop] && (triggerEffects(this.$container$, this, getEffects(target, prop, this.$effects$)),
632
+ return "string" == typeof prop && delete target[prop] && (Array.isArray(target) || this.$container$?.$scheduler$(7, null, this, getEffects(target, prop, this.$effects$)),
628
633
  !0);
629
634
  }
630
635
  has(target, prop) {
@@ -661,7 +666,9 @@
661
666
  ensureContainsBackRef(effectSubscription, target), addQrlToSerializationCtx(effectSubscription, store.$container$);
662
667
  }
663
668
  function setNewValueAndTriggerEffects(prop, value, target, currentStore) {
664
- target[prop] = value, triggerEffects(currentStore.$container$, currentStore, getEffects(target, prop, currentStore.$effects$));
669
+ target[prop] = value;
670
+ const effects = getEffects(target, prop, currentStore.$effects$);
671
+ effects && currentStore.$container$?.$scheduler$(7, null, currentStore, effects);
665
672
  }
666
673
  function getEffects(target, prop, storeEffects) {
667
674
  let effectsToTrigger;
@@ -754,7 +761,7 @@
754
761
  }
755
762
  $computeIfNeeded$() {
756
763
  if (!(1 & this.$flags$)) {
757
- return !1;
764
+ return;
758
765
  }
759
766
  const computeQrl = this.$computeQrl$;
760
767
  throwIfQRLNotResolved(computeQrl);
@@ -772,7 +779,8 @@
772
779
  }
773
780
  this.$promiseValue$ = NEEDS_COMPUTATION, this.$flags$ &= -2;
774
781
  const didChange = untrackedValue !== this.$untrackedValue$;
775
- return didChange && (this.$untrackedValue$ = untrackedValue), didChange;
782
+ return didChange && (this.$flags$ |= 2, this.$untrackedValue$ = untrackedValue),
783
+ didChange;
776
784
  }
777
785
  }
778
786
  const createComputedSignal = (qrl, options) => new ComputedSignalImpl(options?.container || null, qrl, getComputedSignalFlags(options?.serializationStrategy || "always"));
@@ -792,7 +800,7 @@
792
800
  return obj[prop];
793
801
  }
794
802
  if (isSignal(obj)) {
795
- return obj instanceof AsyncComputedSignalImpl || assertEqual(), obj instanceof WrappedSignalImpl && 2 & obj.flags ? obj : getWrapped(args);
803
+ return obj instanceof AsyncComputedSignalImpl || assertEqual(), obj instanceof WrappedSignalImpl && 4 & obj.flags ? obj : getWrapped(args);
796
804
  }
797
805
  if (isPropsProxy(obj)) {
798
806
  const constProps = obj[_CONST_PROPS];
@@ -1014,8 +1022,8 @@
1014
1022
  }
1015
1023
  targetElement = placeholderElement;
1016
1024
  }
1017
- targetElement && ("script" === targetElement.type && key === qVisibleEvent && (eventKey = "document:onQinit$",
1018
- logWarn('You are trying to add an event "' + key + '" using `useVisibleTask$` hook, but a node to which you can add an event is not found. Using document:onQinit$ instead.')),
1025
+ targetElement && ("script" === targetElement.type && key === qVisibleEvent && (eventKey = "document:onQInit$",
1026
+ logWarn('You are trying to add an event "' + key + '" using `useVisibleTask$` hook, but a node to which you can add an event is not found. Using document:onQInit$ instead.')),
1019
1027
  addUseOnEvent(targetElement, eventKey, useOnEvents[key]));
1020
1028
  }
1021
1029
  }
@@ -1167,9 +1175,18 @@
1167
1175
  }(jsx, options.styleScoped);
1168
1176
  let qwikInspectorAttrValue = null;
1169
1177
  build.isDev && jsx.dev && "head" !== jsx.type && (qwikInspectorAttrValue = getFileLocationFromJsx(jsx.dev));
1170
- const innerHTML = ssr.openElement(type, toSsrAttrs(jsx.varProps, jsx.constProps, ssr.serializationCtx, !0, options.styleScoped, jsx.key), function(constProps, varProps, serializationCtx, styleScopedId) {
1171
- return toSsrAttrs(constProps, varProps, serializationCtx, !1, styleScopedId);
1172
- }(jsx.constProps, jsx.varProps, ssr.serializationCtx, options.styleScoped), qwikInspectorAttrValue);
1178
+ const innerHTML = ssr.openElement(type, function(varProps, constProps, options) {
1179
+ return toSsrAttrs(varProps, constProps, !1, options);
1180
+ }(jsx.varProps, jsx.constProps, {
1181
+ serializationCtx: ssr.serializationCtx,
1182
+ styleScopedId: options.styleScoped,
1183
+ key: jsx.key
1184
+ }), function(constProps, varProps, options) {
1185
+ return toSsrAttrs(constProps, varProps, !0, options);
1186
+ }(jsx.constProps, jsx.varProps, {
1187
+ serializationCtx: ssr.serializationCtx,
1188
+ styleScopedId: options.styleScoped
1189
+ }), qwikInspectorAttrValue);
1173
1190
  innerHTML && ssr.htmlNode(innerHTML), enqueue(ssr.closeElement), "head" === type ? (ssr.emitQwikLoaderAtTopIfNeeded(),
1174
1191
  ssr.emitPreloaderPre(), enqueue(ssr.additionalHeadNodes)) : "body" === type ? enqueue(ssr.additionalBodyNodes) : ssr.isHtml || ssr._didAddQwikLoader || (ssr.emitQwikLoaderAtTopIfNeeded(),
1175
1192
  ssr.emitPreloaderPre(), ssr._didAddQwikLoader = !0);
@@ -1233,10 +1250,10 @@
1233
1250
  const host = ssr.getOrCreateLastNode();
1234
1251
  const [componentQrl] = component[SERIALIZABLE_STATE];
1235
1252
  const srcProps = jsx.props;
1236
- srcProps && srcProps.children && delete srcProps.children;
1237
- const scheduler = ssr.$scheduler$;
1238
- return host.setProp("q:renderFn", componentQrl), host.setProp("q:props", srcProps),
1239
- null !== jsx.key && host.setProp("q:key", jsx.key), scheduler(6, host, componentQrl, srcProps);
1253
+ srcProps && srcProps.children && delete srcProps.children, host.setProp("q:renderFn", componentQrl),
1254
+ host.setProp("q:props", srcProps), null !== jsx.key && host.setProp("q:key", jsx.key);
1255
+ const componentChore = ssr.$scheduler$(6, host, componentQrl, srcProps);
1256
+ return getChorePromise(componentChore);
1240
1257
  })(ssr, jsx, type);
1241
1258
  const compStyleComponentId = addComponentStylePrefix(host.getProp("q:sstyle"));
1242
1259
  enqueue(new ParentComponentData(options.styleScoped, options.parentComponentFrame)),
@@ -1257,10 +1274,11 @@
1257
1274
  }
1258
1275
  }
1259
1276
  }
1260
- function toSsrAttrs(record, anotherRecord, serializationCtx, pushMergedEventProps, styleScopedId, key) {
1277
+ function toSsrAttrs(record, anotherRecord, isConst, options) {
1261
1278
  if (null == record) {
1262
1279
  return null;
1263
1280
  }
1281
+ const pushMergedEventProps = !isConst;
1264
1282
  const ssrAttrs = [];
1265
1283
  for (const key in record) {
1266
1284
  let value = record[key];
@@ -1274,14 +1292,14 @@
1274
1292
  value = getMergedEventPropValues(value, anotherValue);
1275
1293
  }
1276
1294
  }
1277
- const eventValue = setEvent(serializationCtx, key, value);
1295
+ const eventValue = setEvent(options.serializationCtx, key, value);
1278
1296
  eventValue && ssrAttrs.push(jsxEventToHtmlAttribute(key), eventValue);
1279
1297
  continue;
1280
1298
  }
1281
- isSignal(value) ? isClassAttr(key) ? ssrAttrs.push(key, [ value, styleScopedId ]) : ssrAttrs.push(key, value) : (isPreventDefault(key) && addPreventDefaultEventToSerializationContext(serializationCtx, key),
1282
- value = serializeAttribute(key, value, styleScopedId), ssrAttrs.push(key, value));
1299
+ isSignal(value) ? isClassAttr(key) ? ssrAttrs.push(key, [ value, options.styleScopedId ]) : ssrAttrs.push(key, value) : (isPreventDefault(key) && addPreventDefaultEventToSerializationContext(options.serializationCtx, key),
1300
+ value = serializeAttribute(key, value, options.styleScopedId), ssrAttrs.push(key, value));
1283
1301
  }
1284
- return null != key && ssrAttrs.push("q:key", key), ssrAttrs;
1302
+ return null != options.key && ssrAttrs.push("q:key", options.key), ssrAttrs;
1285
1303
  }
1286
1304
  function getMergedEventPropValues(value, anotherValue) {
1287
1305
  let mergedValue = value;
@@ -1303,7 +1321,7 @@
1303
1321
  const appendToValue = valueToAppend => {
1304
1322
  value = (null == value ? "" : value + "\n") + valueToAppend;
1305
1323
  };
1306
- const getQrlString = qrl => (qrl.$symbol$.startsWith("_") || !qrl.$captureRef$ && !qrl.$capture$ || (qrl = createQRL(null, "_run", queueQRL, null, null, [ qrl ])),
1324
+ const getQrlString = qrl => (qrl.$symbol$.startsWith("_") || !qrl.$captureRef$ && !qrl.$capture$ || (qrl = createQRL(null, "_run", _run, null, null, [ qrl ])),
1307
1325
  qrlToString(serializationCtx, qrl));
1308
1326
  if (Array.isArray(qrls)) {
1309
1327
  for (let i = 0; i <= qrls.length; i++) {
@@ -1336,8 +1354,10 @@
1336
1354
  assertQrl(qrl), set(1);
1337
1355
  const task = new Task(10, i, iCtx.$hostElement$, qrl, void 0, null);
1338
1356
  set(task);
1339
- const promise = iCtx.$container$.$scheduler$(3, task);
1340
- isPromise(promise) && promise.catch(() => {});
1357
+ const result = runTask(task, iCtx.$container$, iCtx.$hostElement$);
1358
+ if (isPromise(result)) {
1359
+ throw result;
1360
+ }
1341
1361
  };
1342
1362
  const runTask = (task, container, host) => {
1343
1363
  task.$flags$ &= -9, cleanupTask(task);
@@ -1385,7 +1405,7 @@
1385
1405
  const isTask = value => value instanceof Task;
1386
1406
  const scheduleTask = (_event, element) => {
1387
1407
  const [task] = useLexicalScope();
1388
- const type = 1 & task.$flags$ ? 32 : 3;
1408
+ const type = 1 & task.$flags$ ? 16 : 3;
1389
1409
  getDomContainer(element).$scheduler$(type, task);
1390
1410
  };
1391
1411
  const _jsxSorted = (type, varProps, constProps, children, flags, key) => {
@@ -1466,7 +1486,7 @@
1466
1486
  return this.$children$;
1467
1487
  }
1468
1488
  const value = this.$constProps$ && prop in this.$constProps$ ? this.$constProps$[prop] : this.$varProps$[prop];
1469
- return value instanceof WrappedSignalImpl && 2 & value.$flags$ ? value.value : value;
1489
+ return value instanceof WrappedSignalImpl && 4 & value.$flags$ ? value.value : value;
1470
1490
  }
1471
1491
  set(_, prop, value) {
1472
1492
  return prop === _CONST_PROPS ? (this.$constProps$ = value, !0) : prop === _VAR_PROPS ? (this.$varProps$ = value,
@@ -1671,36 +1691,38 @@
1671
1691
  }
1672
1692
  }();
1673
1693
  function diff(jsxNode, vStartNode) {
1674
- for (assertFalse(vnode_isVNode(jsxNode)), assertTrue(vnode_isVNode(vStartNode)),
1694
+ if (assertFalse(vnode_isVNode(jsxNode)), assertTrue(vnode_isVNode(vStartNode)),
1675
1695
  vParent = vStartNode, vNewNode = null, vCurrent = vnode_getFirstChild(vStartNode),
1676
- stackPush(jsxNode, !0); stack.length; ) {
1677
- for (;jsxIdx < jsxCount; ) {
1678
- if (assertFalse(), "string" == typeof jsxValue) {
1679
- expectText(jsxValue);
1680
- } else if ("number" == typeof jsxValue) {
1681
- expectText(String(jsxValue));
1682
- } else if (jsxValue && "object" == typeof jsxValue) {
1683
- if (Array.isArray(jsxValue)) {
1684
- descend(jsxValue, !1);
1685
- } else if (isSignal(jsxValue)) {
1686
- vCurrent && clearAllEffects(container, vCurrent), expectVirtual("S", null), descend(trackSignalAndAssignHost(jsxValue, vNewNode || vCurrent, ".", container), !0);
1687
- } else if (isPromise(jsxValue)) {
1688
- expectVirtual("A", null), asyncQueue.push(jsxValue, vNewNode || vCurrent);
1689
- } else if (isJSXNode(jsxValue)) {
1690
- const type = jsxValue.type;
1691
- "string" == typeof type ? (expectNoMoreTextNodes(), expectElement(jsxValue, type),
1692
- descend(jsxValue.children, !0)) : "function" == typeof type && (type === Fragment ? (expectNoMoreTextNodes(),
1693
- expectVirtual("F", jsxValue.key), descend(jsxValue.children, !0)) : type === Slot ? (expectNoMoreTextNodes(),
1694
- expectSlot() || descend(jsxValue.children, !0)) : type === Projection ? (expectProjection(),
1695
- descend(jsxValue.children, !0)) : type === SSRComment || type === SSRRaw ? expectNoMore() : (expectNoMoreTextNodes(),
1696
- expectComponent(type)));
1696
+ stackPush(jsxNode, !0), !(32 & vParent[0])) {
1697
+ for (;stack.length; ) {
1698
+ for (;jsxIdx < jsxCount; ) {
1699
+ if (assertFalse(), "string" == typeof jsxValue) {
1700
+ expectText(jsxValue);
1701
+ } else if ("number" == typeof jsxValue) {
1702
+ expectText(String(jsxValue));
1703
+ } else if (jsxValue && "object" == typeof jsxValue) {
1704
+ if (Array.isArray(jsxValue)) {
1705
+ descend(jsxValue, !1);
1706
+ } else if (isSignal(jsxValue)) {
1707
+ vCurrent && clearAllEffects(container, vCurrent), expectVirtual("S", null), descend(trackSignalAndAssignHost(jsxValue, vNewNode || vCurrent, ".", container), !0);
1708
+ } else if (isPromise(jsxValue)) {
1709
+ expectVirtual("A", null), asyncQueue.push(jsxValue, vNewNode || vCurrent);
1710
+ } else if (isJSXNode(jsxValue)) {
1711
+ const type = jsxValue.type;
1712
+ "string" == typeof type ? (expectNoMoreTextNodes(), expectElement(jsxValue, type),
1713
+ descend(jsxValue.children, !0)) : "function" == typeof type && (type === Fragment ? (expectNoMoreTextNodes(),
1714
+ expectVirtual("F", jsxValue.key), descend(jsxValue.children, !0)) : type === Slot ? (expectNoMoreTextNodes(),
1715
+ expectSlot() || descend(jsxValue.children, !0)) : type === Projection ? (expectProjection(),
1716
+ descend(jsxValue.children, !0)) : type === SSRComment || type === SSRRaw ? expectNoMore() : (expectNoMoreTextNodes(),
1717
+ expectComponent(type)));
1718
+ }
1719
+ } else {
1720
+ jsxValue === SkipRender ? journal = [] : expectText("");
1697
1721
  }
1698
- } else {
1699
- jsxValue === SkipRender ? journal = [] : expectText("");
1722
+ advance();
1700
1723
  }
1701
- advance();
1724
+ expectNoMore(), ascend();
1702
1725
  }
1703
- expectNoMore(), ascend();
1704
1726
  }
1705
1727
  }
1706
1728
  function advance() {
@@ -1962,8 +1984,12 @@
1962
1984
  let returnValue = !1;
1963
1985
  return qrls.flat(2).forEach(qrl => {
1964
1986
  if (qrl) {
1965
- const value = container.$scheduler$(2, vNode, qrl, [ event, element ]);
1966
- returnValue = returnValue || !0 === value;
1987
+ if (isSyncQrl(qrl)) {
1988
+ qrl(event, element);
1989
+ } else {
1990
+ const value = container.$scheduler$(2, vNode, qrl, [ event, element ]);
1991
+ returnValue = returnValue || !0 === value;
1992
+ }
1967
1993
  }
1968
1994
  }), returnValue;
1969
1995
  }));
@@ -2150,7 +2176,7 @@
2150
2176
  const obj = seq[i];
2151
2177
  if (isTask(obj)) {
2152
2178
  const task = obj;
2153
- clearAllEffects(container, task), 1 & task.$flags$ ? container.$scheduler$(48, task) : cleanupTask(task);
2179
+ clearAllEffects(container, task), 1 & task.$flags$ ? container.$scheduler$(32, task) : cleanupTask(task);
2154
2180
  }
2155
2181
  }
2156
2182
  }
@@ -2176,7 +2202,9 @@
2176
2202
  if (vCursor === vNode) {
2177
2203
  const vFirstChild = vnode_getFirstChild(vCursor);
2178
2204
  if (vFirstChild) {
2179
- return void vnode_walkVNode(vFirstChild);
2205
+ return void vnode_walkVNode(vFirstChild, vNode => {
2206
+ 2 & vNode[0] && vnode_getProp(vNode, "q:sparent", id => vnode_locate(container.rootVNode, id));
2207
+ });
2180
2208
  }
2181
2209
  }
2182
2210
  } else {
@@ -2232,8 +2260,9 @@
2232
2260
  assertQrl(qrl);
2233
2261
  const container = iCtx.$container$;
2234
2262
  const resource = createResourceReturn(container, opts);
2235
- const task = new Task(12, i, iCtx.$hostElement$, qrl, resource, null);
2236
- return container.$scheduler$(3, task), set(resource), resource;
2263
+ const el = iCtx.$hostElement$;
2264
+ const task = new Task(12, i, el, qrl, resource, null);
2265
+ return set(resource), runResource(task, container, el), resource;
2237
2266
  };
2238
2267
  const createResourceReturn = (container, opts, initialPromise) => {
2239
2268
  const result = (opts => ({
@@ -2272,21 +2301,21 @@
2272
2301
  let reject;
2273
2302
  let done = !1;
2274
2303
  const setState = (resolved, value) => !done && (done = !0, resolved ? (done = !0,
2275
- resource.loading = !1, resource._state = "resolved", resource._resolved = value,
2276
- resource._error = void 0, resolve(value)) : (done = !0, resource.loading = !1, resource._state = "rejected",
2277
- resource._error = value, reject(value)), !0);
2304
+ resourceTarget.loading = !1, resourceTarget._state = "resolved", resourceTarget._resolved = value,
2305
+ resourceTarget._error = void 0, resolve(value)) : (done = !0, resourceTarget.loading = !1,
2306
+ resourceTarget._state = "rejected", resourceTarget._error = value, reject(value)),
2307
+ isServerPlatform() || forceStoreEffects(resource, "_state"), !0);
2278
2308
  cleanups.push(() => {
2279
2309
  if (!0 === untrack(() => resource.loading)) {
2280
2310
  const value = untrack(() => resource._resolved);
2281
2311
  setState(!0, value);
2282
2312
  }
2283
2313
  }), invoke(iCtx, () => {
2284
- resource._state = "pending", resource.loading = !isServerPlatform();
2285
- (resource.value = new Promise((r, re) => {
2314
+ resource._state = "pending", resource.loading = !isServerPlatform(), resource.value = new Promise((r, re) => {
2286
2315
  resolve = r, reject = re;
2287
- })).catch(ignoreErrorToPreventNodeFromCrashing);
2316
+ });
2288
2317
  });
2289
- const promise = safeCall(() => Promise.resolve(taskFn(opts)), value => {
2318
+ const promise = safeCall(() => taskFn(opts), value => {
2290
2319
  setState(!0, value);
2291
2320
  }, err => {
2292
2321
  if (isPromise(err)) {
@@ -2299,28 +2328,187 @@
2299
2328
  setState(!1, new Error("timeout")) && cleanupTask(task);
2300
2329
  }) ]) : promise;
2301
2330
  };
2302
- const ignoreErrorToPreventNodeFromCrashing = () => {};
2303
2331
  const aVNodePath = [];
2304
2332
  const bVNodePath = [];
2305
2333
  const aSsrNodePath = [];
2306
2334
  const bSsrNodePath = [];
2307
- const getPromise = chore => chore.$promise$ ||= new Promise(resolve => {
2308
- chore.$resolve$ = resolve;
2309
- });
2310
- const createScheduler = (container, scheduleDrain, journalFlush) => {
2311
- const choreQueue = [];
2312
- const qrlRuns = [];
2313
- let currentChore = null;
2335
+ const VISIBLE_BLOCKING_RULES = [ {
2336
+ blockedType: 16,
2337
+ blockingType: 4,
2338
+ match: (blocked, blocking, container) => isDescendant(blocked, blocking, container) || isDescendant(blocking, blocked, container)
2339
+ }, {
2340
+ blockedType: 16,
2341
+ blockingType: 6,
2342
+ match: (blocked, blocking, container) => isDescendant(blocked, blocking, container) || isDescendant(blocking, blocked, container)
2343
+ } ];
2344
+ const BLOCKING_RULES = [ {
2345
+ blockedType: 2,
2346
+ blockingType: 1,
2347
+ match: (blocked, blocking) => {
2348
+ const blockedQrl = blocked.$target$;
2349
+ const blockingQrl = blocking.$target$;
2350
+ return isSameHost(blocked, blocking) && isSameQrl(blockedQrl, blockingQrl);
2351
+ }
2352
+ }, {
2353
+ blockedType: 3,
2354
+ blockingType: 1,
2355
+ match: (blocked, blocking) => {
2356
+ const blockedTask = blocked.$payload$;
2357
+ const blockingQrl = blocking.$target$;
2358
+ return isSameHost(blocked, blocking) && isSameQrl(blockedTask.$qrl$, blockingQrl);
2359
+ }
2360
+ }, {
2361
+ blockedType: 16,
2362
+ blockingType: 1,
2363
+ match: (blocked, blocking) => {
2364
+ const blockedTask = blocked.$payload$;
2365
+ const blockingQrl = blocking.$target$;
2366
+ return isSameHost(blocked, blocking) && isSameQrl(blockedTask.$qrl$, blockingQrl);
2367
+ }
2368
+ }, {
2369
+ blockedType: 4,
2370
+ blockingType: 6,
2371
+ match: (blocked, blocking) => blocked.$host$ === blocking.$host$
2372
+ }, {
2373
+ blockedType: 5,
2374
+ blockingType: 6,
2375
+ match: (blocked, blocking) => blocked.$host$ === blocking.$host$
2376
+ }, ...VISIBLE_BLOCKING_RULES, {
2377
+ blockedType: 3,
2378
+ blockingType: 3,
2379
+ match: (blocked, blocking, container) => {
2380
+ if (blocked.$host$ !== blocking.$host$) {
2381
+ return !1;
2382
+ }
2383
+ const blockedIdx = blocked.$idx$;
2384
+ if ("number" != typeof blockedIdx || blockedIdx <= 0) {
2385
+ return !1;
2386
+ }
2387
+ const previousTask = function(host, currentTaskIdx, container) {
2388
+ const elementSeq = container.getHostProp(host, "q:seq");
2389
+ if (!elementSeq || elementSeq.length <= currentTaskIdx) {
2390
+ return null;
2391
+ }
2392
+ for (let i = currentTaskIdx - 1; i >= 0; i--) {
2393
+ const candidate = elementSeq[i];
2394
+ if (candidate instanceof Task && 2 & candidate.$flags$) {
2395
+ return candidate;
2396
+ }
2397
+ }
2398
+ return null;
2399
+ }(blocked.$host$, blockedIdx, container);
2400
+ return previousTask === blocking.$payload$;
2401
+ }
2402
+ } ];
2403
+ function isDescendant(descendantChore, ancestorChore, container) {
2404
+ const descendantHost = descendantChore.$host$;
2405
+ const ancestorHost = ancestorChore.$host$;
2406
+ return !(!vnode_isVNode(descendantHost) || !vnode_isVNode(ancestorHost)) && vnode_isDescendantOf(descendantHost, ancestorHost, container.rootVNode);
2407
+ }
2408
+ function isSameHost(a, b) {
2409
+ return a.$host$ === b.$host$;
2410
+ }
2411
+ function isSameQrl(a, b) {
2412
+ return a.$symbol$ === b.$symbol$;
2413
+ }
2414
+ function findBlockingChoreInQueue(chore, choreQueue, container) {
2415
+ for (const candidate of choreQueue) {
2416
+ if (!(candidate.$type$ >= 16 || 3 === candidate.$type$) && isDescendant(chore, candidate, container)) {
2417
+ return candidate;
2418
+ }
2419
+ }
2420
+ return null;
2421
+ }
2422
+ function findBlockingChore(chore, choreQueue, blockedChores, runningChores, container) {
2423
+ const blockingChoreInChoreQueue = findBlockingChoreInQueue(chore, choreQueue, container);
2424
+ if (blockingChoreInChoreQueue) {
2425
+ return blockingChoreInChoreQueue;
2426
+ }
2427
+ const blockingChoreInBlockedChores = findBlockingChoreInQueue(chore, Array.from(blockedChores), container);
2428
+ if (blockingChoreInBlockedChores) {
2429
+ return blockingChoreInBlockedChores;
2430
+ }
2431
+ const blockingChoreInRunningChores = findBlockingChoreInQueue(chore, Array.from(runningChores), container);
2432
+ if (blockingChoreInRunningChores) {
2433
+ return blockingChoreInRunningChores;
2434
+ }
2435
+ for (const rule of BLOCKING_RULES) {
2436
+ if (chore.$type$ === rule.blockedType) {
2437
+ for (const candidate of choreQueue) {
2438
+ if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
2439
+ return candidate;
2440
+ }
2441
+ }
2442
+ for (const candidate of blockedChores) {
2443
+ if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
2444
+ return candidate;
2445
+ }
2446
+ }
2447
+ for (const candidate of runningChores) {
2448
+ if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
2449
+ return candidate;
2450
+ }
2451
+ }
2452
+ }
2453
+ }
2454
+ return null;
2455
+ }
2456
+ function findBlockingChoreForVisible(chore, runningChores, container) {
2457
+ for (const rule of VISIBLE_BLOCKING_RULES) {
2458
+ if (chore.$type$ === rule.blockedType) {
2459
+ for (const candidate of runningChores) {
2460
+ if (candidate.$type$ === rule.blockingType && rule.match(chore, candidate, container)) {
2461
+ return candidate;
2462
+ }
2463
+ }
2464
+ }
2465
+ }
2466
+ return null;
2467
+ }
2468
+ var ChoreState;
2469
+ !function(ChoreState) {
2470
+ ChoreState[ChoreState.NONE = 0] = "NONE", ChoreState[ChoreState.RUNNING = 1] = "RUNNING",
2471
+ ChoreState[ChoreState.FAILED = 2] = "FAILED", ChoreState[ChoreState.DONE = 3] = "DONE";
2472
+ }(ChoreState || (ChoreState = {}));
2473
+ const getChorePromise = chore => chore.$state$ === ChoreState.NONE ? chore.$returnValue$ ||= new Promise((resolve, reject) => {
2474
+ chore.$resolve$ = resolve, chore.$reject$ = reject;
2475
+ }) : chore.$returnValue$;
2476
+ const createScheduler = (container, journalFlush, choreQueue = [], blockedChores = new Set, runningChores = new Set) => {
2477
+ let drainChore = null;
2314
2478
  let drainScheduled = !1;
2315
- return function schedule(type, hostOrTask = null, targetOrQrl = null, payload = null) {
2316
- const isServer = !isDomContainer(container);
2317
- const isComponentSsr = isServer && 6 === type;
2318
- const runLater = 255 !== type && !isComponentSsr && 2 !== type;
2319
- const isTask = 3 === type || 32 === type || 48 === type;
2320
- const isClientOnly = 16 === type || 4 === type || 5 === type || 1 === type || 7 === type;
2321
- if (isServer && isClientOnly) {
2322
- return;
2479
+ let isDraining = !1;
2480
+ let isJournalFlushRunning = !1;
2481
+ let flushBudgetStart = 0;
2482
+ let currentTime = performance.now();
2483
+ const nextTick = (fn => {
2484
+ let nextTick;
2485
+ if ("function" == typeof setImmediate) {
2486
+ nextTick = () => {
2487
+ setImmediate(fn);
2488
+ };
2489
+ } else if ("undefined" != typeof MessageChannel) {
2490
+ const channel = new MessageChannel;
2491
+ channel.port1.onmessage = () => {
2492
+ fn();
2493
+ }, nextTick = () => {
2494
+ channel.port2.postMessage(null);
2495
+ };
2496
+ } else {
2497
+ nextTick = () => {
2498
+ setTimeout(fn);
2499
+ };
2500
+ }
2501
+ return nextTick;
2502
+ })(drainChoreQueue);
2503
+ function drainInNextTick() {
2504
+ drainScheduled || (drainScheduled = !0, nextTick());
2505
+ }
2506
+ const FREQUENCY_MS = Math.floor(1e3 / 60);
2507
+ return function(type, hostOrTask = null, targetOrQrl = null, payload = null) {
2508
+ if (255 === type && drainChore) {
2509
+ return drainChore;
2323
2510
  }
2511
+ const isTask = 3 === type || 16 === type || 32 === type;
2324
2512
  isTask && (hostOrTask.$flags$ |= 8);
2325
2513
  let chore = {
2326
2514
  $type$: type,
@@ -2328,184 +2516,217 @@
2328
2516
  $host$: isTask ? hostOrTask.$el$ : hostOrTask,
2329
2517
  $target$: targetOrQrl,
2330
2518
  $payload$: isTask ? hostOrTask : payload,
2331
- $resolve$: null,
2332
- $promise$: null,
2333
- $returnValue$: null,
2334
- $executed$: !1
2519
+ $state$: ChoreState.NONE,
2520
+ $blockedChores$: null,
2521
+ $startTime$: void 0,
2522
+ $endTime$: void 0,
2523
+ $resolve$: void 0,
2524
+ $reject$: void 0,
2525
+ $returnValue$: null
2335
2526
  };
2336
- chore = function(sortedArray, value, rootVNode) {
2337
- const idx = function(sortedArray, value, rootVNode) {
2338
- let bottom = 0;
2339
- let top = sortedArray.length;
2340
- for (;bottom < top; ) {
2341
- const middle = bottom + (top - bottom >> 1);
2342
- const comp = choreComparator(value, sortedArray[middle], rootVNode);
2343
- if (comp < 0) {
2344
- top = middle;
2345
- } else {
2346
- if (!(comp > 0)) {
2347
- return middle;
2348
- }
2349
- bottom = middle + 1;
2350
- }
2351
- }
2352
- return ~bottom;
2353
- }(sortedArray, value, rootVNode);
2354
- if (idx < 0) {
2355
- return sortedArray.splice(~idx, 0, value), value;
2527
+ if (255 === type) {
2528
+ return getChorePromise(chore), drainChore = chore, drainInNextTick(), chore;
2529
+ }
2530
+ const isServer = isServerPlatform();
2531
+ const isClientOnly = 4 === type || 1 === type;
2532
+ if (isServer && isClientOnly) {
2533
+ return finishChore(chore, void 0), chore;
2534
+ }
2535
+ if (isServer && chore.$host$ && isSsrNode(chore.$host$)) {
2536
+ if (!!!(1 & chore.$host$.flags) && 5 !== chore.$type$ && 7 !== chore.$type$) {
2537
+ const warningMessage = `A '${choreTypeToName(chore.$type$)}' chore was scheduled on a host element that has already been streamed to the client.\nThis can lead to inconsistencies between Server-Side Rendering (SSR) and Client-Side Rendering (CSR).\n\nProblematic chore:\n - Type: ${choreTypeToName(chore.$type$)}\n - Host: ${chore.$host$.toString()}\n - Nearest element location: ${chore.$host$.currentFile}\n\nThis is often caused by modifying a signal in an already rendered component during SSR.`;
2538
+ return logWarn(warningMessage), chore;
2356
2539
  }
2357
- const existing = sortedArray[idx];
2358
- existing.$payload$ !== value.$payload$ && (existing.$payload$ = value.$payload$);
2359
- existing.$executed$ && (existing.$executed$ = !1);
2360
- return existing;
2361
- }(choreQueue, chore, container.rootVNode || null), !drainScheduled && runLater && (drainScheduled = !0,
2362
- schedule(16), scheduleDrain()?.catch?.(() => {}));
2363
- return runLater ? getPromise(chore) : drainUpTo(chore, isServer);
2540
+ }
2541
+ const blockingChore = findBlockingChore(chore, choreQueue, blockedChores, runningChores, container);
2542
+ if (blockingChore) {
2543
+ return addBlockedChore(chore, blockingChore, blockedChores), chore;
2544
+ }
2545
+ chore = sortedInsert(choreQueue, chore, container.rootVNode || null);
2546
+ (isServer && 6 === type || 2 === type) && !isDraining ? (drainScheduled = !0, drainChoreQueue()) : drainInNextTick();
2547
+ return chore;
2364
2548
  };
2365
- function drainUpTo(runUptoChore, isServer) {
2366
- let maxRetries = 5e3;
2367
- for (;choreQueue.length; ) {
2368
- if (maxRetries-- < 0) {
2369
- throw new Error("drainUpTo: max retries reached");
2370
- }
2371
- if (currentChore) {
2372
- return getPromise(currentChore).then(() => drainUpTo(runUptoChore, isServer)).catch(e => {
2373
- container.handleError(e, currentChore?.$host$);
2374
- });
2549
+ function applyJournalFlush() {
2550
+ isJournalFlushRunning || (isJournalFlushRunning = !0, journalFlush(), isJournalFlushRunning = !1,
2551
+ flushBudgetStart = performance.now());
2552
+ }
2553
+ function shouldApplyJournalFlush(isServer) {
2554
+ return !isServer && currentTime - flushBudgetStart >= FREQUENCY_MS;
2555
+ }
2556
+ function drainChoreQueue() {
2557
+ const isServer = isServerPlatform();
2558
+ if (drainScheduled = !1, isDraining) {
2559
+ return;
2560
+ }
2561
+ if (!choreQueue.length) {
2562
+ return applyJournalFlush(), void (drainChore && !runningChores.size && (drainChore.$resolve$(null),
2563
+ drainChore = null));
2564
+ }
2565
+ isDraining = !0, flushBudgetStart = performance.now();
2566
+ const maybeFinishDrain = () => choreQueue.length ? (drainInNextTick(), !1) : drainChore && runningChores.size ? (shouldApplyJournalFlush(isServer) && applyJournalFlush(),
2567
+ !1) : (currentChore = null, applyJournalFlush(), drainChore?.$resolve$(null), drainChore = null,
2568
+ !0);
2569
+ const scheduleBlockedChoresAndDrainIfNeeded = chore => {
2570
+ let blockedChoresScheduled = !1;
2571
+ if (chore.$blockedChores$) {
2572
+ for (const blockedChore of chore.$blockedChores$) {
2573
+ const blockingChore = findBlockingChore(blockedChore, choreQueue, blockedChores, runningChores, container);
2574
+ blockingChore ? addBlockedChore(blockedChore, blockingChore, blockedChores) : (blockedChores.delete(blockedChore),
2575
+ sortedInsert(choreQueue, blockedChore, container.rootVNode || null), blockedChoresScheduled = !0);
2576
+ }
2577
+ chore.$blockedChores$ = null;
2375
2578
  }
2376
- const nextChore = choreQueue[0];
2377
- if (nextChore.$executed$) {
2378
- if (choreQueue.shift(), nextChore === runUptoChore) {
2379
- break;
2579
+ blockedChoresScheduled && !isDraining && drainInNextTick();
2580
+ };
2581
+ let currentChore = null;
2582
+ try {
2583
+ for (;choreQueue.length; ) {
2584
+ currentTime = performance.now();
2585
+ const chore = currentChore = choreQueue.shift();
2586
+ if (chore.$state$ !== ChoreState.NONE) {
2587
+ continue;
2588
+ }
2589
+ if (vNodeAlreadyDeleted(chore) && 32 !== chore.$type$) {
2590
+ continue;
2591
+ }
2592
+ if (16 === chore.$type$) {
2593
+ applyJournalFlush();
2594
+ const blockingChore = findBlockingChoreForVisible(chore, runningChores, container);
2595
+ if (blockingChore && blockingChore.$state$ === ChoreState.RUNNING) {
2596
+ addBlockedChore(chore, blockingChore, blockedChores);
2597
+ continue;
2598
+ }
2599
+ }
2600
+ chore.$startTime$ = performance.now();
2601
+ const result = executeChore(chore, isServer);
2602
+ if (chore.$returnValue$ = result, isPromise(result) ? (runningChores.add(chore),
2603
+ chore.$state$ = ChoreState.RUNNING, result.then(value => {
2604
+ finishChore(chore, value);
2605
+ }).catch(e => {
2606
+ chore.$state$ === ChoreState.RUNNING && handleError(chore, e);
2607
+ }).finally(() => {
2608
+ if (runningChores.delete(chore), scheduleBlockedChoresAndDrainIfNeeded(chore), !runningChores.size) {
2609
+ let finished = !1;
2610
+ drainChore && (finished = maybeFinishDrain()), finished || isDraining || applyJournalFlush();
2611
+ }
2612
+ })) : (finishChore(chore, result), scheduleBlockedChoresAndDrainIfNeeded(chore)),
2613
+ shouldApplyJournalFlush(isServer)) {
2614
+ return applyJournalFlush(), void drainInNextTick();
2380
2615
  }
2381
- } else {
2382
- vNodeAlreadyDeleted(nextChore) && 48 !== nextChore.$type$ ? choreQueue.shift() : executeChore(nextChore, isServer);
2383
2616
  }
2617
+ } catch (e) {
2618
+ handleError(currentChore, e), scheduleBlockedChoresAndDrainIfNeeded(currentChore);
2619
+ } finally {
2620
+ isDraining = !1, maybeFinishDrain();
2384
2621
  }
2385
- return runUptoChore.$returnValue$;
2622
+ }
2623
+ function finishChore(chore, value) {
2624
+ chore.$endTime$ = performance.now(), chore.$state$ = ChoreState.DONE, chore.$returnValue$ = value,
2625
+ chore.$resolve$?.(value);
2626
+ }
2627
+ function handleError(chore, e) {
2628
+ chore.$endTime$ = performance.now(), chore.$state$ = ChoreState.FAILED, chore.$reject$?.(e),
2629
+ container.handleError(e, chore.$host$);
2386
2630
  }
2387
2631
  function executeChore(chore, isServer) {
2388
2632
  const host = chore.$host$;
2389
- assertEqual(), currentChore = chore;
2390
- let returnValue = null;
2391
- try {
2392
- switch (chore.$type$) {
2393
- case 255:
2394
- isServer && (drainScheduled = !1);
2395
- break;
2396
-
2397
- case 16:
2398
- returnValue = journalFlush(), drainScheduled = !1;
2399
- break;
2400
-
2401
- case 6:
2402
- returnValue = safeCall(() => executeComponent(container, host, host, chore.$target$, chore.$payload$), jsx => {
2403
- if (isServer) {
2404
- return jsx;
2405
- }
2406
- {
2407
- const styleScopedId = container.getHostProp(host, "q:sstyle");
2408
- return retryOnPromise(() => vnode_diff(container, jsx, host, addComponentStylePrefix(styleScopedId)));
2409
- }
2410
- }, err => container.handleError(err, host));
2411
- break;
2412
-
2413
- case 2:
2414
- {
2415
- const fn = chore.$target$.getFn();
2416
- const result = retryOnPromise(() => fn(...chore.$payload$));
2417
- if (isPromise(result)) {
2418
- const handled = result.finally(() => {
2419
- qrlRuns.splice(qrlRuns.indexOf(handled), 1);
2420
- }).catch(error => {
2421
- container.handleError(error, chore.$host$);
2422
- });
2423
- return qrlRuns.push(handled), chore.$returnValue$ = handled, chore.$resolve$?.(handled),
2424
- currentChore = null, void (chore.$executed$ = !0);
2425
- }
2426
- returnValue = null;
2633
+ let returnValue;
2634
+ switch (chore.$type$) {
2635
+ case 6:
2636
+ returnValue = safeCall(() => executeComponent(container, host, host, chore.$target$, chore.$payload$), jsx => {
2637
+ if (isServer) {
2638
+ return jsx;
2427
2639
  }
2428
- break;
2429
-
2430
- case 3:
2431
- case 32:
2432
2640
  {
2433
- const payload = chore.$payload$;
2434
- if (4 & payload.$flags$) {
2435
- const result = runResource(payload, container, host);
2436
- returnValue = isServer ? result : null;
2437
- } else {
2438
- returnValue = runTask(payload, container, host);
2439
- }
2641
+ const styleScopedId = container.getHostProp(host, "q:sstyle");
2642
+ return retryOnPromise(() => vnode_diff(container, jsx, host, addComponentStylePrefix(styleScopedId)));
2440
2643
  }
2441
- break;
2644
+ }, err => {
2645
+ handleError(chore, err);
2646
+ });
2647
+ break;
2442
2648
 
2443
- case 48:
2444
- cleanupTask(chore.$payload$);
2445
- break;
2649
+ case 2:
2650
+ {
2651
+ const fn = chore.$target$.getFn();
2652
+ returnValue = retryOnPromise(() => fn(...chore.$payload$));
2653
+ }
2654
+ break;
2446
2655
 
2447
- case 4:
2448
- {
2449
- const parentVirtualNode = chore.$target$;
2450
- let jsx = chore.$payload$;
2451
- isSignal(jsx) && (jsx = jsx.value), returnValue = retryOnPromise(() => vnode_diff(container, jsx, parentVirtualNode, null));
2452
- }
2453
- break;
2656
+ case 3:
2657
+ case 16:
2658
+ {
2659
+ const payload = chore.$payload$;
2660
+ returnValue = 4 & payload.$flags$ ? runResource(payload, container, host) : runTask(payload, container, host);
2661
+ }
2662
+ break;
2454
2663
 
2455
- case 5:
2456
- {
2457
- const virtualNode = chore.$host$;
2458
- const payload = chore.$payload$;
2459
- let value = payload.$value$;
2460
- isSignal(value) && (value = value.value);
2461
- const isConst = payload.$isConst$;
2462
- const journal = container.$journal$;
2463
- const property = chore.$idx$;
2464
- const serializedValue = serializeAttribute(property, value, payload.$scopedStyleIdPrefix$);
2664
+ case 32:
2665
+ cleanupTask(chore.$payload$);
2666
+ break;
2667
+
2668
+ case 4:
2669
+ {
2670
+ const parentVirtualNode = chore.$target$;
2671
+ let jsx = chore.$payload$;
2672
+ isSignal(jsx) && (jsx = jsx.value), returnValue = retryOnPromise(() => vnode_diff(container, jsx, parentVirtualNode, null));
2673
+ }
2674
+ break;
2675
+
2676
+ case 5:
2677
+ {
2678
+ const virtualNode = chore.$host$;
2679
+ const payload = chore.$payload$;
2680
+ let value = payload.$value$;
2681
+ isSignal(value) && (value = value.value);
2682
+ const isConst = payload.$isConst$;
2683
+ const journal = container.$journal$;
2684
+ const property = chore.$idx$;
2685
+ const serializedValue = serializeAttribute(property, value, payload.$scopedStyleIdPrefix$);
2686
+ if (isServer) {
2687
+ container.addBackpatchEntry(chore.$host$.id, property, serializedValue), returnValue = null;
2688
+ } else {
2465
2689
  if (isConst) {
2466
2690
  journal.push(2, virtualNode[6], property, serializedValue);
2467
2691
  } else {
2468
2692
  vnode_setAttr(journal, virtualNode, property, serializedValue);
2469
2693
  }
2694
+ returnValue = void 0;
2470
2695
  }
2471
- break;
2696
+ }
2697
+ break;
2472
2698
 
2473
- case 1:
2474
- {
2475
- const target = chore.$target$;
2476
- returnValue = target.resolved ? null : target.resolve();
2477
- }
2478
- break;
2699
+ case 1:
2700
+ {
2701
+ const target = chore.$target$;
2702
+ returnValue = target.resolved ? null : target.resolve();
2703
+ }
2704
+ break;
2479
2705
 
2480
- case 7:
2481
- {
2482
- const target = chore.$target$;
2483
- const effects = chore.$payload$;
2706
+ case 7:
2707
+ {
2708
+ const target = chore.$target$;
2709
+ const effects = chore.$payload$;
2710
+ if (!effects?.size) {
2711
+ break;
2712
+ }
2713
+ let shouldCompute = target instanceof ComputedSignalImpl || target instanceof WrappedSignalImpl;
2714
+ if (target instanceof AsyncComputedSignalImpl && effects !== target.$effects$ && (shouldCompute = !1),
2715
+ shouldCompute) {
2484
2716
  const ctx = newInvokeContext();
2485
- if (ctx.$container$ = container, target instanceof ComputedSignalImpl || target instanceof WrappedSignalImpl) {
2486
- const forceRunEffects = target.$forceRunEffects$;
2487
- if (target.$forceRunEffects$ = !1, !effects?.size && !forceRunEffects) {
2488
- break;
2717
+ ctx.$container$ = container, returnValue = maybeThen(retryOnPromise(() => invoke.call(target, ctx, target.$computeIfNeeded$)), () => {
2718
+ if (2 & target.$flags$) {
2719
+ return target.$flags$ &= -3, retryOnPromise(() => triggerEffects(container, target, effects));
2489
2720
  }
2490
- returnValue = maybeThen(retryOnPromise(() => invoke.call(target, ctx, target.$computeIfNeeded$)), didChange => {
2491
- if (didChange || forceRunEffects) {
2492
- return retryOnPromise(() => triggerEffects(container, target, effects));
2493
- }
2494
- });
2495
- } else {
2496
- returnValue = retryOnPromise(() => triggerEffects(container, target, effects));
2497
- }
2721
+ });
2722
+ } else {
2723
+ returnValue = retryOnPromise(() => {
2724
+ triggerEffects(container, target, effects);
2725
+ });
2498
2726
  }
2499
2727
  }
2500
- } catch (e) {
2501
- returnValue = Promise.reject(e);
2502
2728
  }
2503
- const after = (value, error) => {
2504
- currentChore = null, chore.$executed$ = !0, error ? container.handleError(error, host) : (chore.$returnValue$ = value,
2505
- chore.$resolve$?.(value));
2506
- };
2507
- isPromise(returnValue) ? (chore.$promise$ = returnValue.then(after, error => after(void 0, error)),
2508
- chore.$resolve$?.(chore.$promise$), chore.$resolve$ = void 0) : after(returnValue);
2729
+ return returnValue;
2509
2730
  }
2510
2731
  function choreComparator(a, b, rootVNode) {
2511
2732
  const macroTypeDiff = (240 & a.$type$) - (240 & b.$type$);
@@ -2553,8 +2774,6 @@
2553
2774
  }
2554
2775
  } else {
2555
2776
  assertFalse(vnode_isVNode(aHost)), assertFalse(vnode_isVNode(bHost));
2556
- const errorMessage = `SERVER: during HTML streaming, re-running tasks on a different host is not allowed.\n You are attempting to change a state that has already been streamed to the client.\n This can lead to inconsistencies between Server-Side Rendering (SSR) and Client-Side Rendering (CSR).\n Problematic Node: ${aHost.toString()}`;
2557
- logWarn(errorMessage);
2558
2777
  const hostDiff = ((a, b) => {
2559
2778
  if (a === b) {
2560
2779
  return 0;
@@ -2562,10 +2781,10 @@
2562
2781
  let aDepth = -1;
2563
2782
  let bDepth = -1;
2564
2783
  for (;a; ) {
2565
- a = (aSsrNodePath[++aDepth] = a).parentSsrNode;
2784
+ a = (aSsrNodePath[++aDepth] = a).parentComponent;
2566
2785
  }
2567
2786
  for (;b; ) {
2568
- b = (bSsrNodePath[++bDepth] = b).parentSsrNode;
2787
+ b = (bSsrNodePath[++bDepth] = b).parentComponent;
2569
2788
  }
2570
2789
  for (;aDepth >= 0 && bDepth >= 0; ) {
2571
2790
  if ((a = aSsrNodePath[aDepth]) !== (b = bSsrNodePath[bDepth])) {
@@ -2585,13 +2804,63 @@
2585
2804
  return microTypeDiff;
2586
2805
  }
2587
2806
  const idxDiff = toNumber(a.$idx$) - toNumber(b.$idx$);
2588
- return 0 !== idxDiff ? idxDiff : a.$target$ !== b.$target$ ? isQrl(a.$target$) && isQrl(b.$target$) && a.$target$.$hash$ === b.$target$.$hash$ ? 0 : 1 : b === currentChore ? 1 : 0;
2807
+ return 0 !== idxDiff ? idxDiff : a.$target$ !== b.$target$ ? isQrl(a.$target$) && isQrl(b.$target$) && a.$target$.$hash$ === b.$target$.$hash$ ? 0 : 1 : 7 === a.$type$ && 7 === b.$type$ && (a.$target$ instanceof StoreHandler && b.$target$ instanceof StoreHandler || a.$target$ instanceof AsyncComputedSignalImpl && b.$target$ instanceof AsyncComputedSignalImpl) && a.$payload$ !== b.$payload$ ? 1 : 0;
2808
+ }
2809
+ function sortedInsert(sortedArray, value, rootVNode) {
2810
+ const idx = function(sortedArray, value, rootVNode) {
2811
+ let bottom = 0;
2812
+ let top = sortedArray.length;
2813
+ for (;bottom < top; ) {
2814
+ const middle = bottom + (top - bottom >> 1);
2815
+ const comp = choreComparator(value, sortedArray[middle], rootVNode);
2816
+ if (comp < 0) {
2817
+ top = middle;
2818
+ } else {
2819
+ if (!(comp > 0)) {
2820
+ return middle;
2821
+ }
2822
+ bottom = middle + 1;
2823
+ }
2824
+ }
2825
+ return ~bottom;
2826
+ }(sortedArray, value, rootVNode);
2827
+ if (idx < 0 && runningChores.size) {
2828
+ for (const chore of runningChores) {
2829
+ if (0 === choreComparator(value, chore, rootVNode)) {
2830
+ return chore;
2831
+ }
2832
+ }
2833
+ }
2834
+ if (idx < 0) {
2835
+ return sortedArray.splice(~idx, 0, value), value;
2836
+ }
2837
+ const existing = sortedArray[idx];
2838
+ return existing.$payload$ !== value.$payload$ && (existing.$payload$ = value.$payload$),
2839
+ existing;
2589
2840
  }
2590
2841
  };
2591
2842
  const toNumber = value => "number" == typeof value ? value : -1;
2592
2843
  function vNodeAlreadyDeleted(chore) {
2593
2844
  return !!(chore.$host$ && vnode_isVNode(chore.$host$) && 32 & chore.$host$[0]);
2594
2845
  }
2846
+ function addBlockedChore(blockedChore, blockingChore, blockedChores) {
2847
+ blockingChore.$blockedChores$ ||= [], blockingChore.$blockedChores$.push(blockedChore),
2848
+ blockedChores.add(blockedChore);
2849
+ }
2850
+ function choreTypeToName(type) {
2851
+ return {
2852
+ 1: "Resolve QRL",
2853
+ 2: "Run QRL",
2854
+ 3: "Task",
2855
+ 4: "Changes diffing",
2856
+ 5: "Updating node property",
2857
+ 6: "Component",
2858
+ 7: "Signal recompute",
2859
+ 16: "Visible",
2860
+ 32: "Cleanup visible",
2861
+ 255: "Wait for queue"
2862
+ }[type] || "Unknown: " + type;
2863
+ }
2595
2864
  class _SharedContainer {
2596
2865
  $version$;
2597
2866
  $scheduler$;
@@ -2602,11 +2871,12 @@
2602
2871
  $currentUniqueId$=0;
2603
2872
  $instanceHash$=null;
2604
2873
  $buildBase$=null;
2605
- constructor(scheduleDrain, journalFlush, serverData, locale) {
2874
+ $flushEpoch$=0;
2875
+ constructor(journalFlush, serverData, locale) {
2606
2876
  this.$serverData$ = serverData, this.$locale$ = locale, this.$version$ = version,
2607
2877
  this.$storeProxyMap$ = new WeakMap, this.$getObjectById$ = () => {
2608
2878
  throw Error("Not implemented");
2609
- }, this.$scheduler$ = createScheduler(this, scheduleDrain, journalFlush);
2879
+ }, this.$scheduler$ = createScheduler(this, journalFlush);
2610
2880
  }
2611
2881
  trackSignalValue(signal, subscriber, property, data) {
2612
2882
  return trackSignalAndAssignHost(signal, subscriber, property, this, data);
@@ -2629,9 +2899,8 @@
2629
2899
  return container || (container = new DomContainer(qContainerElement)), container;
2630
2900
  }
2631
2901
  function _getQContainerElement(element) {
2632
- return (Array.isArray(element) ? vnode_getDomParent(element) : element).closest("[q\\:container]:not([q\\:container=html]):not([q\\:container=text])");
2902
+ return (Array.isArray(element) ? vnode_getDomParent(element, !0) : element).closest("[q\\:container]:not([q\\:container=html]):not([q\\:container=text])");
2633
2903
  }
2634
- const isDomContainer = container => container instanceof DomContainer;
2635
2904
  class DomContainer extends _SharedContainer {
2636
2905
  element;
2637
2906
  qContainer;
@@ -2639,7 +2908,6 @@
2639
2908
  rootVNode;
2640
2909
  document;
2641
2910
  $journal$;
2642
- renderDone=null;
2643
2911
  $rawStateData$;
2644
2912
  $storeProxyMap$=new WeakMap;
2645
2913
  $qFuncs$;
@@ -2649,10 +2917,11 @@
2649
2917
  vNodeLocate=id => vnode_locate(this.rootVNode, id);
2650
2918
  $stateData$;
2651
2919
  $styleIds$=null;
2652
- $renderCount$=0;
2653
2920
  constructor(element) {
2654
- if (super(() => this.scheduleRender(), () => vnode_applyJournal(this.$journal$), {}, element.getAttribute("q:locale")),
2655
- this.qContainer = element.getAttribute("q:container"), !this.qContainer) {
2921
+ if (super(() => {
2922
+ this.$flushEpoch$++, vnode_applyJournal(this.$journal$);
2923
+ }, {}, element.getAttribute("q:locale")), this.qContainer = element.getAttribute("q:container"),
2924
+ !this.qContainer) {
2656
2925
  throw qError(25);
2657
2926
  }
2658
2927
  this.$journal$ = [ 3, element.ownerDocument ], this.document = element.ownerDocument,
@@ -2789,7 +3058,10 @@
2789
3058
  nextNode = nextSibling(node);
2790
3059
  const shadowRootContainer = node;
2791
3060
  const shadowRoot = shadowRootContainer?.shadowRoot;
2792
- shadowRoot && walkContainer(document.createTreeWalker(shadowRoot, 129), null, firstChild(shadowRoot), null, "", null);
3061
+ if (shadowRoot) {
3062
+ const firstShadowRootChild = firstChild(shadowRoot);
3063
+ walkContainer(document.createTreeWalker(firstShadowRootChild, 129), null, firstShadowRootChild, null, "", null);
3064
+ }
2793
3065
  }
2794
3066
  if (!(2 & ~nodeType)) {
2795
3067
  if (vNodeElementIndex < elementIdx && (-1 === vNodeElementIndex && (vNodeElementIndex = 0),
@@ -2878,26 +3150,6 @@
2878
3150
  }
2879
3151
  return vnode_getProp(vNode, name, getObjectById);
2880
3152
  }
2881
- scheduleRender() {
2882
- return this.$renderCount$++, this.renderDone ||= getPlatform().nextTick(() => this.processChores()),
2883
- this.renderDone.finally(() => emitEvent("qrender", {
2884
- instanceHash: this.$instanceHash$,
2885
- renderCount: this.$renderCount$
2886
- }));
2887
- }
2888
- processChores() {
2889
- let renderCount = this.$renderCount$;
2890
- const result = this.$scheduler$(255);
2891
- if (isPromise(result)) {
2892
- return result.then(async () => {
2893
- for (;renderCount !== this.$renderCount$; ) {
2894
- renderCount = this.$renderCount$, await this.$scheduler$(255);
2895
- }
2896
- this.renderDone = null;
2897
- });
2898
- }
2899
- renderCount === this.$renderCount$ ? this.renderDone = null : this.processChores();
2900
- }
2901
3153
  ensureProjectionResolved(vNode) {
2902
3154
  if (!(16 & vNode[0])) {
2903
3155
  vNode[0] |= 16;
@@ -2905,7 +3157,10 @@
2905
3157
  for (let i = 0; i < props.length; i += 2) {
2906
3158
  if (isSlotProp(props[i])) {
2907
3159
  const value = props[i + 1];
2908
- "string" == typeof value && (props[i + 1] = this.vNodeLocate(value));
3160
+ if ("string" == typeof value) {
3161
+ const projection = this.vNodeLocate(value);
3162
+ props[i + 1] = projection, vnode_getProp(projection, "q:sparent", id => this.vNodeLocate(id));
3163
+ }
2909
3164
  }
2910
3165
  }
2911
3166
  }
@@ -2969,7 +3224,7 @@
2969
3224
  array[2] ||= new Set, array[2].add(value);
2970
3225
  };
2971
3226
  const addQrlToSerializationCtx = (effectSubscriber, container) => {
2972
- if (container && !isDomContainer(container)) {
3227
+ if (container && !(container => container instanceof DomContainer)(container)) {
2973
3228
  const effect = effectSubscriber[0];
2974
3229
  const property = effectSubscriber[1];
2975
3230
  let qrl = null;
@@ -2978,7 +3233,7 @@
2978
3233
  }
2979
3234
  };
2980
3235
  const triggerEffects = (container, signal, effects) => {
2981
- const isBrowser = isDomContainer(container);
3236
+ const isBrowser = !isServerPlatform();
2982
3237
  if (effects) {
2983
3238
  const scheduleEffect = effectSubscription => {
2984
3239
  const consumer = effectSubscription[0];
@@ -2986,7 +3241,7 @@
2986
3241
  if (assertDefined(), isTask(consumer)) {
2987
3242
  consumer.$flags$ |= 8;
2988
3243
  let choreType = 3;
2989
- 1 & consumer.$flags$ && (choreType = 32), container.$scheduler$(choreType, consumer);
3244
+ 1 & consumer.$flags$ && (choreType = 16), container.$scheduler$(choreType, consumer);
2990
3245
  } else if (consumer instanceof SignalImpl) {
2991
3246
  consumer instanceof ComputedSignalImpl && (consumer.$computeQrl$.resolved || container.$scheduler$(1, null, consumer.$computeQrl$)),
2992
3247
  consumer.invalidate();
@@ -2996,18 +3251,18 @@
2996
3251
  assertDefined();
2997
3252
  const props = container.getHostProp(host, "q:props");
2998
3253
  container.$scheduler$(6, host, qrl, props);
2999
- } else if (isBrowser) {
3000
- if ("." === property) {
3254
+ } else if ("." === property) {
3255
+ if (isBrowser) {
3001
3256
  container.$scheduler$(4, consumer, consumer, signal);
3002
- } else {
3003
- const effectData = effectSubscription[3];
3004
- if (effectData instanceof SubscriptionData) {
3005
- const payload = {
3006
- ...effectData.data,
3007
- $value$: signal
3008
- };
3009
- container.$scheduler$(5, consumer, property, payload);
3010
- }
3257
+ }
3258
+ } else {
3259
+ const effectData = effectSubscription[3];
3260
+ if (effectData instanceof SubscriptionData) {
3261
+ const payload = {
3262
+ ...effectData.data,
3263
+ $value$: signal
3264
+ };
3265
+ container.$scheduler$(5, consumer, property, payload);
3011
3266
  }
3012
3267
  }
3013
3268
  };
@@ -3020,11 +3275,11 @@
3020
3275
  let flags = 1;
3021
3276
  switch (serializationStrategy) {
3022
3277
  case "never":
3023
- flags |= 8;
3278
+ flags |= 16;
3024
3279
  break;
3025
3280
 
3026
3281
  case "always":
3027
- flags |= 16;
3282
+ flags |= 32;
3028
3283
  }
3029
3284
  return flags;
3030
3285
  };
@@ -3179,13 +3434,16 @@
3179
3434
  }
3180
3435
  }
3181
3436
  };
3182
- function vnode_walkVNode(vNode) {
3437
+ function vnode_walkVNode(vNode, callback) {
3183
3438
  let vCursor = vNode;
3184
3439
  if (vnode_isTextVNode(vNode)) {
3185
3440
  return;
3186
3441
  }
3187
3442
  let vParent = null;
3188
3443
  for (;;) {
3444
+ if (callback?.(vCursor, vParent)) {
3445
+ return;
3446
+ }
3189
3447
  const vFirstChild = vnode_getFirstChild(vCursor);
3190
3448
  if (vFirstChild) {
3191
3449
  vCursor = vFirstChild;
@@ -3277,6 +3535,7 @@
3277
3535
  const textVNode = ensureTextVNode(vnode);
3278
3536
  if (!(8 & textVNode[0])) {
3279
3537
  const parentNode = vnode_getDomParent(vnode);
3538
+ assertDefined();
3280
3539
  const sharedTextNode = textVNode[4];
3281
3540
  const doc = parentNode.ownerDocument;
3282
3541
  let cursor = vnode_getDomSibling(vnode, !1, !0);
@@ -3442,7 +3701,7 @@
3442
3701
  }
3443
3702
  insertBefore = null;
3444
3703
  }
3445
- const domParentVNode = vnode_getDomParentVNode(parent);
3704
+ const domParentVNode = vnode_getDomParentVNode(parent, !1);
3446
3705
  const parentNode = domParentVNode && domParentVNode[6];
3447
3706
  let domChildren = null;
3448
3707
  domParentVNode && (domChildren = function(journal, domParentVNode, newChild) {
@@ -3468,27 +3727,30 @@
3468
3727
  }
3469
3728
  return domChildren;
3470
3729
  }(journal, domParentVNode, newChild)), newChildCurrentParent && (newChild[2] || newChild[3] || newChildCurrentParent !== parent) && vnode_remove(journal, newChildCurrentParent, newChild, !1);
3471
- let adjustedInsertBefore = null;
3472
- null == insertBefore ? vnode_isVirtualVNode(parent) && (adjustedInsertBefore = vnode_getDomSibling(parent, !0, !1)) : adjustedInsertBefore = vnode_isVirtualVNode(insertBefore) ? vnode_getDomSibling(insertBefore, !0, !0) : insertBefore,
3473
- adjustedInsertBefore && ((journal, vNode) => {
3474
- vnode_isTextVNode(vNode) && vnode_ensureTextInflated(journal, vNode);
3475
- })(journal, adjustedInsertBefore), domChildren && domChildren.length && journal.push(5, parentNode, vnode_getNode(adjustedInsertBefore), ...domChildren);
3730
+ const parentIsDeleted = 32 & parent[0];
3731
+ if (!parentIsDeleted) {
3732
+ let adjustedInsertBefore = null;
3733
+ null == insertBefore ? vnode_isVirtualVNode(parent) && (adjustedInsertBefore = vnode_getDomSibling(parent, !0, !1)) : adjustedInsertBefore = vnode_isVirtualVNode(insertBefore) ? vnode_getDomSibling(insertBefore, !0, !0) : insertBefore,
3734
+ adjustedInsertBefore && ((journal, vNode) => {
3735
+ vnode_isTextVNode(vNode) && vnode_ensureTextInflated(journal, vNode);
3736
+ })(journal, adjustedInsertBefore), domChildren && domChildren.length && journal.push(5, parentNode, vnode_getNode(adjustedInsertBefore), ...domChildren);
3737
+ }
3476
3738
  const vNext = insertBefore;
3477
3739
  const vPrevious = vNext ? vNext[2] : parent[5];
3478
3740
  vNext ? vNext[2] = newChild : parent[5] = newChild, vPrevious ? vPrevious[3] = newChild : parent[4] = newChild,
3479
- newChild[2] = vPrevious, newChild[3] = vNext, newChild[1] = parent;
3741
+ newChild[2] = vPrevious, newChild[3] = vNext, newChild[1] = parent, parentIsDeleted && (newChild[0] |= 32);
3480
3742
  };
3481
- const vnode_getDomParent = vnode => (vnode = vnode_getDomParentVNode(vnode)) && vnode[6];
3482
- const vnode_getDomParentVNode = vnode => {
3743
+ const vnode_getDomParent = (vnode, includeProjection = !0) => (vnode = vnode_getDomParentVNode(vnode, includeProjection)) && vnode[6];
3744
+ const vnode_getDomParentVNode = (vnode, includeProjection = !0) => {
3483
3745
  for (;vnode && !vnode_isElementVNode(vnode); ) {
3484
- vnode = vnode[1];
3746
+ vnode = vnode[1] || (includeProjection ? vnode_getProp(vnode, "q:sparent", id => vnode_isVNode(id) ? id : null) : null);
3485
3747
  }
3486
3748
  return vnode;
3487
3749
  };
3488
3750
  const vnode_remove = (journal, vParent, vToRemove, removeDOM) => {
3489
3751
  if (assertEqual(vnode_getParent(vToRemove)), vnode_isTextVNode(vToRemove) && vnode_ensureTextInflated(journal, vToRemove),
3490
3752
  removeDOM) {
3491
- const domParent = vnode_getDomParent(vParent);
3753
+ const domParent = vnode_getDomParent(vParent, !1);
3492
3754
  if (vnode_getAttr(vParent, "dangerouslySetInnerHTML")) {
3493
3755
  return;
3494
3756
  }
@@ -3868,6 +4130,25 @@
3868
4130
  };
3869
4131
  const vnode_getProps = vnode => vnode[vnode_getPropStartIndex(vnode)];
3870
4132
  const vnode_getParent = vnode => vnode[1] || null;
4133
+ const vnode_isDescendantOf = (vnode, ancestor, rootVNode) => {
4134
+ let parent = vnode_getParentOrProjectionParent(vnode, rootVNode);
4135
+ for (;parent; ) {
4136
+ if (parent === ancestor) {
4137
+ return !0;
4138
+ }
4139
+ parent = vnode_getParentOrProjectionParent(parent, rootVNode);
4140
+ }
4141
+ return !1;
4142
+ };
4143
+ const vnode_getParentOrProjectionParent = (vnode, rootVNode) => {
4144
+ if (rootVNode) {
4145
+ const parentProjection = vnode_getProp(vnode, "q:sparent", id => vnode_locate(rootVNode, id));
4146
+ if (parentProjection) {
4147
+ return parentProjection;
4148
+ }
4149
+ }
4150
+ return vnode_getParent(vnode);
4151
+ };
3871
4152
  const vnode_getNode = vnode => null === vnode || vnode_isVirtualVNode(vnode) ? null : vnode_isElementVNode(vnode) ? vnode[6] : (assertTrue(vnode_isTextVNode(vnode)),
3872
4153
  vnode[4]);
3873
4154
  function vnode_toString(depth = 20, offset = "", materialize = !1, siblings = !1, colorize = !0) {
@@ -4008,9 +4289,9 @@
4008
4289
  }
4009
4290
  const container = this.$container$;
4010
4291
  let propValue = allocate(container, typeId, value);
4011
- return typeId >= 14 && (propValue = inflate(container, propValue, typeId, value)),
4012
- Reflect.set(target, property, propValue), this.$data$[idx] = void 0, this.$data$[idx + 1] = propValue,
4013
- propValue;
4292
+ return Reflect.set(target, property, propValue), this.$data$[idx] = void 0, this.$data$[idx + 1] = propValue,
4293
+ typeId >= 14 && (propValue = inflate(container, propValue, typeId, value), Reflect.set(target, property, propValue),
4294
+ this.$data$[idx + 1] = propValue), propValue;
4014
4295
  }
4015
4296
  has(target, property) {
4016
4297
  return property === SERIALIZER_PROXY_UNWRAP || Object.prototype.hasOwnProperty.call(target, property);
@@ -4133,7 +4414,7 @@
4133
4414
  const d = data;
4134
4415
  computed.$computeQrl$ = d[0], computed.$effects$ = new Set(d[1]);
4135
4416
  d.length > 2 ? (computed.$untrackedValue$ = d[2], 29 === typeId && (computed.$flags$ |= 1)) : (computed.$flags$ |= 1,
4136
- computed.$computeQrl$.resolve(), container.$scheduler$?.(1, null, computed.$computeQrl$));
4417
+ computed.$computeQrl$.resolve(), container.$scheduler$(1, null, computed.$computeQrl$));
4137
4418
  break;
4138
4419
  }
4139
4420
 
@@ -4613,8 +4894,8 @@
4613
4894
  output(26, [ ...serializeWrappingFn(serializationContext, value), filterEffectBackRefs(value[_EFFECT_BACK_REF]), value.$flags$, value.$hostElement$, ...value.$effects$ || [] ]);
4614
4895
  } else if (value instanceof ComputedSignalImpl) {
4615
4896
  let v = value.$untrackedValue$;
4616
- const shouldAlwaysSerialize = 16 & value.$flags$;
4617
- const shouldNeverSerialize = 8 & value.$flags$;
4897
+ const shouldAlwaysSerialize = 32 & value.$flags$;
4898
+ const shouldNeverSerialize = 16 & value.$flags$;
4618
4899
  const isInvalid = 1 & value.$flags$;
4619
4900
  const isSkippable = fastSkipSerialize(value.$untrackedValue$);
4620
4901
  shouldAlwaysSerialize ? v = value.$untrackedValue$ : (shouldNeverSerialize || isInvalid || isSkippable) && (v = NEEDS_COMPUTATION),
@@ -4851,8 +5132,7 @@
4851
5132
  const result = platform.chunkForSymbol(symbol, chunk, value.dev?.file);
4852
5133
  result && (chunk = result[1], symbol = result[0]);
4853
5134
  }
4854
- const isSync = (value => isQrl(value) && "<sync>" == value.$symbol$)(value);
4855
- if (isSync) {
5135
+ if (isSyncQrl(value)) {
4856
5136
  chunk = "", symbol = String(serializationContext.$addSyncFn$(null, 0, value.resolved));
4857
5137
  } else {
4858
5138
  chunk || (chunk = serializationContext.$symbolToChunkResolver$(value.$hash$));
@@ -5471,7 +5751,7 @@
5471
5751
  assertQrl(qrl);
5472
5752
  const task = new Task(1, i, iCtx.$hostElement$, qrl, void 0, null);
5473
5753
  set(task), useRunTask(task, eagerness), isServerPlatform() || (qrl.resolve(iCtx.$element$),
5474
- iCtx.$container$.$scheduler$(32, task));
5754
+ iCtx.$container$.$scheduler$(16, task));
5475
5755
  };
5476
5756
  const useRunTask = (task, eagerness) => {
5477
5757
  "intersection-observer" === eagerness ? useOn("qvisible", getTaskHandlerQrl(task)) : "document-ready" === eagerness ? useOnDocument("qinit", getTaskHandlerQrl(task)) : "document-idle" === eagerness && useOnDocument("qidle", getTaskHandlerQrl(task));
@@ -5491,7 +5771,8 @@
5491
5771
  cacheName && caches.delete(cacheName).catch(console.error);
5492
5772
  }).catch(console.error);
5493
5773
  }).toString();
5494
- Object.defineProperty(exports, "isBrowser", {
5774
+ globalThis.__qwik && console.error(`==============================================\nQwik version ${globalThis.__qwik} already imported while importing ${version}. Verify external vs bundled imports etc. This can lead to issues due to duplicated shared structures.\n==============================================\n`),
5775
+ globalThis.__qwik = version, Object.defineProperty(exports, "isBrowser", {
5495
5776
  enumerable: !0,
5496
5777
  get: function() {
5497
5778
  return build.isBrowser;
@@ -5530,8 +5811,8 @@
5530
5811
  }, exports.RenderOnce = RenderOnce, exports.Resource = props => _jsxSorted(Fragment, null, null, function(props) {
5531
5812
  const resource = props.value;
5532
5813
  if (isResourceReturn(resource)) {
5814
+ const state = resource._state;
5533
5815
  if (!isServerPlatform()) {
5534
- const state = resource._state;
5535
5816
  if ("pending" === state && props.onPending) {
5536
5817
  return Promise.resolve().then(useBindInvokeContext(props.onPending));
5537
5818
  }
@@ -5545,8 +5826,7 @@
5545
5826
  }
5546
5827
  }
5547
5828
  }
5548
- const value = resource.value;
5549
- return value ? value.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected)) : Promise.resolve(void 0);
5829
+ return untrack(() => resource.value).then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
5550
5830
  }
5551
5831
  if (isPromise(resource)) {
5552
5832
  return resource.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
@@ -5604,8 +5884,10 @@
5604
5884
  exports._getVarProps = props => props ? _VAR_PROPS in props ? "children" in props ? {
5605
5885
  ...props[_VAR_PROPS],
5606
5886
  children: props.children
5607
- } : props[_VAR_PROPS] : props : null, exports._isJSXNode = isJSXNode, exports._isStore = isStore,
5608
- exports._isStringifiable = function(value) {
5887
+ } : props[_VAR_PROPS] : props : null, exports._hasStoreEffects = (value, prop) => {
5888
+ const handler = getStoreHandler(value);
5889
+ return !!handler && (handler.$effects$?.get(prop)?.size ?? 0) > 0;
5890
+ }, exports._isJSXNode = isJSXNode, exports._isStore = isStore, exports._isStringifiable = function(value) {
5609
5891
  return null === value || "string" == typeof value || "number" == typeof value || "boolean" == typeof value;
5610
5892
  }, exports._isTask = isTask, exports._jsxBranch = input => input, exports._jsxC = (type, mutable, _flags, key) => jsx(type, mutable, key),
5611
5893
  exports._jsxQ = (type, mutable, immutable, children, _flags, key) => jsx(type, {
@@ -5630,7 +5912,7 @@
5630
5912
  if (hostElement) {
5631
5913
  return iCtx.$container$?.resolveContext(hostElement, context);
5632
5914
  }
5633
- }, exports._restProps = (props, omit, target = {}) => {
5915
+ }, exports._restProps = (props, omit = [], target = {}) => {
5634
5916
  let constPropsTarget = null;
5635
5917
  const constProps = props[_CONST_PROPS];
5636
5918
  if (constProps) {
@@ -5644,7 +5926,7 @@
5644
5926
  omit.includes(key) || (varPropsTarget[key] = varProps[key]);
5645
5927
  }
5646
5928
  return createPropsProxy(varPropsTarget, constPropsTarget);
5647
- }, exports._run = queueQRL, exports._serializationWeakRef = obj => new SerializationWeakRef(obj),
5929
+ }, exports._run = _run, exports._serializationWeakRef = obj => new SerializationWeakRef(obj),
5648
5930
  exports._serialize = async function(data) {
5649
5931
  const serializationContext = createSerializationContext(null, null, () => "", () => "", () => {}, new WeakMap);
5650
5932
  for (const root of data) {
@@ -5658,12 +5940,17 @@
5658
5940
  exports._vnode_getProps = vnode_getProps, exports._vnode_isMaterialized = vnode_isMaterialized,
5659
5941
  exports._vnode_isTextVNode = vnode_isTextVNode, exports._vnode_isVirtualVNode = vnode_isVirtualVNode,
5660
5942
  exports._vnode_toString = vnode_toString, exports._waitUntilRendered = elm => {
5661
- const containerEl = _getQContainerElement(elm);
5662
- if (!containerEl) {
5663
- return Promise.resolve();
5664
- }
5665
- const container = containerEl.qContainer;
5666
- return container?.renderDone ?? Promise.resolve();
5943
+ const container = _getQContainerElement(elm)?.qContainer;
5944
+ return container ? (async () => {
5945
+ for (;;) {
5946
+ await container.$scheduler$(255).$returnValue$;
5947
+ const firstEpoch = container.$flushEpoch$ || 0;
5948
+ await Promise.resolve();
5949
+ if (firstEpoch === (container.$flushEpoch$ || 0)) {
5950
+ return;
5951
+ }
5952
+ }
5953
+ })() : Promise.resolve();
5667
5954
  }, exports._walkJSX = _walkJSX, exports._wrapProp = _wrapProp, exports._wrapSignal = (obj, prop) => {
5668
5955
  const r = _wrapProp(obj, prop);
5669
5956
  return r === _IMMUTABLE ? obj[prop] : r;
@@ -5672,8 +5959,8 @@
5672
5959
  exports.createComputed$ = createComputed$, exports.createComputedQrl = createComputedSignal,
5673
5960
  exports.createContextId = createContextId, exports.createElement = h, exports.createSerializer$ = createSerializer$,
5674
5961
  exports.createSerializerQrl = createSerializerSignal, exports.createSignal = createSignal,
5675
- exports.event$ = event$, exports.eventQrl = eventQrl, exports.getDomContainer = getDomContainer,
5676
- exports.getLocale = function(defaultLocale) {
5962
+ exports.event$ = event$, exports.eventQrl = eventQrl, exports.forceStoreEffects = forceStoreEffects,
5963
+ exports.getDomContainer = getDomContainer, exports.getLocale = function(defaultLocale) {
5677
5964
  if (void 0 === _locale) {
5678
5965
  const ctx = tryGetInvokeContext();
5679
5966
  if (ctx && ctx.$locale$) {
@@ -5716,7 +6003,7 @@
5716
6003
  const container = getDomContainer(parent);
5717
6004
  container.$serverData$ = opts.serverData || {};
5718
6005
  const host = container.rootVNode;
5719
- return container.$scheduler$(4, host, host, jsxNode), await container.$scheduler$(255),
6006
+ return container.$scheduler$(4, host, host, jsxNode), await container.$scheduler$(255).$returnValue$,
5720
6007
  {
5721
6008
  cleanup: () => {
5722
6009
  cleanup(container, container.rootVNode);