@qwik.dev/core 2.0.0-beta.21 → 2.0.0-beta.23

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.21-dev+c008e88
3
+ * @qwik.dev/core 2.0.0-beta.23-dev+03de42d
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
@@ -11,7 +11,7 @@ export { isBrowser, isDev, isServer } from "@qwik.dev/core/build";
11
11
 
12
12
  import { p } from "@qwik.dev/core/preloader";
13
13
 
14
- const version = "2.0.0-beta.21-dev+c008e88";
14
+ const version = "2.0.0-beta.23-dev+03de42d";
15
15
 
16
16
  const qDev = !1;
17
17
 
@@ -158,8 +158,6 @@ const XLINK_NS = "http://www.w3.org/1999/xlink";
158
158
 
159
159
  const XML_NS = "http://www.w3.org/XML/1998/namespace";
160
160
 
161
- const ResourceEvent = "qResource";
162
-
163
161
  const RenderEvent = "qRender";
164
162
 
165
163
  const TaskEvent = "qTask";
@@ -266,10 +264,6 @@ const safeCall = (call, thenFn, rejectFn) => {
266
264
 
267
265
  const maybeThen = (valueOrPromise, thenFn) => isPromise(valueOrPromise) ? valueOrPromise.then(thenFn) : thenFn(valueOrPromise);
268
266
 
269
- const delay = timeout => new Promise(resolve => {
270
- setTimeout(resolve, timeout);
271
- });
272
-
273
267
  const checkError = e => {
274
268
  isServer && e instanceof ReferenceError && e.message.includes("window") && (e.message = 'It seems like you forgot to add "if (isBrowser) {...}" here:' + e.message);
275
269
  };
@@ -389,30 +383,6 @@ const vnode_getElementNamespaceFlags = element => {
389
383
  }
390
384
  };
391
385
 
392
- function vnode_getDomChildrenWithCorrectNamespacesToInsert(journal, domParentVNode, newChild) {
393
- const {elementNamespace, elementNamespaceFlag} = getNewElementNamespaceData(domParentVNode, newChild);
394
- let domChildren = [];
395
- if (elementNamespace === HTML_NS) {
396
- domChildren = vnode_getDOMChildNodes(journal, newChild, !0);
397
- } else {
398
- const children = vnode_getDOMChildNodes(journal, newChild, !0);
399
- for (let i = 0; i < children.length; i++) {
400
- const childVNode = children[i];
401
- if (vnode_isTextVNode(childVNode)) {
402
- domChildren.push(childVNode);
403
- continue;
404
- }
405
- if ((1536 & childVNode.flags) == (1536 & domParentVNode.flags)) {
406
- domChildren.push(childVNode);
407
- continue;
408
- }
409
- const newChildElement = vnode_cloneElementWithNamespace(childVNode, domParentVNode, elementNamespace, elementNamespaceFlag);
410
- newChildElement && (childVNode.node = newChildElement, domChildren.push(childVNode));
411
- }
412
- }
413
- return domChildren;
414
- }
415
-
416
386
  function cloneDomTreeWithNamespace(element, elementName, namespace, deep = !1) {
417
387
  const newElement = element.ownerDocument.createElementNS(namespace, elementName);
418
388
  for (const attr of element.attributes) {
@@ -650,7 +620,7 @@ function addCursorToQueue(container, cursor) {
650
620
  break;
651
621
  }
652
622
  }
653
- globalCursorQueue.splice(insertIndex, 0, cursor), container.$cursorCount$++, container.$renderPromise$ ||= new Promise(r => container.$resolveRenderPromise$ = r);
623
+ globalCursorQueue.splice(insertIndex, 0, cursor), container.$pendingCount$++, container.$renderPromise$ ||= new Promise(r => container.$resolveRenderPromise$ = r);
654
624
  }
655
625
 
656
626
  function getHighestPriorityCursor() {
@@ -671,7 +641,7 @@ function getHighestPriorityCursor() {
671
641
  }
672
642
 
673
643
  function pauseCursor(cursor, container) {
674
- pausedCursorQueue.push(cursor), removeCursorFromQueue(cursor, container, !0), container.$pausedCursorCount$++;
644
+ pausedCursorQueue.push(cursor), removeCursorFromQueue(cursor, container, !0), container.$pendingCount$++;
675
645
  }
676
646
 
677
647
  function resumeCursor(cursor, container) {
@@ -679,7 +649,7 @@ function resumeCursor(cursor, container) {
679
649
  if (-1 !== index) {
680
650
  const lastIndex = pausedCursorQueue.length - 1;
681
651
  index !== lastIndex && (pausedCursorQueue[index] = pausedCursorQueue[lastIndex]),
682
- pausedCursorQueue.pop(), container.$pausedCursorCount$--;
652
+ pausedCursorQueue.pop(), container.$pendingCount$--;
683
653
  }
684
654
  addCursorToQueue(container, cursor);
685
655
  }
@@ -687,7 +657,7 @@ function resumeCursor(cursor, container) {
687
657
  function removeCursorFromQueue(cursor, container, keepCursorFlag) {
688
658
  keepCursorFlag || (cursor.flags &= -257);
689
659
  const index = globalCursorQueue.indexOf(cursor);
690
- -1 !== index && (globalCursorQueue.splice(index, 1), container.$cursorCount$--);
660
+ -1 !== index && (globalCursorQueue.splice(index, 1), container.$pendingCount$--);
691
661
  }
692
662
 
693
663
  const cursorDatas = new WeakMap;
@@ -739,7 +709,7 @@ class SignalImpl {
739
709
  $container$=null;
740
710
  $wrappedSignal$=null;
741
711
  constructor(container, value) {
742
- this.$container$ = container, this.$untrackedValue$ = value;
712
+ this.$container$ = container || tryGetInvokeContext()?.$container$ || null, this.$untrackedValue$ = value;
743
713
  }
744
714
  force() {
745
715
  scheduleEffects(this.$container$, this, this.$effects$);
@@ -751,22 +721,16 @@ class SignalImpl {
751
721
  this.$untrackedValue$ = value;
752
722
  }
753
723
  get value() {
724
+ const val = this.untrackedValue;
754
725
  const ctx = tryGetInvokeContext();
755
726
  if (!ctx) {
756
- return this.untrackedValue;
757
- }
758
- if (null === this.$container$) {
759
- if (!ctx.$container$) {
760
- return this.untrackedValue;
761
- }
762
- this.$container$ = ctx.$container$;
763
- } else {
764
- isDev && assertTrue(!ctx.$container$ || ctx.$container$ === this.$container$, "Do not use signals across containers");
727
+ return val;
765
728
  }
729
+ null === this.$container$ ? this.$container$ = ctx.$container$ : isDev && assertTrue(!ctx.$container$ || ctx.$container$ === this.$container$, "Do not use signals across containers");
766
730
  const effectSubscriber = ctx.$effectSubscriber$;
767
731
  return effectSubscriber && (ensureContainsSubscription(this.$effects$ ||= new Set, effectSubscriber),
768
732
  ensureContainsBackRef(effectSubscriber, this), (import.meta.env.TEST ? !isDomContainer(this.$container$) : isServer) && addQrlToSerializationCtx(effectSubscriber, this.$container$)),
769
- this.untrackedValue;
733
+ val;
770
734
  }
771
735
  set value(value) {
772
736
  value !== this.$untrackedValue$ && (this.$untrackedValue$ = value, scheduleEffects(this.$container$, this, this.$effects$));
@@ -775,7 +739,14 @@ class SignalImpl {
775
739
  qDev;
776
740
  }
777
741
  toString() {
778
- return isDev ? `[${this.constructor.name}${1 & this.$flags$ ? " INVALID" : ""} ${String(this.$untrackedValue$)}]` + (Array.from(this.$effects$ || []).map(e => "\n -> " + pad(qwikDebugToString(e.consumer), " ")).join("\n") || "") : this.constructor.name;
742
+ if (!isDev) {
743
+ return this.constructor.name;
744
+ }
745
+ try {
746
+ return `[${this.constructor.name}${1 & this.$flags$ ? " INVALID" : ""} ${this.$untrackedValue$}]` + (Array.from(this.$effects$ || []).map(e => "\n -> " + pad(qwikDebugToString(e.consumer), " ")).join("\n") || "");
747
+ } catch (e) {
748
+ return `[${this.constructor.name} <cannot stringify>]`;
749
+ }
779
750
  }
780
751
  toJSON() {
781
752
  return {
@@ -784,23 +755,15 @@ class SignalImpl {
784
755
  }
785
756
  }
786
757
 
787
- const setupSignalValueAccess = (target, effectsFn, returnValueFn) => {
758
+ const setupSignalValueAccess = (target, effectsProp, valueProp) => {
788
759
  const ctx = tryGetInvokeContext();
789
- if (!ctx) {
790
- return returnValueFn();
791
- }
792
- if (null === target.$container$) {
793
- if (!ctx.$container$) {
794
- return returnValueFn();
795
- }
796
- target.$container$ = ctx.$container$;
797
- } else {
760
+ if (ctx && (target.$container$ ||= ctx.$container$ || null)) {
798
761
  isDev && assertTrue(!ctx.$container$ || ctx.$container$ === target.$container$, "Do not use signals across containers");
762
+ const effectSubscriber = ctx.$effectSubscriber$;
763
+ effectSubscriber && (ensureContainsSubscription(target[effectsProp] ||= new Set, effectSubscriber),
764
+ ensureContainsBackRef(effectSubscriber, target), addQrlToSerializationCtx(effectSubscriber, target.$container$));
799
765
  }
800
- const effectSubscriber = ctx.$effectSubscriber$;
801
- return effectSubscriber && (ensureContainsSubscription(effectsFn(), effectSubscriber),
802
- ensureContainsBackRef(effectSubscriber, target), addQrlToSerializationCtx(effectSubscriber, target.$container$)),
803
- returnValueFn();
766
+ return target[valueProp];
804
767
  };
805
768
 
806
769
  const _CONST_PROPS = Symbol("CONST");
@@ -943,18 +906,6 @@ const _getConstProps = props => props && _CONST_PROPS in props ? props[_CONST_PR
943
906
 
944
907
  const isPropsProxy = obj => obj && _VAR_PROPS in obj;
945
908
 
946
- const cleanupDestroyable = destroyable => {
947
- const destroy = destroyable.$destroy$;
948
- if (destroy) {
949
- destroyable.$destroy$ = null;
950
- try {
951
- destroy();
952
- } catch (err) {
953
- logError(err);
954
- }
955
- }
956
- };
957
-
958
909
  const NEEDS_COMPUTATION = Symbol("invalid");
959
910
 
960
911
  class EffectSubscription {
@@ -1009,7 +960,7 @@ const trackFn = (target, container) => (obj, prop) => {
1009
960
  const cleanupFn = (target, handleError) => {
1010
961
  let cleanupFns = null;
1011
962
  return [ fn => {
1012
- "function" == typeof fn && (cleanupFns || (cleanupFns = [], target.$destroy$ = noSerialize(() => {
963
+ "function" == typeof fn && (cleanupFns || (cleanupFns = [], target.$destroy$ = () => {
1013
964
  target.$destroy$ = null;
1014
965
  for (const fn of cleanupFns) {
1015
966
  try {
@@ -1018,31 +969,30 @@ const cleanupFn = (target, handleError) => {
1018
969
  handleError(err);
1019
970
  }
1020
971
  }
1021
- })), cleanupFns.push(fn));
972
+ }), cleanupFns.push(fn));
1022
973
  }, cleanupFns ?? [] ];
1023
974
  };
1024
975
 
1025
- const DEBUG = !1;
976
+ const DEBUG$1 = !1;
1026
977
 
1027
- const log = (...args) => console.log("COMPUTED SIGNAL", ...args.map(qwikDebugToString));
978
+ const log$1 = (...args) => console.log("COMPUTED SIGNAL", ...args.map(qwikDebugToString));
1028
979
 
1029
980
  class ComputedSignalImpl extends SignalImpl {
1030
981
  $computeQrl$;
1031
982
  $flags$;
1032
983
  [_EFFECT_BACK_REF]=void 0;
1033
984
  constructor(container, fn, flags = 17) {
1034
- super(container, NEEDS_COMPUTATION), this.$computeQrl$ = fn, this.$flags$ = flags;
985
+ super(container || fn.$container$, NEEDS_COMPUTATION), this.$computeQrl$ = fn, this.$flags$ = flags;
1035
986
  }
1036
987
  invalidate() {
1037
988
  this.$flags$ |= 1;
1038
989
  const ctx = newInvokeContext();
1039
- ctx.$container$ = this.$container$ || void 0, maybeThen(retryOnPromise(() => invoke.call(this, ctx, this.$computeIfNeeded$)), () => {
1040
- 2 & this.$flags$ && (this.$flags$ &= -3, scheduleEffects(this.$container$, this, this.$effects$));
990
+ ctx.$container$ = this.$container$ || void 0;
991
+ const running = retryOnPromise(invokeApply.bind(this, ctx, this.$computeIfNeeded$));
992
+ running && running.catch(err => {
993
+ this.$container$ ? this.$container$.handleError(err, null) : console.error("Error during computation", err);
1041
994
  });
1042
995
  }
1043
- force() {
1044
- this.$flags$ |= 2, super.force();
1045
- }
1046
996
  get untrackedValue() {
1047
997
  return this.$computeIfNeeded$(), isDev && assertFalse(this.$untrackedValue$ === NEEDS_COMPUTATION, "Invalid state"),
1048
998
  this.$untrackedValue$;
@@ -1064,38 +1014,89 @@ class ComputedSignalImpl extends SignalImpl {
1064
1014
  if (isPromise(untrackedValue)) {
1065
1015
  throw qError(29, [ computeQrl.dev ? computeQrl.dev.file : "", computeQrl.$hash$ ]);
1066
1016
  }
1067
- this.$flags$ &= -2;
1068
- untrackedValue !== this.$untrackedValue$ && (this.$untrackedValue$ !== NEEDS_COMPUTATION && (this.$flags$ |= 2),
1069
- this.$untrackedValue$ = untrackedValue);
1017
+ this.$flags$ &= -2, super.value = untrackedValue;
1070
1018
  } finally {
1071
1019
  ctx && (ctx.$effectSubscriber$ = previousEffectSubscription);
1072
1020
  }
1073
1021
  }
1074
1022
  }
1075
1023
 
1024
+ const DEBUG = !1;
1025
+
1026
+ const log = (...args) => console.log("ASYNC COMPUTED SIGNAL", ...args.map(qwikDebugToString));
1027
+
1028
+ class AsyncJob {
1029
+ $signal$;
1030
+ $promise$=null;
1031
+ $cleanupRequested$=!1;
1032
+ $canWrite$=!0;
1033
+ $track$;
1034
+ $cleanups$;
1035
+ $abortController$;
1036
+ constructor($signal$) {
1037
+ this.$signal$ = $signal$;
1038
+ }
1039
+ get track() {
1040
+ return this.$track$ ||= trackFn(this.$signal$, this.$signal$.$container$);
1041
+ }
1042
+ get abortSignal() {
1043
+ return (this.$abortController$ ||= new AbortController).signal;
1044
+ }
1045
+ cache() {
1046
+ console.error("useResource cache() method does not do anything. Use `useAsync$` instead of `useResource$`, use the `interval` option for polling behavior.");
1047
+ }
1048
+ get previous() {
1049
+ const val = this.$signal$.$untrackedValue$;
1050
+ if (val !== NEEDS_COMPUTATION) {
1051
+ return val;
1052
+ }
1053
+ }
1054
+ cleanup(callback) {
1055
+ "function" == typeof callback && (this.$cleanups$ ||= []).push(callback);
1056
+ }
1057
+ }
1058
+
1076
1059
  class AsyncSignalImpl extends ComputedSignalImpl {
1077
1060
  $untrackedLoading$=!1;
1078
1061
  $untrackedError$=void 0;
1079
1062
  $loadingEffects$=void 0;
1080
1063
  $errorEffects$=void 0;
1081
- $destroy$;
1082
- $promiseValue$=NEEDS_COMPUTATION;
1083
- $promise$=null;
1064
+ $current$=null;
1065
+ $jobs$=[];
1066
+ $concurrency$=1;
1067
+ $interval$=0;
1068
+ $pollTimeoutId$=void 0;
1069
+ $timeoutMs$;
1070
+ $computationTimeoutId$;
1084
1071
  [_EFFECT_BACK_REF]=void 0;
1085
- constructor(container, fn, flags = 1) {
1072
+ constructor(container, fn, flags = 17, options) {
1086
1073
  super(container, fn, flags);
1074
+ const interval = options?.interval || 0;
1075
+ const concurrency = options?.concurrency ?? 1;
1076
+ const initial = options?.initial;
1077
+ const timeout = options?.timeout;
1078
+ const eagerCleanup = options?.eagerCleanup;
1079
+ if (void 0 !== initial) {
1080
+ const initialValue = "function" == typeof initial ? initial() : initial;
1081
+ this.$untrackedValue$ = initialValue;
1082
+ }
1083
+ this.$concurrency$ = concurrency, this.$timeoutMs$ = timeout, eagerCleanup && (this.$flags$ |= 32),
1084
+ this.interval = interval;
1087
1085
  }
1088
1086
  get loading() {
1089
- return setupSignalValueAccess(this, () => this.$loadingEffects$ ||= new Set, () => this.untrackedLoading);
1087
+ return setupSignalValueAccess(this, "$loadingEffects$", "untrackedLoading");
1090
1088
  }
1091
1089
  set untrackedLoading(value) {
1092
1090
  value !== this.$untrackedLoading$ && (this.$untrackedLoading$ = value, scheduleEffects(this.$container$, this, this.$loadingEffects$));
1093
1091
  }
1094
1092
  get untrackedLoading() {
1093
+ if (this.$computeIfNeeded$(), (import.meta.env.TEST ? isServerPlatform() : isServer) && this.$current$?.$promise$) {
1094
+ throw this.$current$?.$promise$;
1095
+ }
1095
1096
  return this.$untrackedLoading$;
1096
1097
  }
1097
1098
  get error() {
1098
- return setupSignalValueAccess(this, () => this.$errorEffects$ ||= new Set, () => this.untrackedError);
1099
+ return setupSignalValueAccess(this, "$errorEffects$", "untrackedError");
1099
1100
  }
1100
1101
  set untrackedError(value) {
1101
1102
  value !== this.$untrackedError$ && (this.$untrackedError$ = value, scheduleEffects(this.$container$, this, this.$errorEffects$));
@@ -1103,48 +1104,121 @@ class AsyncSignalImpl extends ComputedSignalImpl {
1103
1104
  get untrackedError() {
1104
1105
  return this.$untrackedError$;
1105
1106
  }
1106
- invalidate() {
1107
- this.$promise$ = null, super.invalidate();
1107
+ get interval() {
1108
+ return this.$interval$;
1109
+ }
1110
+ set interval(value) {
1111
+ this.$clearNextPoll$(), this.$interval$ = value, this.$interval$ > 0 && this.$effects$?.size && this.$scheduleNextPoll$();
1112
+ }
1113
+ async invalidate() {
1114
+ this.$flags$ |= 1, this.$clearNextPoll$(), (this.$effects$?.size || this.$loadingEffects$?.size || this.$errorEffects$?.size) && (await !0,
1115
+ this.$computeIfNeeded$());
1116
+ }
1117
+ abort(reason) {
1118
+ this.$current$ && this.$requestCleanups$(this.$current$, reason);
1119
+ }
1120
+ $scheduleEagerCleanup$() {
1121
+ 32 & this.$flags$ && !this.$hasSubscribers$() && (import.meta.env.TEST ? !isServerPlatform() : isBrowser) && setTimeout(() => {
1122
+ this.$hasSubscribers$() || this.abort();
1123
+ });
1108
1124
  }
1109
1125
  async promise() {
1110
- return this.$promise$ = null, await retryOnPromise(this.$computeIfNeeded$.bind(this)),
1111
- this.$untrackedValue$;
1126
+ for (this.$computeIfNeeded$(); this.$current$?.$promise$; ) {
1127
+ await (this.$current$?.$promise$);
1128
+ }
1112
1129
  }
1113
1130
  $computeIfNeeded$() {
1114
1131
  if (!(1 & this.$flags$)) {
1115
1132
  return;
1116
1133
  }
1117
- const untrackedValue = this.$promiseValue$ === NEEDS_COMPUTATION || null === this.$promise$ ? this.$promiseComputation$() : this.$promiseValue$;
1118
- if (isPromise(untrackedValue)) {
1119
- const isFirstComputation = this.$promiseValue$ === NEEDS_COMPUTATION;
1120
- this.untrackedLoading = !0, this.untrackedError = void 0, this.$promiseValue$ !== NEEDS_COMPUTATION && cleanupDestroyable(this);
1121
- const promise = untrackedValue.then(promiseValue => {
1122
- this.$promiseValue$ = promiseValue, this.untrackedLoading = !1, this.untrackedError = void 0,
1123
- this.setValue(promiseValue) && (this.$flags$ &= -3, scheduleEffects(this.$container$, this, this.$effects$));
1124
- }).catch(err => {
1125
- isPromise(err) || (this.$promiseValue$ = err, this.untrackedLoading = !1, this.untrackedError = err);
1126
- });
1127
- if (isFirstComputation) {
1128
- throw promise;
1134
+ this.$clearNextPoll$(), this.$current$ && this.$requestCleanups$(this.$current$);
1135
+ if (this.$jobs$.length >= (0 === this.$concurrency$ ? Number.POSITIVE_INFINITY : this.$concurrency$)) {
1136
+ return;
1137
+ }
1138
+ this.$flags$ &= -2;
1139
+ const running = new AsyncJob(this);
1140
+ this.$current$ = running, this.$jobs$.push(running), running.$promise$ = this.$runComputation$(running);
1141
+ }
1142
+ async $runComputation$(running) {
1143
+ const isCurrent = () => running === this.$current$;
1144
+ this.untrackedLoading = !0;
1145
+ const fn = this.$computeQrl$.resolved || await this.$computeQrl$.resolve();
1146
+ try {
1147
+ this.$timeoutMs$ && (this.$computationTimeoutId$ = setTimeout(() => {
1148
+ running.$abortController$?.abort();
1149
+ const error = new Error("timeout");
1150
+ isCurrent() && (this.untrackedError = error, running.$canWrite$ = !1);
1151
+ }, this.$timeoutMs$));
1152
+ const value = await retryOnPromise(fn.bind(null, running));
1153
+ if (running.$promise$ = null, running.$canWrite$) {
1154
+ const index = this.$jobs$.indexOf(running);
1155
+ if (-1 !== index) {
1156
+ for (let i = 0; i < index; i++) {
1157
+ this.$jobs$[i].$canWrite$ = !1;
1158
+ }
1159
+ }
1160
+ this.untrackedError = void 0, this.value = value;
1129
1161
  }
1130
- return promise;
1162
+ } catch (err) {
1163
+ running.$promise$ = null, isCurrent() && (this.untrackedError = err);
1131
1164
  }
1132
- this.setValue(untrackedValue);
1165
+ isCurrent() && (clearTimeout(this.$computationTimeoutId$), 1 & this.$flags$ ? this.$computeIfNeeded$() : (this.untrackedLoading = !1,
1166
+ this.$scheduleNextPoll$()));
1133
1167
  }
1134
- async $promiseComputation$() {
1135
- if (!this.$promise$) {
1136
- const [cleanup] = cleanupFn(this, err => this.$container$?.handleError(err, null));
1137
- this.$promise$ = this.$computeQrl$.getFn()({
1138
- track: trackFn(this, this.$container$),
1139
- cleanup
1140
- });
1168
+ async $destroy$() {
1169
+ this.$clearNextPoll$(), clearTimeout(this.$computationTimeoutId$), this.$current$ && await this.$requestCleanups$(this.$current$),
1170
+ await Promise.all(this.$jobs$.map(job => job.$promise$));
1171
+ }
1172
+ get untrackedValue() {
1173
+ if (this.$computeIfNeeded$(), this.$current$?.$promise$) {
1174
+ if (this.$untrackedValue$ === NEEDS_COMPUTATION || (import.meta.env.TEST ? isServerPlatform() : isServer)) {
1175
+ throw this.$current$?.$promise$;
1176
+ }
1177
+ return this.$untrackedValue$;
1178
+ }
1179
+ if (this.$untrackedError$) {
1180
+ throw this.$untrackedError$;
1141
1181
  }
1142
- return this.$promise$;
1182
+ return this.$untrackedValue$;
1143
1183
  }
1144
- setValue(value) {
1145
- this.$flags$ &= -2;
1146
- const didChange = value !== this.$untrackedValue$;
1147
- return didChange && (this.$untrackedValue$ = value, this.$flags$ |= 2), didChange;
1184
+ $clearNextPoll$() {
1185
+ void 0 !== this.$pollTimeoutId$ && (clearTimeout(this.$pollTimeoutId$), this.$pollTimeoutId$ = void 0);
1186
+ }
1187
+ $scheduleNextPoll$() {
1188
+ (import.meta.env.TEST ? !isServerPlatform() : isBrowser) && this.$interval$ > 0 && (this.$clearNextPoll$(),
1189
+ this.$pollTimeoutId$ = setTimeout(this.invalidate.bind(this), this.$interval$),
1190
+ this.$pollTimeoutId$?.unref?.());
1191
+ }
1192
+ $hasSubscribers$() {
1193
+ return !!(this.$effects$?.size || this.$loadingEffects$?.size || this.$errorEffects$?.size);
1194
+ }
1195
+ async $requestCleanups$(job, reason) {
1196
+ if (job.$cleanupRequested$) {
1197
+ return job.$promise$;
1198
+ }
1199
+ job.$cleanupRequested$ = !0, job.$abortController$?.abort(reason), job.$promise$ = Promise.resolve(job.$promise$).then(() => job.$promise$ = this.$runCleanups$(job));
1200
+ }
1201
+ async $runCleanups$(job) {
1202
+ const cleanups = job.$cleanups$;
1203
+ if (cleanups?.length) {
1204
+ const onError = err => {
1205
+ const handleError = this.$container$?.handleError;
1206
+ handleError ? handleError(err, null) : console.error("Error in async signal cleanup", err);
1207
+ };
1208
+ await Promise.all(cleanups.map(fn => {
1209
+ try {
1210
+ const result = fn();
1211
+ if (isPromise(result)) {
1212
+ return result.catch(onError);
1213
+ }
1214
+ } catch (err) {
1215
+ onError(err);
1216
+ }
1217
+ })), cleanups.length = 0;
1218
+ }
1219
+ const jobs = this.$jobs$;
1220
+ const idx = jobs.indexOf(job);
1221
+ -1 !== idx && jobs.splice(idx, 1), this.$computeIfNeeded$();
1148
1222
  }
1149
1223
  }
1150
1224
 
@@ -1161,16 +1235,16 @@ class SerializerSignalImpl extends ComputedSignalImpl {
1161
1235
  if (!(1 & this.$flags$)) {
1162
1236
  return;
1163
1237
  }
1164
- throwIfQRLNotResolved(this.$computeQrl$);
1238
+ throwIfQRLNotResolved(this.$computeQrl$), this.$flags$ &= -2;
1165
1239
  let arg = this.$computeQrl$.resolved;
1166
1240
  "function" == typeof arg && (arg = arg());
1167
1241
  const {deserialize, initial} = arg;
1168
1242
  const update = arg.update;
1169
1243
  const currentValue = this.$untrackedValue$ === NEEDS_COMPUTATION ? initial : this.$untrackedValue$;
1170
1244
  const untrackedValue = trackSignal(() => this.$didInitialize$ ? update?.(currentValue) || currentValue : deserialize(currentValue), this, ".", this.$container$);
1171
- const didChange = this.$didInitialize$ && "undefined" !== untrackedValue || untrackedValue !== this.$untrackedValue$;
1172
- this.$flags$ &= -2, this.$didInitialize$ = !0, didChange && (this.$flags$ |= 2,
1173
- this.$untrackedValue$ = untrackedValue);
1245
+ this.$didInitialize$ = !0;
1246
+ (this.$didInitialize$ && "undefined" !== untrackedValue || untrackedValue !== this.$untrackedValue$) && (this.$untrackedValue$ = untrackedValue,
1247
+ scheduleEffects(this.$container$, this, this.$effects$));
1174
1248
  }
1175
1249
  }
1176
1250
 
@@ -1178,7 +1252,7 @@ const createSignal$1 = value => new SignalImpl(null, value);
1178
1252
 
1179
1253
  const createComputedSignal = (qrl, options) => new ComputedSignalImpl(options?.container || null, qrl, getComputedSignalFlags(options?.serializationStrategy || "always"));
1180
1254
 
1181
- const createAsyncSignal = (qrl, options) => new AsyncSignalImpl(options?.container || null, qrl, getComputedSignalFlags(options?.serializationStrategy || "never"));
1255
+ const createAsyncSignal = (qrl, options) => new AsyncSignalImpl(options?.container || null, qrl, getComputedSignalFlags(options?.serializationStrategy || "always"), options);
1182
1256
 
1183
1257
  const createSerializerSignal = arg => new SerializerSignalImpl(null, arg);
1184
1258
 
@@ -1186,8 +1260,7 @@ const createSignal = createSignal$1;
1186
1260
 
1187
1261
  const createComputed$ = /*#__PURE__*/ implicit$FirstArg(createComputedSignal);
1188
1262
 
1189
- const createAsync$ =
1190
- /*#__PURE__*/ implicit$FirstArg(createAsyncSignal);
1263
+ const createAsync$ = /*#__PURE__*/ implicit$FirstArg(createAsyncSignal);
1191
1264
 
1192
1265
  const createSerializer$ = implicit$FirstArg(createSerializerSignal);
1193
1266
 
@@ -1253,10 +1326,6 @@ class WrappedSignalImpl extends SignalImpl {
1253
1326
  }
1254
1327
  2 & this.$flags$ && (this.$flags$ &= -3, scheduleEffects(this.$container$, this, this.$effects$));
1255
1328
  }
1256
- force() {
1257
- this.$flags$ |= 2, this.$container$ && this.$hostElement$ && (this.$container$.setHostProp(this.$hostElement$, ":signal", this),
1258
- markVNodeDirty(this.$container$, this.$hostElement$, 16));
1259
- }
1260
1329
  get untrackedValue() {
1261
1330
  return this.$computeIfNeeded$(), isDev && assertFalse(this.$untrackedValue$ === NEEDS_COMPUTATION, "Invalid state"),
1262
1331
  this.$untrackedValue$;
@@ -1321,6 +1390,8 @@ function clearAsyncSignal(producer, effect) {
1321
1390
  effects && effects.has(effect) && effects.delete(effect);
1322
1391
  const pendingEffects = producer.$loadingEffects$;
1323
1392
  pendingEffects && pendingEffects.has(effect) && pendingEffects.delete(effect);
1393
+ const errorEffects = producer.$errorEffects$;
1394
+ errorEffects && errorEffects.has(effect) && errorEffects.delete(effect), producer.$scheduleEagerCleanup$();
1324
1395
  }
1325
1396
 
1326
1397
  function clearStoreOrProps(producer, effect) {
@@ -1357,6 +1428,19 @@ function _chk(_, element) {
1357
1428
  _captures[0].value = element.checked;
1358
1429
  }
1359
1430
 
1431
+ function _res(_, element) {
1432
+ maybeScopeFromQL(this, element);
1433
+ }
1434
+
1435
+ const isObjectEmpty = obj => {
1436
+ for (const key in obj) {
1437
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1438
+ return !1;
1439
+ }
1440
+ }
1441
+ return !0;
1442
+ };
1443
+
1360
1444
  const _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1361
1445
 
1362
1446
  class JSXNodeImpl {
@@ -1370,7 +1454,7 @@ class JSXNodeImpl {
1370
1454
  _proxy=null;
1371
1455
  constructor(type, varProps, constProps, children, key, toSort, dev) {
1372
1456
  this.type = type, this.children = children, this.toSort = !!toSort, this.key = null == key ? null : "string" == typeof key ? key : "" + key,
1373
- this.varProps = !varProps || isEmpty(varProps) ? EMPTY_OBJ : varProps, this.constProps = !constProps || isEmpty(constProps) ? null : constProps,
1457
+ this.varProps = !varProps || isObjectEmpty(varProps) ? EMPTY_OBJ : varProps, this.constProps = !constProps || isObjectEmpty(constProps) ? null : constProps,
1374
1458
  seal();
1375
1459
  }
1376
1460
  get props() {
@@ -1388,8 +1472,6 @@ const mergeHandlers = (obj, event, handler) => {
1388
1472
 
1389
1473
  const isJSXNode = n => n instanceof JSXNodeImpl;
1390
1474
 
1391
- const isEmpty = obj => 0 === Object.keys(obj).length;
1392
-
1393
1475
  const BIND_VALUE = "bind:value";
1394
1476
 
1395
1477
  const BIND_CHECKED = "bind:checked";
@@ -1589,7 +1671,7 @@ function addUseOnEvent(jsxElement, key, value) {
1589
1671
  props[key] = void 0);
1590
1672
  }
1591
1673
 
1592
- const getValue$1 = o => o.value;
1674
+ const getValue = o => o.value;
1593
1675
 
1594
1676
  function findFirstElementNode(jsx) {
1595
1677
  const queue = [ jsx ];
@@ -1607,7 +1689,7 @@ function findFirstElementNode(jsx) {
1607
1689
  return maybeThen(jsx, jsx => findFirstElementNode(jsx));
1608
1690
  }
1609
1691
  if (isSignal(jsx)) {
1610
- return findFirstElementNode(untrack(getValue$1, jsx));
1692
+ return findFirstElementNode(untrack(getValue, jsx));
1611
1693
  }
1612
1694
  }
1613
1695
  }
@@ -1903,6 +1985,17 @@ const createInsertOrMoveOperation = (target, parent, beforeTarget) => new Insert
1903
1985
 
1904
1986
  const createSetAttributeOperation = (target, attrName, attrValue, scopedStyleIdPrefix = null, isSvg = !1) => new SetAttributeOperation(target, attrName, attrValue, scopedStyleIdPrefix, isSvg);
1905
1987
 
1988
+ const cleanupDestroyable = destroyable => {
1989
+ if (destroyable.$destroy$) {
1990
+ try {
1991
+ destroyable.$destroy$();
1992
+ } catch (err) {
1993
+ logError(err);
1994
+ }
1995
+ destroyable.$destroy$ = null;
1996
+ }
1997
+ };
1998
+
1906
1999
  function runEventHandlerQRL(handler, event, element, ctx = newInvokeContextFromDOM(event, element)) {
1907
2000
  const container = ctx.$container$;
1908
2001
  const hostElement = ctx.$hostElement$;
@@ -2173,16 +2266,16 @@ function expectSlot(diffContext) {
2173
2266
  const slotNameKey = getSlotNameKey(diffContext, vHost);
2174
2267
  const vProjectedNode = vHost ? vnode_getProp(vHost, slotNameKey, null) : null;
2175
2268
  if (null == vProjectedNode) {
2176
- return vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newVirtual(), diffContext.vCurrent && getInsertBefore(diffContext)),
2177
- vnode_setProp(diffContext.vNewNode, QSlot, slotNameKey), vHost && vnode_setProp(vHost, slotNameKey, diffContext.vNewNode),
2178
- isDev && vnode_setProp(diffContext.vNewNode, "q:type", "P"), isDev && vnode_setProp(diffContext.vNewNode, "q:code", "expectSlot" + count++),
2269
+ return diffContext.vNewNode = vnode_newVirtual(), vnode_setProp(diffContext.vNewNode, QSlot, slotNameKey),
2270
+ vHost && vnode_setProp(vHost, slotNameKey, diffContext.vNewNode), isDev && vnode_setProp(diffContext.vNewNode, "q:type", "P"),
2271
+ vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode, diffContext.vCurrent && getInsertBefore(diffContext)),
2179
2272
  !1;
2180
2273
  }
2181
2274
  if (vProjectedNode === diffContext.vCurrent) {} else {
2182
2275
  const oldParent = vProjectedNode.parent;
2183
- vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vProjectedNode, diffContext.vCurrent && getInsertBefore(diffContext)),
2184
- vnode_setProp(diffContext.vNewNode, QSlot, slotNameKey), vHost && vnode_setProp(vHost, slotNameKey, diffContext.vNewNode),
2185
- isDev && vnode_setProp(diffContext.vNewNode, "q:type", "P"), isDev && vnode_setProp(diffContext.vNewNode, "q:code", "expectSlot" + count++),
2276
+ diffContext.vNewNode = vProjectedNode, vnode_setProp(diffContext.vNewNode, QSlot, slotNameKey),
2277
+ vHost && vnode_setProp(vHost, slotNameKey, diffContext.vNewNode), isDev && vnode_setProp(diffContext.vNewNode, "q:type", "P"),
2278
+ vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode, diffContext.vCurrent && getInsertBefore(diffContext)),
2186
2279
  oldParent && vnode_isElementVNode(oldParent) && !oldParent.firstChild && vnode_getElementName(oldParent) === QTemplate && vnode_remove(diffContext.journal, oldParent.parent, oldParent, !0);
2187
2280
  }
2188
2281
  return !0;
@@ -2318,18 +2411,30 @@ function createNewElement(diffContext, jsx, elementName, currentFile) {
2318
2411
  if (key && (diffContext.vNewNode.key = key), diffContext.scopedStyleIdPrefix) {
2319
2412
  _hasOwnProperty.call(jsx.varProps, "class") || jsx.constProps && _hasOwnProperty.call(jsx.constProps, "class") || element.setAttribute("class", diffContext.scopedStyleIdPrefix);
2320
2413
  }
2321
- vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode, diffContext.vCurrent);
2414
+ vnode_insertElementBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode, diffContext.vCurrent);
2322
2415
  }
2323
2416
 
2324
2417
  function registerEventHandlers(key, value, element, vnode, diffContext) {
2325
2418
  const scopedKebabName = key.slice(2);
2326
- Array.isArray(value) || (value = [ value ]);
2327
- const handlers = [];
2328
- for (const handler of value.flat(2)) {
2329
- handler && handlers.push(runEventHandlerQRL.bind(null, handler));
2419
+ if (Array.isArray(value)) {
2420
+ const arr = value;
2421
+ const handlers = [];
2422
+ for (let i = 0; i < arr.length; i++) {
2423
+ const item = arr[i];
2424
+ if (Array.isArray(item)) {
2425
+ for (let j = 0; j < item.length; j++) {
2426
+ const handler = item[j];
2427
+ handler && handlers.push(runEventHandlerQRL.bind(null, handler));
2428
+ }
2429
+ } else {
2430
+ item && handlers.push(runEventHandlerQRL.bind(null, item));
2431
+ }
2432
+ }
2433
+ (element._qDispatch ||= {})[scopedKebabName] = handlers;
2434
+ } else {
2435
+ value && ((element._qDispatch ||= {})[scopedKebabName] = [ runEventHandlerQRL.bind(null, value) ]);
2330
2436
  }
2331
- (element._qDispatch ||= {})[scopedKebabName] = handlers, "e" !== key.charAt(2) && vnode_setAttr(diffContext.journal, vnode, key, ""),
2332
- registerQwikLoaderEvent(diffContext, scopedKebabName);
2437
+ "e" !== key.charAt(2) && vnode_setAttr(diffContext.journal, vnode, key, ""), registerQwikLoaderEvent(diffContext, scopedKebabName);
2333
2438
  }
2334
2439
 
2335
2440
  function createElementWithNamespace(diffContext, elementName) {
@@ -2522,8 +2627,8 @@ function expectVirtual(diffContext, type, jsxKey) {
2522
2627
  const checkKey = "F" === type;
2523
2628
  const currentKey = getKey(diffContext.vCurrent);
2524
2629
  if (!diffContext.vCurrent || !vnode_isVirtualVNode(diffContext.vCurrent) || currentKey !== jsxKey || checkKey && !jsxKey) {
2525
- return null === jsxKey || diffContext.isCreationMode ? (vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newVirtual(), diffContext.vCurrent && getInsertBefore(diffContext)),
2526
- diffContext.vNewNode.key = jsxKey, void (isDev && vnode_setProp(diffContext.vNewNode, "q:type", type))) : void (moveOrCreateKeyedNode(diffContext, null, jsxKey, getSideBufferKey(null, jsxKey), diffContext.vParent, !0) && (vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newVirtual(), diffContext.vCurrent && getInsertBefore(diffContext)),
2630
+ return null === jsxKey || diffContext.isCreationMode ? (vnode_insertVirtualBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newVirtual(), diffContext.vCurrent && getInsertBefore(diffContext)),
2631
+ diffContext.vNewNode.key = jsxKey, void (isDev && vnode_setProp(diffContext.vNewNode, "q:type", type))) : void (moveOrCreateKeyedNode(diffContext, null, jsxKey, getSideBufferKey(null, jsxKey), diffContext.vParent, !0) && (vnode_insertVirtualBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newVirtual(), diffContext.vCurrent && getInsertBefore(diffContext)),
2527
2632
  diffContext.vNewNode.key = jsxKey, isDev && vnode_setProp(diffContext.vNewNode, "q:type", type)));
2528
2633
  }
2529
2634
  deleteFromSideBuffer(diffContext, null, currentKey);
@@ -2567,14 +2672,14 @@ function expectComponent(diffContext, component) {
2567
2672
  }
2568
2673
 
2569
2674
  function insertNewComponent(diffContext, host, componentQRL, jsxProps) {
2570
- host && clearAllEffects(diffContext.container, host), vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newVirtual(), diffContext.vCurrent && getInsertBefore(diffContext));
2675
+ host && clearAllEffects(diffContext.container, host), vnode_insertVirtualBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newVirtual(), diffContext.vCurrent && getInsertBefore(diffContext));
2571
2676
  const jsxNode = diffContext.jsxValue;
2572
2677
  isDev && vnode_setProp(diffContext.vNewNode, "q:type", "C"), vnode_setProp(diffContext.vNewNode, "q:renderFn", componentQRL),
2573
2678
  vnode_setProp(diffContext.vNewNode, "q:props", jsxProps), diffContext.vNewNode.key = jsxNode.key;
2574
2679
  }
2575
2680
 
2576
2681
  function insertNewInlineComponent(diffContext) {
2577
- vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newVirtual(), diffContext.vCurrent && getInsertBefore(diffContext));
2682
+ vnode_insertVirtualBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newVirtual(), diffContext.vCurrent && getInsertBefore(diffContext));
2578
2683
  const jsxNode = diffContext.jsxValue;
2579
2684
  isDev && vnode_setProp(diffContext.vNewNode, "q:type", "I"), vnode_setProp(diffContext.vNewNode, "q:props", jsxNode.props),
2580
2685
  jsxNode.key && (diffContext.vNewNode.key = jsxNode.key);
@@ -2586,7 +2691,7 @@ function expectText(diffContext, text) {
2586
2691
  return text !== vnode_getText(diffContext.vCurrent) ? void vnode_setText(diffContext.journal, diffContext.vCurrent, text) : void 0;
2587
2692
  }
2588
2693
  }
2589
- vnode_insertBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newText((import.meta.env.TEST ? diffContext.container.document : document).createTextNode(text), text), diffContext.vCurrent);
2694
+ vnode_insertElementBefore(diffContext.journal, diffContext.vParent, diffContext.vNewNode = vnode_newText((import.meta.env.TEST ? diffContext.container.document : document).createTextNode(text), text), diffContext.vCurrent);
2590
2695
  }
2591
2696
 
2592
2697
  function getKey(vNode) {
@@ -2645,7 +2750,7 @@ function handleChangedProps(src, dst, propsHandler, container, triggerEffects =
2645
2750
  }
2646
2751
 
2647
2752
  function isPropsEmpty(props) {
2648
- return !props || 0 === Object.keys(props).length;
2753
+ return !props || isObjectEmpty(props);
2649
2754
  }
2650
2755
 
2651
2756
  function cleanup(container, journal, vNode, cursorRoot = null) {
@@ -2666,7 +2771,7 @@ function cleanup(container, journal, vNode, cursorRoot = null) {
2666
2771
  if (isObject(obj)) {
2667
2772
  const objIsTask = isTask(obj);
2668
2773
  if (objIsTask && 1 & obj.$flags$) {
2669
- obj.$flags$ |= 32, markVNodeDirty(container, vCursor, 64, cursorRoot);
2774
+ obj.$flags$ |= 16, markVNodeDirty(container, vCursor, 64, cursorRoot);
2670
2775
  continue;
2671
2776
  }
2672
2777
  (obj instanceof SignalImpl || isStore(obj)) && clearAllEffects(container, obj),
@@ -2776,147 +2881,6 @@ function containsWrappedSignal(data, signal) {
2776
2881
  return !1;
2777
2882
  }
2778
2883
 
2779
- let count = 0;
2780
-
2781
- const useSequentialScope = () => {
2782
- const iCtx = useInvokeContext();
2783
- const host = iCtx.$hostElement$;
2784
- let seq = iCtx.$container$.getHostProp(host, "q:seq");
2785
- null === seq && (seq = [], iCtx.$container$.setHostProp(host, "q:seq", seq));
2786
- let seqIdx = iCtx.$container$.getHostProp(host, "q:seqIdx");
2787
- for (null === seqIdx && (seqIdx = 0), iCtx.$container$.setHostProp(host, "q:seqIdx", seqIdx + 1); seq.length <= seqIdx; ) {
2788
- seq.push(void 0);
2789
- }
2790
- return {
2791
- val: seq[seqIdx],
2792
- set: value => seq[seqIdx] = value,
2793
- i: seqIdx,
2794
- iCtx
2795
- };
2796
- };
2797
-
2798
- const useResourceQrl = (qrl, opts) => {
2799
- const {val, set, i, iCtx} = useSequentialScope();
2800
- if (null != val) {
2801
- return val.$state$;
2802
- }
2803
- assertQrl(qrl);
2804
- const container = iCtx.$container$;
2805
- const resource = createResourceReturn(container, opts);
2806
- const el = iCtx.$hostElement$;
2807
- const task = new Task(12, i, el, qrl, resource, null);
2808
- return set(task), runResource(task, container, el), resource;
2809
- };
2810
-
2811
- const Resource = props => _jsxSorted(Fragment, null, null, getResourceValueAsPromise(props), 0, null);
2812
-
2813
- const getResolved = resource => resource._resolved;
2814
-
2815
- const getValue = resource => resource.value;
2816
-
2817
- const getLoading = resource => resource.loading;
2818
-
2819
- function getResourceValueAsPromise(props) {
2820
- const resource = props.value;
2821
- if (isResourceReturn(resource)) {
2822
- const state = resource._state;
2823
- if (!isServerPlatform()) {
2824
- if ("pending" === state && props.onPending) {
2825
- return resource.value.catch(() => {}), Promise.resolve().then(useBindInvokeContext(props.onPending));
2826
- }
2827
- if ("rejected" === state && props.onRejected) {
2828
- return Promise.resolve(resource._error).then(useBindInvokeContext(props.onRejected));
2829
- }
2830
- {
2831
- const resolvedValue = untrack(getResolved, resource);
2832
- if (void 0 !== resolvedValue) {
2833
- return Promise.resolve(resolvedValue).then(useBindInvokeContext(props.onResolved));
2834
- }
2835
- }
2836
- }
2837
- return untrack(getValue, resource).then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
2838
- }
2839
- if (isPromise(resource)) {
2840
- return resource.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
2841
- }
2842
- if (isSignal(resource)) {
2843
- const value = retryOnPromise(() => resource.value);
2844
- return (isPromise(value) ? value : Promise.resolve(value)).then(useBindInvokeContext(props.onResolved));
2845
- }
2846
- return Promise.resolve(resource).then(useBindInvokeContext(props.onResolved));
2847
- }
2848
-
2849
- const _createResourceReturn = opts => ({
2850
- __brand: "resource",
2851
- value: void 0,
2852
- loading: !isServerPlatform(),
2853
- _resolved: void 0,
2854
- _error: void 0,
2855
- _state: "pending",
2856
- _timeout: opts?.timeout ?? -1,
2857
- _cache: 0,
2858
- _generation: 0
2859
- });
2860
-
2861
- const createResourceReturn = (container, opts, initialPromise) => {
2862
- const result = _createResourceReturn(opts);
2863
- return result.value = initialPromise, createStore(container, result, 1);
2864
- };
2865
-
2866
- const isResourceReturn = obj => isObject(obj) && "resource" === (getStoreTarget(obj) || obj).__brand;
2867
-
2868
- const runResource = (task, container, host) => {
2869
- task.$flags$ &= -9, cleanupDestroyable(task);
2870
- const iCtx = newInvokeContext(container.$locale$, host, "qResource");
2871
- iCtx.$container$ = container;
2872
- const taskFn = task.$qrl$.getFn(iCtx, () => clearAllEffects(container, task));
2873
- const resource = task.$state$;
2874
- isDev && assertDefined(resource, 'useResource: when running a resource, "task.resource" must be a defined.', task);
2875
- const track = trackFn(task, container);
2876
- const [cleanup, cleanups] = cleanupFn(task, reason => container.handleError(reason, host));
2877
- const resourceTarget = unwrapStore(resource);
2878
- const opts = {
2879
- track,
2880
- cleanup,
2881
- cache(policy) {
2882
- let milliseconds = 0;
2883
- milliseconds = "immutable" === policy ? 1 / 0 : policy, resource._cache = milliseconds;
2884
- },
2885
- previous: resourceTarget._resolved
2886
- };
2887
- let resolve;
2888
- let reject;
2889
- let done = !1;
2890
- const currentGeneration = ++resourceTarget._generation;
2891
- const setState = (resolved, value) => !done && resourceTarget._generation === currentGeneration && (done = !0,
2892
- resolved ? (resourceTarget.loading = !1, resourceTarget._state = "resolved", resourceTarget._resolved = value,
2893
- resourceTarget._error = void 0, resolve(value)) : (resourceTarget.loading = !1,
2894
- resourceTarget._state = "rejected", resourceTarget._error = value, reject(value)),
2895
- isServerPlatform() || forceStoreEffects(resource, "_state"), !0);
2896
- cleanups.push(() => {
2897
- if (!0 === untrack(getLoading, resource)) {
2898
- const value = untrack(getResolved, resource);
2899
- setState(!0, value);
2900
- }
2901
- }), invoke(iCtx, () => {
2902
- resource._state = "pending", resource.loading = !isServerPlatform(), resource.value = new Promise((r, re) => {
2903
- resolve = r, reject = re;
2904
- });
2905
- });
2906
- const promise = safeCall(() => taskFn(opts), value => {
2907
- setState(!0, value);
2908
- }, err => {
2909
- if (isPromise(err)) {
2910
- return err.then(() => runResource(task, container, host));
2911
- }
2912
- setState(!1, err);
2913
- });
2914
- const timeout = resourceTarget._timeout;
2915
- return timeout > 0 ? Promise.race([ promise, delay(timeout).then(() => {
2916
- setState(!1, new Error("timeout")) && cleanupDestroyable(task);
2917
- }) ]) : promise;
2918
- };
2919
-
2920
2884
  function executeTasks(vNode, container, cursorData) {
2921
2885
  vNode.dirty &= -2;
2922
2886
  const elementSeq = container.getHostProp(vNode, "q:seq");
@@ -2927,15 +2891,13 @@ function executeTasks(vNode, container, cursorData) {
2927
2891
  for (const item of elementSeq) {
2928
2892
  if (item instanceof Task) {
2929
2893
  const task = item;
2930
- if (!(8 & task.$flags$)) {
2894
+ if (!(4 & task.$flags$)) {
2931
2895
  continue;
2932
2896
  }
2933
- if (4 & task.$flags$) {
2934
- runResource(task, container, vNode);
2935
- } else if (1 & task.$flags$) {
2897
+ if (1 & task.$flags$) {
2936
2898
  (cursorData.afterFlushTasks ||= []).push(task);
2937
2899
  } else {
2938
- const isRenderBlocking = !!(16 & task.$flags$);
2900
+ const isRenderBlocking = !!(8 & task.$flags$);
2939
2901
  const result = runTask(task, container, vNode);
2940
2902
  isPromise(result) && (isRenderBlocking ? taskPromise = taskPromise ? taskPromise.then(() => result) : result : (cursorData.extraPromises ||= []).push(result));
2941
2903
  }
@@ -3020,8 +2982,8 @@ function executeCleanup(vNode, container) {
3020
2982
  const elementSeq = container.getHostProp(vNode, "q:seq");
3021
2983
  if (elementSeq && 0 !== elementSeq.length) {
3022
2984
  for (const item of elementSeq) {
3023
- if (item instanceof Task && 32 & item.$flags$) {
3024
- item.$flags$ &= -33;
2985
+ if (item instanceof Task && 16 & item.$flags$) {
2986
+ item.$flags$ &= -17;
3025
2987
  cleanupDestroyable(item);
3026
2988
  }
3027
2989
  }
@@ -3067,15 +3029,16 @@ function _flushJournal(journal) {
3067
3029
  fastInsertBefore(batchParent, batchNodes[0], batchBefore);
3068
3030
  } else {
3069
3031
  const fragment = (batchParent.ownerDocument || batchParent).createDocumentFragment();
3070
- for (const node of batchNodes) {
3071
- fragment.appendChild(node);
3032
+ for (let i = 0; i < batchNodes.length; i++) {
3033
+ fragment.appendChild(batchNodes[i]);
3072
3034
  }
3073
3035
  fastInsertBefore(batchParent, fragment, batchBefore);
3074
3036
  }
3075
3037
  batchNodes = null, batchParent = null, batchBefore = null, batchSet.clear();
3076
3038
  }
3077
3039
  };
3078
- for (const operation of journal) {
3040
+ for (let i = 0; i < journal.length; i++) {
3041
+ const operation = journal[i];
3079
3042
  if (operation instanceof InsertOrMoveOperation) {
3080
3043
  if (batchParent === operation.parent && batchBefore === operation.beforeTarget) {
3081
3044
  batchNodes || (batchNodes = []), batchNodes.push(operation.target), batchSet.add(operation.target);
@@ -3260,8 +3223,7 @@ function finishWalk(container, cursor, cursorData, isServer) {
3260
3223
  }
3261
3224
 
3262
3225
  function resolveCursor(container) {
3263
- 0 === container.$cursorCount$ && 0 === container.$pausedCursorCount$ && (container.$resolveRenderPromise$(),
3264
- container.$renderPromise$ = null);
3226
+ container.$checkPendingCount$();
3265
3227
  }
3266
3228
 
3267
3229
  function partitionDirtyChildren(dirtyChildren, parent) {
@@ -3360,11 +3322,10 @@ function executeTasksChore(container, ssrNode) {
3360
3322
  for (const item of elementSeq) {
3361
3323
  if (item instanceof Task) {
3362
3324
  const task = item;
3363
- if (!(8 & task.$flags$)) {
3325
+ if (!(4 & task.$flags$)) {
3364
3326
  continue;
3365
3327
  }
3366
- let result;
3367
- result = 4 & task.$flags$ ? runResource(task, container, ssrNode) : runTask(task, container, ssrNode),
3328
+ const result = runTask(task, container, ssrNode);
3368
3329
  promise = promise ? promise.then(() => result) : result;
3369
3330
  }
3370
3331
  }
@@ -3631,6 +3592,14 @@ function registerQrlHandlers(attr, key, container, element) {
3631
3592
  (element._qDispatch ||= {})[scopedKebabName] = handlers;
3632
3593
  }
3633
3594
 
3595
+ function vnode_walkDirectChildren(journal, vParent, callback) {
3596
+ let vNode = vnode_getFirstChild(vParent);
3597
+ for (;vNode; ) {
3598
+ vnode_isTextVNode(vNode) ? (vnode_ensureTextInflated(journal, vNode), callback(vNode, vParent)) : vnode_isElementVNode(vNode) ? callback(vNode, vParent) : vnode_walkDirectChildren(journal, vNode, callback),
3599
+ vNode = vNode.nextSibling;
3600
+ }
3601
+ }
3602
+
3634
3603
  function vnode_walkVNode(vNode, callback) {
3635
3604
  let vCursor = vNode;
3636
3605
  if (vnode_isTextVNode(vNode)) {
@@ -3671,29 +3640,12 @@ function vnode_walkVNode(vNode, callback) {
3671
3640
  }
3672
3641
  }
3673
3642
 
3674
- function vnode_getDOMChildNodes(journal, root, isVNode = !1, childNodes = []) {
3675
- if (vnode_isElementOrTextVNode(root)) {
3676
- return vnode_isTextVNode(root) && vnode_ensureTextInflated(journal, root), childNodes.push(isVNode ? root : vnode_getNode(root)),
3677
- childNodes;
3678
- }
3679
- let vNode = vnode_getFirstChild(root);
3680
- for (;vNode; ) {
3681
- vnode_isElementVNode(vNode) ? childNodes.push(isVNode ? vNode : vnode_getNode(vNode)) : vnode_isTextVNode(vNode) ? (vnode_ensureTextInflated(journal, vNode),
3682
- childNodes.push(isVNode ? vNode : vnode_getNode(vNode))) : vnode_getDOMChildNodes(journal, vNode, !!isVNode, childNodes),
3683
- vNode = vNode.nextSibling;
3684
- }
3685
- return childNodes;
3686
- }
3687
-
3688
3643
  function vnode_getDOMContainer(vNode) {
3689
3644
  let cursor = vNode;
3690
3645
  for (;cursor; ) {
3691
3646
  if (vnode_isElementVNode(cursor)) {
3692
- try {
3693
- return getDomContainer(cursor.node);
3694
- } catch {
3695
- return null;
3696
- }
3647
+ const qContainerElement = _getQContainerElement(cursor.node);
3648
+ return qContainerElement ? getDomContainerFromQContainerElement(qContainerElement) : null;
3697
3649
  }
3698
3650
  cursor = cursor.parent;
3699
3651
  }
@@ -3878,13 +3830,24 @@ const vnode_createErrorDiv = (journal, document, host, err) => {
3878
3830
  error: err
3879
3831
  }), errorDiv.setAttribute("q:key", "_error_");
3880
3832
  const vErrorDiv = vnode_newElement(errorDiv, "errored-host");
3881
- return vnode_getDOMChildNodes(journal, host, !0).forEach(child => {
3882
- vnode_insertBefore(journal, vErrorDiv, child, null);
3883
- }), vErrorDiv;
3833
+ if (vnode_isElementOrTextVNode(host)) {
3834
+ vnode_insertBefore(journal, vErrorDiv, host, null);
3835
+ } else {
3836
+ const children = [];
3837
+ vnode_walkDirectChildren(journal, host, vNode => {
3838
+ children.push(vNode);
3839
+ });
3840
+ for (let i = 0; i < children.length; i++) {
3841
+ vnode_insertBefore(journal, vErrorDiv, children[i], null);
3842
+ }
3843
+ }
3844
+ return vErrorDiv;
3884
3845
  };
3885
3846
 
3886
- const vnode_insertBefore = (journal, parent, newChild, insertBefore) => {
3887
- ensureElementOrVirtualVNode(parent), vnode_isElementVNode(parent) && ensureMaterialized(parent);
3847
+ const vnode_insertElementBefore = (journal, parent, newChild, insertBefore) => {
3848
+ ensureElementOrVirtualVNode(parent);
3849
+ const parentIsElement = vnode_isElementVNode(parent);
3850
+ parentIsElement && ensureMaterialized(parent);
3888
3851
  const newChildCurrentParent = newChild.parent;
3889
3852
  if (newChild === insertBefore) {
3890
3853
  if (newChildCurrentParent) {
@@ -3892,25 +3855,73 @@ const vnode_insertBefore = (journal, parent, newChild, insertBefore) => {
3892
3855
  }
3893
3856
  insertBefore = null;
3894
3857
  }
3895
- const domParentVNode = vnode_getDomParentVNode(parent, !1);
3896
- const parentNode = domParentVNode && domParentVNode.node;
3897
- let domChildren = null;
3898
- domParentVNode && (domChildren = vnode_getDomChildrenWithCorrectNamespacesToInsert(journal, domParentVNode, newChild)),
3899
- newChildCurrentParent && (newChild.previousSibling || newChild.nextSibling || newChildCurrentParent !== parent) && vnode_remove(journal, newChildCurrentParent, newChild, !1);
3858
+ vnode_unlinkFromOldParent(journal, newChildCurrentParent, parent, newChild);
3859
+ const childNode = newChild.node;
3900
3860
  const parentIsDeleted = 32 & parent.flags;
3901
- let adjustedInsertBefore = null;
3902
- if (!parentIsDeleted && (null == insertBefore ? vnode_isVirtualVNode(parent) && (adjustedInsertBefore = vnode_getDomSibling(parent, !0, !1)) : adjustedInsertBefore = vnode_isVirtualVNode(insertBefore) ? vnode_getDomSibling(insertBefore, !0, !0) : insertBefore,
3903
- adjustedInsertBefore && vnode_ensureInflatedIfText(journal, adjustedInsertBefore),
3904
- domChildren && domChildren.length)) {
3905
- for (const child of domChildren) {
3906
- addVNodeOperation(journal, createInsertOrMoveOperation(child.node, parentNode, vnode_getNode(adjustedInsertBefore)));
3861
+ const parentNode = parentIsElement ? parent.node : vnode_getDomParent(parent, !1);
3862
+ parentNode && !parentIsDeleted && addVNodeOperation(journal, createInsertOrMoveOperation(childNode, parentNode, vnode_findInsertBefore(journal, parent, insertBefore)?.node ?? null)),
3863
+ vnode_connectSiblings(parent, newChild, insertBefore), parentIsDeleted && (newChild.flags |= 32);
3864
+ };
3865
+
3866
+ const vnode_insertVirtualBefore = (journal, parent, newChild, insertBefore) => {
3867
+ ensureElementOrVirtualVNode(parent);
3868
+ const parentIsElement = vnode_isElementVNode(parent);
3869
+ parentIsElement && ensureMaterialized(parent);
3870
+ const newChildCurrentParent = newChild.parent;
3871
+ if (newChild === insertBefore) {
3872
+ if (newChildCurrentParent) {
3873
+ return;
3907
3874
  }
3875
+ insertBefore = null;
3876
+ }
3877
+ vnode_unlinkFromOldParent(journal, newChildCurrentParent, parent, newChild);
3878
+ const parentIsDeleted = 32 & parent.flags;
3879
+ const domParentVNode = parentIsElement ? parent : vnode_getDomParentVNode(parent, !1);
3880
+ const parentNode = domParentVNode?.node;
3881
+ const adjustedInsertBefore = vnode_findInsertBefore(journal, parent, insertBefore);
3882
+ const adjustedInsertBeforeNode = adjustedInsertBefore?.node ?? null;
3883
+ if (vnode_isProjection(newChild) && domParentVNode && 1536 & domParentVNode.flags) {
3884
+ const domParentVNode = vnode_getDomParentVNode(parent, !1);
3885
+ const adjustedInsertBeforeNode = vnode_findInsertBefore(journal, parent, insertBefore)?.node ?? null;
3886
+ const {elementNamespace, elementNamespaceFlag} = getNewElementNamespaceData(domParentVNode, newChild);
3887
+ vnode_walkDirectChildren(journal, newChild, vNode => {
3888
+ if (vnode_isTextVNode(vNode)) {
3889
+ addVNodeOperation(journal, createInsertOrMoveOperation(vNode.node, parentNode, adjustedInsertBeforeNode));
3890
+ } else {
3891
+ if ((1536 & vNode.flags) !== elementNamespaceFlag) {
3892
+ const newChildElement = vnode_cloneElementWithNamespace(vNode, domParentVNode, elementNamespace, elementNamespaceFlag);
3893
+ newChildElement && (vNode.node = newChildElement);
3894
+ }
3895
+ addVNodeOperation(journal, createInsertOrMoveOperation(vNode.node, parentNode, adjustedInsertBeforeNode));
3896
+ }
3897
+ });
3898
+ } else {
3899
+ parentNode && !parentIsDeleted && vnode_walkDirectChildren(journal, newChild, vNode => {
3900
+ addVNodeOperation(journal, createInsertOrMoveOperation(vNode.node, parentNode, adjustedInsertBeforeNode));
3901
+ });
3908
3902
  }
3909
- const vNext = insertBefore;
3903
+ vnode_connectSiblings(parent, newChild, insertBefore), parentIsDeleted && (newChild.flags |= 32);
3904
+ };
3905
+
3906
+ const vnode_findInsertBefore = (journal, parent, insertBefore) => {
3907
+ let adjustedInsertBefore = null;
3908
+ return null == insertBefore ? vnode_isVirtualVNode(parent) && (adjustedInsertBefore = vnode_getDomSibling(parent, !0, !1)) : adjustedInsertBefore = vnode_isVirtualVNode(insertBefore) ? vnode_getDomSibling(insertBefore, !0, !0) : insertBefore,
3909
+ adjustedInsertBefore && vnode_ensureInflatedIfText(journal, adjustedInsertBefore),
3910
+ adjustedInsertBefore;
3911
+ };
3912
+
3913
+ const vnode_connectSiblings = (parent, vNode, vNext) => {
3910
3914
  const vPrevious = vNext ? vNext.previousSibling : parent.lastChild;
3911
- vNext ? vNext.previousSibling = newChild : parent.lastChild = newChild, vPrevious ? vPrevious.nextSibling = newChild : parent.firstChild = newChild,
3912
- newChild.previousSibling = vPrevious, newChild.nextSibling = vNext, newChild.parent = parent,
3913
- parentIsDeleted && (newChild.flags |= 32);
3915
+ vNext ? vNext.previousSibling = vNode : parent.lastChild = vNode, vPrevious ? vPrevious.nextSibling = vNode : parent.firstChild = vNode,
3916
+ vNode.previousSibling = vPrevious, vNode.nextSibling = vNext, vNode.parent = parent;
3917
+ };
3918
+
3919
+ const vnode_unlinkFromOldParent = (journal, currentParent, newParent, newChild) => {
3920
+ currentParent && (newChild.previousSibling || newChild.nextSibling || currentParent !== newParent) && vnode_remove(journal, currentParent, newChild, !1);
3921
+ };
3922
+
3923
+ const vnode_insertBefore = (journal, parent, newChild, insertBefore) => {
3924
+ vnode_isElementOrTextVNode(newChild) ? vnode_insertElementBefore(journal, parent, newChild, insertBefore) : vnode_insertVirtualBefore(journal, parent, newChild, insertBefore);
3914
3925
  };
3915
3926
 
3916
3927
  const vnode_getDomParent = (vnode, includeProjection) => (vnode = vnode_getDomParentVNode(vnode, includeProjection)) && vnode.node;
@@ -3925,16 +3936,12 @@ const vnode_getDomParentVNode = (vnode, includeProjection) => {
3925
3936
  const vnode_remove = (journal, vParent, vToRemove, removeDOM) => {
3926
3937
  if (isDev && assertEqual(vParent, vToRemove.parent, "Parent mismatch."), vnode_isTextVNode(vToRemove) && vnode_ensureTextInflated(journal, vToRemove),
3927
3938
  removeDOM) {
3928
- const domParent = vnode_getDomParent(vParent, !1);
3929
3939
  if (null !== vnode_getProp(vParent, dangerouslySetInnerHTML, null)) {
3930
3940
  return;
3931
3941
  }
3932
- const children = vnode_getDOMChildNodes(journal, vToRemove, !0);
3933
- if (domParent && children.length) {
3934
- for (const child of children) {
3935
- addVNodeOperation(journal, createDeleteOperation(child.node));
3936
- }
3937
- }
3942
+ vnode_isElementOrTextVNode(vToRemove) ? addVNodeOperation(journal, createDeleteOperation(vToRemove.node)) : vnode_walkDirectChildren(journal, vToRemove, vNode => {
3943
+ addVNodeOperation(journal, createDeleteOperation(vNode.node));
3944
+ });
3938
3945
  }
3939
3946
  const vPrevious = vToRemove.previousSibling;
3940
3947
  const vNext = vToRemove.nextSibling;
@@ -3944,18 +3951,9 @@ const vnode_remove = (journal, vParent, vToRemove, removeDOM) => {
3944
3951
 
3945
3952
  const vnode_truncate = (journal, vParent, vDelete, removeDOM = !0) => {
3946
3953
  isDev && assertDefined(vDelete, "Missing vDelete.");
3947
- if (vnode_getDomParent(vParent, !0) && removeDOM) {
3948
- if (vnode_isElementVNode(vParent)) {
3949
- addVNodeOperation(journal, createRemoveAllChildrenOperation(vParent.node));
3950
- } else {
3951
- const children = vnode_getDOMChildNodes(journal, vParent, !0);
3952
- if (children.length) {
3953
- for (const child of children) {
3954
- addVNodeOperation(journal, createDeleteOperation(child.node));
3955
- }
3956
- }
3957
- }
3958
- }
3954
+ vnode_getDomParent(vParent, !0) && removeDOM && (vnode_isElementOrTextVNode(vParent) ? addVNodeOperation(journal, createRemoveAllChildrenOperation(vParent.node)) : vnode_walkDirectChildren(journal, vParent, vNode => {
3955
+ addVNodeOperation(journal, createDeleteOperation(vNode.node));
3956
+ }));
3959
3957
  const vPrevious = vDelete.previousSibling;
3960
3958
  vPrevious ? vPrevious.nextSibling = null : vParent.firstChild = null, vParent.lastChild = vPrevious;
3961
3959
  };
@@ -4203,7 +4201,7 @@ const vnode_getAttrKeys = (container, vnode) => {
4203
4201
  const keys = [];
4204
4202
  const props = vnode.props;
4205
4203
  if (props) {
4206
- for (const key of Object.keys(props)) {
4204
+ for (const key in props) {
4207
4205
  key.startsWith(":") || keys.push(key);
4208
4206
  }
4209
4207
  }
@@ -4227,7 +4225,12 @@ const vnode_getProjectionParentOrParent = vnode => vnode.parent || vnode.slotPar
4227
4225
 
4228
4226
  const vnode_getNode = vnode => null === vnode || vnode_isVirtualVNode(vnode) ? null : vnode.node;
4229
4227
 
4230
- function vnode_toString(depth = 20, offset = "", materialize = !1, siblings = !1, colorize = !0, container = this && vnode_getDOMContainer(this)) {
4228
+ function vnode_toString(depth = 20, offset = "", materialize = !1, siblings = !1, colorize = !0, container = null) {
4229
+ if (this && !container) {
4230
+ try {
4231
+ container = vnode_getDOMContainer(this);
4232
+ } catch {}
4233
+ }
4231
4234
  let vnode = this;
4232
4235
  if (0 === depth) {
4233
4236
  return "...";
@@ -4244,7 +4247,7 @@ function vnode_toString(depth = 20, offset = "", materialize = !1, siblings = !1
4244
4247
  strings.push(qwikDebugToString(vnode_getText(vnode)));
4245
4248
  } else if (vnode_isVirtualVNode(vnode)) {
4246
4249
  const attrs = [ "[" + String(vnode.flags >>> 11) + "]" ];
4247
- vnode.dirty && attrs.push(` dirty:${vnode.dirty}`), vnode_getAttrKeys(container, vnode).forEach(key => {
4250
+ vnode.dirty && attrs.push(` dirty:${vnode.dirty}`), container && vnode_getAttrKeys(container, vnode).forEach(key => {
4248
4251
  if ("q:type" !== key && "__scopedStyleIdPrefix__" !== key) {
4249
4252
  const value = vnode_getProp(vnode, key, null);
4250
4253
  attrs.push(" " + key + "=" + qwikDebugToString(value));
@@ -4260,7 +4263,7 @@ function vnode_toString(depth = 20, offset = "", materialize = !1, siblings = !1
4260
4263
  const attrs = [];
4261
4264
  isCursor(vnode) && attrs.push(" cursor"), vnode.dirty && attrs.push(` dirty:${vnode.dirty}`),
4262
4265
  vnode.dirtyChildren && attrs.push(` dirtyChildren[${vnode.dirtyChildren.length}]`);
4263
- const keys = vnode_getAttrKeys(container, vnode);
4266
+ const keys = container ? vnode_getAttrKeys(container, vnode) : [];
4264
4267
  for (const key of keys) {
4265
4268
  const value = vnode_getProp(vnode, key, null);
4266
4269
  attrs.push(" " + key + "=" + qwikDebugToString(value));
@@ -4386,8 +4389,8 @@ function materializeFromVNodeData(vParent, vData, element, child) {
4386
4389
  }
4387
4390
  }), components) {
4388
4391
  container || (container = getDomContainer(element));
4389
- for (const component of components) {
4390
- container.ensureProjectionResolved(component);
4392
+ for (let i = 0; i < components.length; i++) {
4393
+ container.ensureProjectionResolved(components[i]);
4391
4394
  }
4392
4395
  components = null;
4393
4396
  }
@@ -4489,16 +4492,6 @@ const useInvokeContext = () => {
4489
4492
  ctx;
4490
4493
  };
4491
4494
 
4492
- function useBindInvokeContext(fn) {
4493
- if (null == fn) {
4494
- return fn;
4495
- }
4496
- const ctx = getInvokeContext();
4497
- return function(...args) {
4498
- return invokeApply.call(this, ctx, fn, args);
4499
- };
4500
- }
4501
-
4502
4495
  function invoke(context, fn, ...args) {
4503
4496
  return invokeApply.call(this, context, fn, args);
4504
4497
  }
@@ -4568,7 +4561,7 @@ const trackSignal = (fn, subscriber, property, container, data) => {
4568
4561
  const previousContainer = trackInvocation.$container$;
4569
4562
  try {
4570
4563
  return trackInvocation.$effectSubscriber$ = getSubscriber(subscriber, property, data),
4571
- trackInvocation.$container$ = container, invoke(trackInvocation, fn);
4564
+ trackInvocation.$container$ = container, invokeApply(trackInvocation, fn);
4572
4565
  } finally {
4573
4566
  trackInvocation.$effectSubscriber$ = previousSubscriber, trackInvocation.$container$ = previousContainer;
4574
4567
  }
@@ -4597,6 +4590,23 @@ const _jsxBranch = input => input;
4597
4590
 
4598
4591
  const _waitUntilRendered = container => container.$renderPromise$ || Promise.resolve();
4599
4592
 
4593
+ const useSequentialScope = () => {
4594
+ const iCtx = useInvokeContext();
4595
+ const host = iCtx.$hostElement$;
4596
+ let seq = iCtx.$container$.getHostProp(host, "q:seq");
4597
+ null === seq && (seq = [], iCtx.$container$.setHostProp(host, "q:seq", seq));
4598
+ let seqIdx = iCtx.$container$.getHostProp(host, "q:seqIdx");
4599
+ for (null === seqIdx && (seqIdx = 0), iCtx.$container$.setHostProp(host, "q:seqIdx", seqIdx + 1); seq.length <= seqIdx; ) {
4600
+ seq.push(void 0);
4601
+ }
4602
+ return {
4603
+ val: seq[seqIdx],
4604
+ set: value => seq[seqIdx] = value,
4605
+ i: seqIdx,
4606
+ iCtx
4607
+ };
4608
+ };
4609
+
4600
4610
  const createContextId = name => (isDev && assertTrue(/^[\w/.-]+$/.test(name), "Context name must only contain A-Z,a-z,0-9,_,.,-", name),
4601
4611
  /*#__PURE__*/ Object.freeze({
4602
4612
  id: fromCamelToKebabCase(name)
@@ -4648,7 +4658,7 @@ const _constants = [ void 0, null, !0, !1, "", EMPTY_ARRAY, EMPTY_OBJ, NEEDS_COM
4648
4658
 
4649
4659
  const _constantNames = [ "undefined", "null", "true", "false", "''", "EMPTY_ARRAY", "EMPTY_OBJ", "NEEDS_COMPUTATION", "STORE_ALL_PROPS", "_UNINITIALIZED", "Slot", "Fragment", "NaN", "Infinity", "-Infinity", "MAX_SAFE_INTEGER", "MAX_SAFE_INTEGER-1", "MIN_SAFE_INTEGER" ];
4650
4660
 
4651
- const _typeIdNames = [ "Plain", "RootRef", "ForwardRef", "Constant", "Array", "Object", "URL", "Date", "Regex", "QRL", "VNode", "RefVNode", "BigInt", "URLSearchParams", "ForwardRefs", "Error", "Promise", "Set", "Map", "Uint8Array", "Task", "Resource", "Component", "Signal", "WrappedSignal", "ComputedSignal", "AsyncSignal", "SerializerSignal", "Store", "FormData", "JSXNode", "PropsProxy", "SubscriptionData", "EffectSubscription" ];
4661
+ const _typeIdNames = [ "Plain", "RootRef", "ForwardRef", "Constant", "Array", "Object", "URL", "Date", "Regex", "QRL", "VNode", "RefVNode", "BigInt", "URLSearchParams", "ForwardRefs", "Error", "Promise", "Set", "Map", "Uint8Array", "Task", "Component", "Signal", "WrappedSignal", "ComputedSignal", "AsyncSignal", "SerializerSignal", "Store", "FormData", "JSXNode", "PropsProxy", "SubscriptionData", "EffectSubscription" ];
4652
4662
 
4653
4663
  function qrlToString(serializationContext, qrl, raw) {
4654
4664
  let symbol = qrl.$symbol$;
@@ -4745,12 +4755,6 @@ const allocate = (container, typeId, value) => {
4745
4755
  case 20:
4746
4756
  return new Task(-1, -1, null, null, null, null);
4747
4757
 
4748
- case 21:
4749
- {
4750
- const res = createResourceReturn(container, void 0, void 0);
4751
- return res.loading = !1, res;
4752
- }
4753
-
4754
4758
  case 6:
4755
4759
  return new URL(value);
4756
4760
 
@@ -4764,25 +4768,27 @@ const allocate = (container, typeId, value) => {
4764
4768
  case 15:
4765
4769
  return new Error;
4766
4770
 
4767
- case 22:
4771
+ case 21:
4768
4772
  return componentQrl(null);
4769
4773
 
4770
- case 23:
4774
+ case 22:
4771
4775
  return new SignalImpl(container, 0);
4772
4776
 
4773
- case 24:
4777
+ case 23:
4774
4778
  return new WrappedSignalImpl(container, null, null, null);
4775
4779
 
4776
- case 25:
4780
+ case 24:
4777
4781
  return new ComputedSignalImpl(container, null);
4778
4782
 
4779
- case 26:
4780
- return new AsyncSignalImpl(container, null);
4783
+ case 25:
4784
+ return new AsyncSignalImpl(container, null, void 0, {
4785
+ interval: 0
4786
+ });
4781
4787
 
4782
- case 27:
4788
+ case 26:
4783
4789
  return new SerializerSignalImpl(container, null);
4784
4790
 
4785
- case 28:
4791
+ case 27:
4786
4792
  {
4787
4793
  const data = value;
4788
4794
  const t = data[0];
@@ -4798,10 +4804,10 @@ const allocate = (container, typeId, value) => {
4798
4804
  case 13:
4799
4805
  return new URLSearchParams(value);
4800
4806
 
4801
- case 29:
4807
+ case 28:
4802
4808
  return new FormData;
4803
4809
 
4804
- case 30:
4810
+ case 29:
4805
4811
  return new JSXNodeImpl(null, null, null, null, null);
4806
4812
 
4807
4813
  case 12:
@@ -4826,7 +4832,7 @@ const allocate = (container, typeId, value) => {
4826
4832
  const rest = 3 & encodedLength;
4827
4833
  return new Uint8Array(3 * (encodedLength >>> 2) + (rest ? rest - 1 : 0));
4828
4834
 
4829
- case 31:
4835
+ case 30:
4830
4836
  return createPropsProxy(null);
4831
4837
 
4832
4838
  case 10:
@@ -4839,10 +4845,10 @@ const allocate = (container, typeId, value) => {
4839
4845
  }
4840
4846
  throw qError(17, [ typeof vNode ]);
4841
4847
 
4842
- case 32:
4848
+ case 31:
4843
4849
  return new SubscriptionData({});
4844
4850
 
4845
- case 33:
4851
+ case 32:
4846
4852
  return new EffectSubscription(null, null, null, null);
4847
4853
 
4848
4854
  default:
@@ -5040,7 +5046,7 @@ async function serialize(serializationContext) {
5040
5046
  }
5041
5047
  {
5042
5048
  const [qrl] = value[SERIALIZABLE_STATE];
5043
- serializationContext.$renderSymbols$.add(qrl.$symbol$), output(22, [ qrl ]);
5049
+ serializationContext.$renderSymbols$.add(qrl.$symbol$), output(21, [ qrl ]);
5044
5050
  }
5045
5051
  }
5046
5052
  break;
@@ -5071,36 +5077,30 @@ async function serialize(serializationContext) {
5071
5077
  const writeObjectValue = value => {
5072
5078
  if (isPropsProxy(value)) {
5073
5079
  const owner = value[_OWNER];
5074
- output(31, [ _serializationWeakRef(owner), owner.varProps, owner.constProps, value[_PROPS_HANDLER].$effects$ ]);
5080
+ output(30, [ _serializationWeakRef(owner), owner.varProps, owner.constProps, value[_PROPS_HANDLER].$effects$ ]);
5075
5081
  } else if (value instanceof SubscriptionData) {
5076
- output(32, [ value.data.$scopedStyleIdPrefix$, value.data.$isConst$ ]);
5082
+ output(31, [ value.data.$scopedStyleIdPrefix$, value.data.$isConst$ ]);
5077
5083
  } else if (value instanceof EffectSubscription) {
5078
- output(33, [ value.consumer, value.property, value.backRef, value.data ]);
5084
+ output(32, [ value.consumer, value.property, value.backRef, value.data ]);
5079
5085
  } else if (isStore(value)) {
5080
- if (isResource(value)) {
5081
- serializationContext.$resources$.add(value);
5082
- const forwardRefId = resolvePromise(value.value, $addRoot$, (resolved, resolvedValue) => new PromiseResult(21, resolved, resolvedValue, getStoreHandler(value).$effects$));
5083
- output(2, forwardRefId);
5084
- } else {
5085
- const storeHandler = getStoreHandler(value);
5086
- const storeTarget = getStoreTarget(value);
5087
- const flags = storeHandler.$flags$;
5088
- const effects = storeHandler.$effects$;
5089
- const innerStores = [];
5090
- for (const prop in storeTarget) {
5091
- const innerStore = $storeProxyMap$.get(storeTarget[prop]);
5092
- innerStore && innerStores.push(innerStore);
5093
- }
5094
- const out = [ storeTarget, flags, effects, ...innerStores ];
5095
- for (;void 0 === out[out.length - 1]; ) {
5096
- out.pop();
5097
- }
5098
- output(28, out);
5086
+ const storeHandler = getStoreHandler(value);
5087
+ const storeTarget = getStoreTarget(value);
5088
+ const flags = storeHandler.$flags$;
5089
+ const effects = storeHandler.$effects$;
5090
+ const innerStores = [];
5091
+ for (const prop in storeTarget) {
5092
+ const innerStore = $storeProxyMap$.get(storeTarget[prop]);
5093
+ innerStore && innerStores.push(innerStore);
5094
+ }
5095
+ const out = [ storeTarget, flags, effects, ...innerStores ];
5096
+ for (;void 0 === out[out.length - 1]; ) {
5097
+ out.pop();
5099
5098
  }
5099
+ output(27, out);
5100
5100
  } else if (isSerializerObj(value)) {
5101
5101
  const result = value[SerializerSymbol](value);
5102
5102
  if (isPromise(result)) {
5103
- const forwardRef = resolvePromise(result, $addRoot$, (resolved, resolvedValue) => new PromiseResult(27, resolved, resolvedValue, void 0, void 0));
5103
+ const forwardRef = resolvePromise(result, $addRoot$, (resolved, resolvedValue) => new PromiseResult(26, resolved, resolvedValue, void 0, void 0));
5104
5104
  output(2, forwardRef);
5105
5105
  } else {
5106
5106
  const index = parent.$index$;
@@ -5125,33 +5125,38 @@ async function serialize(serializationContext) {
5125
5125
  if (value instanceof SerializerSignalImpl) {
5126
5126
  const maybeValue = getCustomSerializerPromise(value, value.$untrackedValue$);
5127
5127
  if (isPromise(maybeValue)) {
5128
- const forwardRefId = resolvePromise(maybeValue, $addRoot$, (resolved, resolvedValue) => new PromiseResult(27, resolved, resolvedValue, value.$effects$, value.$computeQrl$));
5128
+ const forwardRefId = resolvePromise(maybeValue, $addRoot$, (resolved, resolvedValue) => new PromiseResult(26, resolved, resolvedValue, value.$effects$, value.$computeQrl$));
5129
5129
  output(2, forwardRefId);
5130
5130
  } else {
5131
- output(27, [ value.$computeQrl$, filterEffectBackRefs(value[_EFFECT_BACK_REF]), value.$effects$, maybeValue ]);
5131
+ output(26, [ value.$computeQrl$, filterEffectBackRefs(value[_EFFECT_BACK_REF]), value.$effects$, maybeValue ]);
5132
5132
  }
5133
5133
  return;
5134
5134
  }
5135
5135
  if (value instanceof WrappedSignalImpl) {
5136
- output(24, [ ...serializeWrappingFn(serializationContext, value), filterEffectBackRefs(value[_EFFECT_BACK_REF]), value.$flags$, value.$hostElement$, ...value.$effects$ || [] ]);
5136
+ output(23, [ ...serializeWrappingFn(serializationContext, value), filterEffectBackRefs(value[_EFFECT_BACK_REF]), value.$flags$, value.$hostElement$, ...value.$effects$ || [] ]);
5137
5137
  } else if (value instanceof ComputedSignalImpl) {
5138
5138
  let v = value.$untrackedValue$;
5139
5139
  const shouldAlwaysSerialize = 16 & value.$flags$;
5140
5140
  const shouldNeverSerialize = 8 & value.$flags$;
5141
5141
  const isInvalid = 1 & value.$flags$;
5142
5142
  const isSkippable = fastSkipSerialize(value.$untrackedValue$);
5143
- shouldAlwaysSerialize ? v = value.$untrackedValue$ : (shouldNeverSerialize || isInvalid || isSkippable) && (v = NEEDS_COMPUTATION);
5144
- const out = [ value.$computeQrl$, filterEffectBackRefs(value[_EFFECT_BACK_REF]), value.$effects$ ];
5145
5143
  const isAsync = value instanceof AsyncSignalImpl;
5146
- isAsync && out.push(value.$loadingEffects$, value.$errorEffects$, value.$untrackedLoading$, value.$untrackedError$);
5144
+ const interval = isAsync && value.$interval$ > 0 ? value.$interval$ : void 0;
5145
+ const concurrency = isAsync && 1 !== value.$concurrency$ ? value.$concurrency$ : void 0;
5146
+ const timeout = isAsync && 0 !== value.$timeoutMs$ ? value.$timeoutMs$ : void 0;
5147
+ const eagerCleanup = !!(isAsync && 32 & value.$flags$) || void 0;
5148
+ isInvalid || isSkippable ? v = NEEDS_COMPUTATION : shouldAlwaysSerialize ? v = value.$untrackedValue$ : shouldNeverSerialize && (v = NEEDS_COMPUTATION);
5149
+ const out = [ value.$computeQrl$, filterEffectBackRefs(value[_EFFECT_BACK_REF]), value.$effects$ ];
5150
+ isAsync && out.push(value.$loadingEffects$, value.$errorEffects$, value.$untrackedError$);
5147
5151
  let keepUndefined = !1;
5148
- v !== NEEDS_COMPUTATION && (out.push(v), isAsync || void 0 !== v || (keepUndefined = !0)),
5149
- output(isAsync ? 26 : 25, out, keepUndefined);
5152
+ v === NEEDS_COMPUTATION && void 0 === interval && void 0 === concurrency && void 0 === timeout || (out.push(v),
5153
+ void 0 === v && (keepUndefined = !0)), isAsync && (out.push(interval), out.push(concurrency),
5154
+ out.push(timeout), out.push(eagerCleanup)), output(isAsync ? 25 : 24, out, keepUndefined);
5150
5155
  } else {
5151
5156
  const v = value.$untrackedValue$;
5152
5157
  const keepUndefined = void 0 === v;
5153
5158
  const out = [ v ];
5154
- value.$effects$ && out.push(...value.$effects$), output(23, out, keepUndefined);
5159
+ value.$effects$ && out.push(...value.$effects$), output(22, out, keepUndefined);
5155
5160
  }
5156
5161
  } else if (value instanceof URL) {
5157
5162
  output(6, value.href);
@@ -5186,7 +5191,7 @@ async function serialize(serializationContext) {
5186
5191
  const array = [];
5187
5192
  value.forEach((value, key) => {
5188
5193
  array.push(key, "string" == typeof value ? value : value.name);
5189
- }), output(29, array);
5194
+ }), output(28, array);
5190
5195
  } else if (value instanceof URLSearchParams) {
5191
5196
  output(13, value.toString());
5192
5197
  } else if (value instanceof Set) {
@@ -5202,7 +5207,7 @@ async function serialize(serializationContext) {
5202
5207
  for (;void 0 === out[out.length - 1]; ) {
5203
5208
  out.pop();
5204
5209
  }
5205
- output(30, out);
5210
+ output(29, out);
5206
5211
  } else if (value instanceof Task) {
5207
5212
  const out = [ value.$qrl$, value.$flags$, value.$index$, value.$el$, value[_EFFECT_BACK_REF], value.$state$ ];
5208
5213
  for (;void 0 === out[out.length - 1]; ) {
@@ -5213,11 +5218,9 @@ async function serialize(serializationContext) {
5213
5218
  const forwardRefId = resolvePromise(value, $addRoot$, (resolved, resolvedValue) => new PromiseResult(16, resolved, resolvedValue));
5214
5219
  output(2, forwardRefId);
5215
5220
  } else if (value instanceof PromiseResult) {
5216
- if (21 === value.$type$) {
5217
- output(21, [ value.$resolved$, value.$value$, value.$effects$ ]);
5218
- } else if (27 === value.$type$) {
5221
+ if (26 === value.$type$) {
5219
5222
  if (value.$qrl$) {
5220
- output(27, [ value.$qrl$, value.$effects$, value.$value$ ]);
5223
+ output(26, [ value.$qrl$, value.$effects$, value.$value$ ]);
5221
5224
  } else {
5222
5225
  if (!value.$resolved$) {
5223
5226
  throw console.error(value.$value$), qError(33);
@@ -5329,10 +5332,6 @@ function isObjectLiteral(obj) {
5329
5332
  return null == prototype || prototype === Object.prototype || prototype === Array.prototype;
5330
5333
  }
5331
5334
 
5332
- function isResource(value) {
5333
- return "__brand" in value && "resource" === value.__brand;
5334
- }
5335
-
5336
5335
  function serializeWrappingFn(serializationContext, value) {
5337
5336
  value.$funcStr$ && "{" === value.$funcStr$[0] && (value.$funcStr$ = `(${value.$funcStr$})`);
5338
5337
  return [ serializationContext.$addSyncFn$(value.$funcStr$, value.$args$.length, value.$func$), value.$args$ ];
@@ -5378,6 +5377,7 @@ const createSerializationContext = (NodeConstructor, DomRefConstructor, symbolTo
5378
5377
  const syncFnMap = new Map;
5379
5378
  const syncFns = [];
5380
5379
  const roots = [];
5380
+ const eagerResume = new Set;
5381
5381
  const $promoteToRoot$ = (ref, index) => {
5382
5382
  const path = (ref => {
5383
5383
  const path = [];
@@ -5441,9 +5441,10 @@ const createSerializationContext = (NodeConstructor, DomRefConstructor, symbolTo
5441
5441
  $writer$: writer,
5442
5442
  $eventQrls$: new Set,
5443
5443
  $eventNames$: new Set,
5444
- $resources$: new Set,
5445
5444
  $renderSymbols$: new Set,
5446
5445
  $storeProxyMap$: storeProxyMap,
5446
+ $eagerResume$: eagerResume,
5447
+ $resources$: new Set,
5447
5448
  $getProp$: getProp,
5448
5449
  $setProp$: setProp
5449
5450
  };
@@ -5460,8 +5461,7 @@ class _SharedContainer {
5460
5461
  $buildBase$=null;
5461
5462
  $renderPromise$=null;
5462
5463
  $resolveRenderPromise$=null;
5463
- $cursorCount$=0;
5464
- $pausedCursorCount$=0;
5464
+ $pendingCount$=0;
5465
5465
  constructor(serverData, locale) {
5466
5466
  this.$serverData$ = serverData, this.$locale$ = locale, this.$version$ = version,
5467
5467
  this.$storeProxyMap$ = new WeakMap, this.$getObjectById$ = () => {
@@ -5474,6 +5474,9 @@ class _SharedContainer {
5474
5474
  serializationCtxFactory(NodeConstructor, DomRefConstructor, symbolToChunkResolver, writer) {
5475
5475
  return createSerializationContext(NodeConstructor, DomRefConstructor, symbolToChunkResolver, this.getHostProp.bind(this), this.setHostProp.bind(this), this.$storeProxyMap$, writer);
5476
5476
  }
5477
+ $checkPendingCount$() {
5478
+ 0 === this.$pendingCount$ && (this.$resolveRenderPromise$?.(), this.$renderPromise$ = null);
5479
+ }
5477
5480
  }
5478
5481
 
5479
5482
  function isAsyncGenerator(value) {
@@ -5550,7 +5553,7 @@ function processJSXNode(ssr, enqueue, value, options) {
5550
5553
  enqueue(value[i]);
5551
5554
  }
5552
5555
  } else if (isSignal(value)) {
5553
- ssr.openFragment(isDev ? [ "q:type", "S" ] : EMPTY_ARRAY);
5556
+ maybeAddPollingAsyncSignalToEagerResume(ssr.serializationCtx, value), ssr.openFragment(isDev ? [ "q:type", "S" ] : EMPTY_ARRAY);
5554
5557
  const signalNode = ssr.getOrCreateLastNode();
5555
5558
  const unwrappedSignal = value instanceof WrappedSignalImpl ? value.$unwrapIfSignal$() : value;
5556
5559
  enqueue(ssr.closeFragment), enqueue(() => trackSignalAndAssignHost(unwrappedSignal, signalNode, ".", ssr)),
@@ -5668,8 +5671,12 @@ function toSsrAttrs(record, options) {
5668
5671
  const eventValue = setEvent(options.serializationCtx, key, value);
5669
5672
  return void (eventValue && ssrAttrs.push(key, eventValue));
5670
5673
  }
5671
- isSignal(value) ? isClassAttr(key) ? ssrAttrs.push(key, [ value, options.styleScopedId ]) : ssrAttrs.push(key, value) : (isPreventDefault(key) ? addPreventDefaultEventToSerializationContext(options.serializationCtx, key) : "q:p" !== key && "q:ps" !== key || (value = options.serializationCtx.$addRoot$(value)),
5672
- value = serializeAttribute(key, value, options.styleScopedId), ssrAttrs.push(key, value));
5674
+ if (isSignal(value)) {
5675
+ return maybeAddPollingAsyncSignalToEagerResume(options.serializationCtx, value),
5676
+ void (isClassAttr(key) ? ssrAttrs.push(key, [ value, options.styleScopedId ]) : ssrAttrs.push(key, value));
5677
+ }
5678
+ isPreventDefault(key) ? addPreventDefaultEventToSerializationContext(options.serializationCtx, key) : "q:p" !== key && "q:ps" !== key || (value = options.serializationCtx.$addRoot$(value)),
5679
+ value = serializeAttribute(key, value, options.styleScopedId), ssrAttrs.push(key, value);
5673
5680
  }
5674
5681
  };
5675
5682
  if (options.toSort) {
@@ -5723,6 +5730,14 @@ function addPreventDefaultEventToSerializationContext(serializationCtx, key) {
5723
5730
  eventName && serializationCtx.$eventNames$.add(eventName);
5724
5731
  }
5725
5732
 
5733
+ function maybeAddPollingAsyncSignalToEagerResume(serializationCtx, signal) {
5734
+ const unwrappedSignal = signal instanceof WrappedSignalImpl ? signal.$unwrapIfSignal$() : signal;
5735
+ if (unwrappedSignal instanceof AsyncSignalImpl) {
5736
+ unwrappedSignal.$interval$ > 0 && (serializationCtx.$addRoot$(unwrappedSignal),
5737
+ serializationCtx.$eagerResume$.add(unwrappedSignal));
5738
+ }
5739
+ }
5740
+
5726
5741
  function getSlotName(host, jsx, ssr) {
5727
5742
  const constProps = jsx.constProps;
5728
5743
  if (constProps && "object" == typeof constProps && "name" in constProps) {
@@ -5746,6 +5761,60 @@ function appendClassIfScopedStyleExists(jsx, styleScoped) {
5746
5761
  const useLexicalScope = () => (isDev && assertDefined(_captures, "invoke: captures must be defined for useLexicalScope()"),
5747
5762
  _captures);
5748
5763
 
5764
+ const _rsc = async arg => {
5765
+ const [fn, ref] = _captures;
5766
+ const result = await fn(arg);
5767
+ return result && "object" == typeof result ? ref.r ? Object.assign(ref.r, result) : ref.r = createStore(fn.$container$, result, 1) : ref.r = result,
5768
+ {
5769
+ r: ref.r
5770
+ };
5771
+ };
5772
+
5773
+ const useResourceQrl = (qrl, opts) => {
5774
+ assertQrl(qrl);
5775
+ const {val, set, iCtx} = useSequentialScope();
5776
+ if (val) {
5777
+ return val;
5778
+ }
5779
+ const wrapped = createQRL(null, "_rsc", _rsc, null, [ qrl, {} ]);
5780
+ qrl.$container$ = iCtx.$container$;
5781
+ const asyncSignal = createAsyncSignal(wrapped, {
5782
+ timeout: opts?.timeout,
5783
+ container: iCtx.$container$,
5784
+ concurrency: 0
5785
+ });
5786
+ asyncSignal.$computeIfNeeded$();
5787
+ const resource = {
5788
+ __brand: "resource",
5789
+ signal: asyncSignal,
5790
+ get value() {
5791
+ return asyncSignal.promise().then(() => asyncSignal.error ? Promise.reject(asyncSignal.error) : asyncSignal.value.r);
5792
+ },
5793
+ get loading() {
5794
+ return asyncSignal.loading;
5795
+ }
5796
+ };
5797
+ return set(resource), resource;
5798
+ };
5799
+
5800
+ const Resource = ({value, onResolved, onPending, onRejected}) => {
5801
+ if (isPromise(value)) {
5802
+ return value.then(onResolved, onRejected);
5803
+ }
5804
+ const isRes = isResourceReturn(value);
5805
+ const signal = isRes ? value.signal : value;
5806
+ if (onPending && signal.loading) {
5807
+ return onPending();
5808
+ }
5809
+ if (onRejected && signal.error) {
5810
+ return onRejected(signal.error);
5811
+ }
5812
+ const val = isRes ? signal.value?.r : signal.value;
5813
+ return isPromise(val) ? val.then(onResolved, onRejected) : onResolved(val);
5814
+ };
5815
+
5816
+ const isResourceReturn = obj => obj && "resource" === obj.__brand;
5817
+
5749
5818
  let loading = Promise.resolve();
5750
5819
 
5751
5820
  const inflate = (container, target, typeId, data) => {
@@ -5773,18 +5842,10 @@ const inflate = (container, target, typeId, data) => {
5773
5842
  break;
5774
5843
 
5775
5844
  case 21:
5776
- const [resolved, result, effects] = data;
5777
- const resource = target;
5778
- resolved ? (resource.value = Promise.resolve(result), resource._resolved = result,
5779
- resource._state = "resolved") : (resource.value = Promise.reject(result), resource._error = result,
5780
- resource._state = "rejected"), getStoreHandler(target).$effects$ = effects;
5781
- break;
5782
-
5783
- case 22:
5784
5845
  target[SERIALIZABLE_STATE][0] = data[0];
5785
5846
  break;
5786
5847
 
5787
- case 28:
5848
+ case 27:
5788
5849
  {
5789
5850
  const store = unwrapStore(target);
5790
5851
  const storeTarget = pendingStoreTargets.get(store);
@@ -5795,7 +5856,7 @@ const inflate = (container, target, typeId, data) => {
5795
5856
  break;
5796
5857
  }
5797
5858
 
5798
- case 23:
5859
+ case 22:
5799
5860
  {
5800
5861
  const signal = target;
5801
5862
  const d = data;
@@ -5803,7 +5864,7 @@ const inflate = (container, target, typeId, data) => {
5803
5864
  break;
5804
5865
  }
5805
5866
 
5806
- case 24:
5867
+ case 23:
5807
5868
  {
5808
5869
  const signal = target;
5809
5870
  const d = data;
@@ -5813,27 +5874,28 @@ const inflate = (container, target, typeId, data) => {
5813
5874
  break;
5814
5875
  }
5815
5876
 
5816
- case 26:
5877
+ case 25:
5817
5878
  {
5818
5879
  const asyncSignal = target;
5819
5880
  const d = data;
5820
5881
  asyncSignal.$computeQrl$ = d[0], asyncSignal[_EFFECT_BACK_REF] = d[1], asyncSignal.$effects$ = new Set(d[2]),
5821
5882
  asyncSignal.$loadingEffects$ = new Set(d[3]), asyncSignal.$errorEffects$ = new Set(d[4]),
5822
- asyncSignal.$untrackedLoading$ = d[5], asyncSignal.$untrackedError$ = d[6];
5823
- d.length > 7 && (asyncSignal.$untrackedValue$ = d[7], asyncSignal.$promiseValue$ = d[7]),
5824
- asyncSignal.$flags$ |= 1;
5883
+ asyncSignal.$untrackedError$ = d[5];
5884
+ d.length > 6 && (asyncSignal.$untrackedValue$ = d[6]), asyncSignal.$untrackedValue$ !== NEEDS_COMPUTATION && (asyncSignal.$flags$ &= -2),
5885
+ asyncSignal.interval = d[7] ?? 0, asyncSignal.$concurrency$ = d[8] ?? 1, asyncSignal.$timeoutMs$ = d[9] ?? 0,
5886
+ d[10] && (asyncSignal.$flags$ |= 32);
5825
5887
  break;
5826
5888
  }
5827
5889
 
5828
- case 27:
5829
- case 25:
5890
+ case 26:
5891
+ case 24:
5830
5892
  {
5831
5893
  const computed = target;
5832
5894
  const d = data;
5833
5895
  computed.$computeQrl$ = d[0];
5834
5896
  const p = computed.$computeQrl$.resolve(container).catch(() => {});
5835
5897
  loading = loading.finally(() => p), computed[_EFFECT_BACK_REF] = d[1], d[2] && (computed.$effects$ = new Set(d[2]));
5836
- d.length > 3 ? (computed.$untrackedValue$ = d[3], 27 === typeId && (computed.$flags$ |= 1)) : computed.$flags$ |= 1;
5898
+ d.length > 3 && (computed.$untrackedValue$ = d[3]), 26 !== typeId && computed.$untrackedValue$ !== NEEDS_COMPUTATION && (computed.$flags$ &= -2);
5837
5899
  break;
5838
5900
  }
5839
5901
 
@@ -5847,7 +5909,7 @@ const inflate = (container, target, typeId, data) => {
5847
5909
  break;
5848
5910
  }
5849
5911
 
5850
- case 29:
5912
+ case 28:
5851
5913
  {
5852
5914
  const formData = target;
5853
5915
  const d = data;
@@ -5857,7 +5919,7 @@ const inflate = (container, target, typeId, data) => {
5857
5919
  break;
5858
5920
  }
5859
5921
 
5860
- case 30:
5922
+ case 29:
5861
5923
  {
5862
5924
  const jsx = target;
5863
5925
  const [type, key, varProps, constProps, children, toSort] = data;
@@ -5904,7 +5966,7 @@ const inflate = (container, target, typeId, data) => {
5904
5966
  }
5905
5967
  break;
5906
5968
 
5907
- case 31:
5969
+ case 30:
5908
5970
  const propsProxy = target;
5909
5971
  const d = data;
5910
5972
  let owner = d[0];
@@ -5912,14 +5974,14 @@ const inflate = (container, target, typeId, data) => {
5912
5974
  owner._proxy = propsProxy), propsProxy[_OWNER] = owner, propsProxy[_PROPS_HANDLER].$effects$ = d[3];
5913
5975
  break;
5914
5976
 
5915
- case 32:
5977
+ case 31:
5916
5978
  {
5917
5979
  const effectData = target;
5918
5980
  effectData.data.$scopedStyleIdPrefix$ = data[0], effectData.data.$isConst$ = data[1];
5919
5981
  break;
5920
5982
  }
5921
5983
 
5922
- case 33:
5984
+ case 32:
5923
5985
  {
5924
5986
  const effectSub = target;
5925
5987
  const d = data;
@@ -6383,7 +6445,7 @@ const useTaskQrl = (qrl, opts) => {
6383
6445
  return;
6384
6446
  }
6385
6447
  assertQrl(qrl), set(1);
6386
- const task = new Task(10 | (!1 === opts?.deferUpdates ? 0 : 16), i, iCtx.$hostElement$, qrl, void 0, null);
6448
+ const task = new Task(6 | (!1 === opts?.deferUpdates ? 0 : 8), i, iCtx.$hostElement$, qrl, void 0, null);
6387
6449
  set(task);
6388
6450
  const container = iCtx.$container$;
6389
6451
  const {$waitOn$: waitOn} = iCtx;
@@ -6392,7 +6454,7 @@ const useTaskQrl = (qrl, opts) => {
6392
6454
  };
6393
6455
 
6394
6456
  const runTask = (task, container, host) => {
6395
- task.$flags$ &= -9, cleanupDestroyable(task);
6457
+ task.$flags$ &= -5, cleanupDestroyable(task);
6396
6458
  const iCtx = newInvokeContext(container.$locale$, host, "qTask");
6397
6459
  iCtx.$container$ = container;
6398
6460
  const taskFn = task.$qrl$.getFn(iCtx, () => clearAllEffects(container, task));
@@ -6429,7 +6491,7 @@ function scheduleTask(_event, element) {
6429
6491
  const container = getDomContainer(element);
6430
6492
  "string" == typeof this && setCaptures(deserializeCaptures(container, this));
6431
6493
  const task = _captures[0];
6432
- task.$flags$ |= 8, markVNodeDirty(container, task.$el$, 1);
6494
+ task.$flags$ |= 4, markVNodeDirty(container, task.$el$, 1);
6433
6495
  }
6434
6496
 
6435
6497
  const throwIfQRLNotResolved = qrl => {
@@ -6449,7 +6511,7 @@ const ensureContainsBackRef = (array, value) => {
6449
6511
  };
6450
6512
 
6451
6513
  const addQrlToSerializationCtx = (effectSubscriber, container) => {
6452
- if (container) {
6514
+ if (container?.serializationCtx) {
6453
6515
  const effect = effectSubscriber.consumer;
6454
6516
  const property = effectSubscriber.property;
6455
6517
  let qrl = null;
@@ -6465,7 +6527,7 @@ const scheduleEffects = (container, signal, effects) => {
6465
6527
  const consumer = effectSubscription.consumer;
6466
6528
  const property = effectSubscription.property;
6467
6529
  if (isDev && assertDefined(container, "Container must be defined."), isTask(consumer)) {
6468
- consumer.$flags$ |= 8, markVNodeDirty(container, consumer.$el$, 1);
6530
+ consumer.$flags$ |= 4, markVNodeDirty(container, consumer.$el$, 1);
6469
6531
  } else if (consumer instanceof SignalImpl) {
6470
6532
  consumer.invalidate();
6471
6533
  } else if (":" === property) {
@@ -6907,26 +6969,19 @@ function preprocessState(data, container) {
6907
6969
 
6908
6970
  async function _serialize(data) {
6909
6971
  const serializationContext = createSerializationContext(null, null, () => "", () => "", () => {}, new WeakMap);
6910
- for (const root of data) {
6911
- serializationContext.$addRoot$(root);
6912
- }
6913
- return await serializationContext.$serialize$(), serializationContext.$writer$.toString();
6972
+ return serializationContext.$addRoot$(data), await serializationContext.$serialize$(),
6973
+ serializationContext.$writer$.toString();
6914
6974
  }
6915
6975
 
6916
6976
  function _deserialize(rawStateData) {
6917
6977
  if (null == rawStateData) {
6918
- return [];
6978
+ throw new Error("No state data to deserialize");
6919
6979
  }
6920
6980
  const stateData = JSON.parse(rawStateData);
6921
- if (!Array.isArray(stateData)) {
6922
- return [];
6923
- }
6924
- const container = _createDeserializeContainer(stateData);
6925
- const output = [];
6926
- for (let i = 0; i < stateData.length; i += 2) {
6927
- output[i / 2] = deserializeData(container, stateData[i], stateData[i + 1]);
6981
+ if (!Array.isArray(stateData) || stateData.length < 2 || "number" != typeof stateData[0]) {
6982
+ throw new Error("Invalid state data");
6928
6983
  }
6929
- return output;
6984
+ return deserializeData(_createDeserializeContainer(stateData), stateData[0], stateData[1]);
6930
6985
  }
6931
6986
 
6932
6987
  function getObjectById(id, stateData) {
@@ -6987,6 +7042,9 @@ const _verifySerializable = (value, seen, ctx, preMessage) => {
6987
7042
  _verifySerializable(v, seen, ctx + "[" + i + "]"), expectIndex = i + 1;
6988
7043
  }), value;
6989
7044
  }
7045
+ if (unwrapped.__brand) {
7046
+ return value;
7047
+ }
6990
7048
  if (isSerializableObject(unwrapped)) {
6991
7049
  for (const [key, item] of Object.entries(unwrapped)) {
6992
7050
  _verifySerializable(item, seen, ctx + "." + key);
@@ -7545,10 +7603,10 @@ const useVisibleTaskQrl = (qrl, opts) => {
7545
7603
  const {val, set, i, iCtx} = useSequentialScope();
7546
7604
  const eagerness = opts?.strategy ?? "intersection-observer";
7547
7605
  if (val) {
7548
- return void (64 & val.$flags$ || isServerPlatform() || (val.$flags$ |= 64, useRegisterTaskEvents(val, eagerness)));
7606
+ return void (32 & val.$flags$ || isServerPlatform() || (val.$flags$ |= 32, useRegisterTaskEvents(val, eagerness)));
7549
7607
  }
7550
7608
  let flags;
7551
- assertQrl(qrl), isServerPlatform() ? flags = 1 : (flags = 9, qrl.resolve(), markVNodeDirty(iCtx.$container$, iCtx.$hostElement$, 1));
7609
+ assertQrl(qrl), isServerPlatform() ? flags = 1 : (flags = 5, qrl.resolve(), markVNodeDirty(iCtx.$container$, iCtx.$hostElement$, 1));
7552
7610
  const task = new Task(flags, i, iCtx.$hostElement$, qrl, void 0, null);
7553
7611
  set(task), useRegisterTaskEvents(task, eagerness);
7554
7612
  };
@@ -7559,7 +7617,7 @@ const useRegisterTaskEvents = (task, eagerness) => {
7559
7617
 
7560
7618
  const getTaskHandlerQrl = task => createQRL(null, "_task", scheduleTask, null, [ task ]);
7561
7619
 
7562
- const useResource$ = (generatorFn, opts) => useResourceQrl(dollar(generatorFn), opts);
7620
+ const useResource$ = implicit$FirstArg(useResourceQrl);
7563
7621
 
7564
7622
  const useTask$ = /*#__PURE__*/ implicit$FirstArg(useTaskQrl);
7565
7623
 
@@ -7617,4 +7675,4 @@ globalThis.__qwik = version, import.meta.hot && import.meta.hot.dispose(() => {
7617
7675
  globalThis.__qwik = void 0;
7618
7676
  });
7619
7677
 
7620
- export { $, Fragment, NoSerializeSymbol, PrefetchGraph, PrefetchServiceWorker, RenderOnce, Resource, SSRComment, SSRRaw, SSRStream, SSRStreamBlock, SerializerSymbol, SkipRender, Slot, _CONST_PROPS, DomContainer as _DomContainer, _EFFECT_BACK_REF, EMPTY_ARRAY as _EMPTY_ARRAY, _IMMUTABLE, _SharedContainer, SubscriptionData as _SubscriptionData, _UNINITIALIZED, _VAR_PROPS, _captures, _chk, _deserialize, _dumpState, _executeSsrChores, _fnSignal, _getConstProps, _getContextContainer, _getContextEvent, _getContextHostElement, getDomContainer as _getDomContainer, _getQContainerElement, _getVarProps, _hasStoreEffects, isJSXNode as _isJSXNode, isStore as _isStore, isStringifiable as _isStringifiable, isTask as _isTask, _jsxBranch, _jsxC, _jsxQ, _jsxS, _jsxSorted, _jsxSplit, mapApp_findIndx as _mapApp_findIndx, mapArray_get as _mapArray_get, mapArray_set as _mapArray_set, _noopQrl, _noopQrlDEV, preprocessState as _preprocessState, _qrlSync, _regSymbol, _resolveContextWithoutSequentialScope, _restProps, _run, _serialize, scheduleTask as _task, _val, verifySerializable as _verifySerializable, vnode_ensureElementInflated as _vnode_ensureElementInflated, vnode_getAttrKeys as _vnode_getAttrKeys, vnode_getFirstChild as _vnode_getFirstChild, vnode_isMaterialized as _vnode_isMaterialized, vnode_isTextVNode as _vnode_isTextVNode, vnode_isVirtualVNode as _vnode_isVirtualVNode, vnode_toString as _vnode_toString, _waitUntilRendered, _walkJSX, _wrapProp, _wrapSignal, component$, componentQrl, createAsync$, createAsyncSignal as createAsyncQrl, createComputed$, createComputedSignal as createComputedQrl, createContextId, h as createElement, createSerializer$, createSerializerSignal as createSerializerQrl, createSignal, event$, eventQrl, forceStoreEffects, getDomContainer, getLocale, getPlatform, h, implicit$FirstArg, inlinedQrl, inlinedQrlDEV, isSignal, jsx, jsxDEV, jsxs, noSerialize, qrl, qrlDEV, render, setPlatform, sync$, untrack, unwrapStore, useAsync$, useAsyncQrl, useComputed$, useComputedQrl, useConstant, useContext, useContextProvider, useErrorBoundary, useId, useLexicalScope, useOn, useOnDocument, useOnWindow, useResource$, useResourceQrl, useSerializer$, useSerializerQrl, useServerData, useSignal, useStore, useStyles$, useStylesQrl, useStylesScoped$, useStylesScopedQrl, useTask$, useTaskQrl, useVisibleTask$, useVisibleTaskQrl, version, withLocale };
7678
+ export { $, Fragment, NoSerializeSymbol, PrefetchGraph, PrefetchServiceWorker, RenderOnce, Resource, SSRComment, SSRRaw, SSRStream, SSRStreamBlock, SerializerSymbol, SkipRender, Slot, _CONST_PROPS, DomContainer as _DomContainer, _EFFECT_BACK_REF, EMPTY_ARRAY as _EMPTY_ARRAY, _IMMUTABLE, _SharedContainer, SubscriptionData as _SubscriptionData, _UNINITIALIZED, _VAR_PROPS, _captures, _chk, createQRL as _createQRL, _deserialize, _dumpState, _executeSsrChores, _fnSignal, _getConstProps, _getContextContainer, _getContextEvent, _getContextHostElement, getDomContainer as _getDomContainer, _getQContainerElement, _getVarProps, _hasStoreEffects, isJSXNode as _isJSXNode, isStore as _isStore, isStringifiable as _isStringifiable, isTask as _isTask, _jsxBranch, _jsxC, _jsxQ, _jsxS, _jsxSorted, _jsxSplit, mapApp_findIndx as _mapApp_findIndx, mapArray_get as _mapArray_get, mapArray_set as _mapArray_set, _noopQrl, _noopQrlDEV, preprocessState as _preprocessState, _qrlSync, qrlToString as _qrlToString, _regSymbol, _res, _resolveContextWithoutSequentialScope, _restProps, _rsc, _run, _serialize, scheduleTask as _task, _val, verifySerializable as _verifySerializable, vnode_ensureElementInflated as _vnode_ensureElementInflated, vnode_getAttrKeys as _vnode_getAttrKeys, vnode_getFirstChild as _vnode_getFirstChild, vnode_isMaterialized as _vnode_isMaterialized, vnode_isTextVNode as _vnode_isTextVNode, vnode_isVirtualVNode as _vnode_isVirtualVNode, vnode_toString as _vnode_toString, _waitUntilRendered, _walkJSX, _wrapProp, _wrapSignal, component$, componentQrl, createAsync$, createAsyncSignal as createAsyncQrl, createComputed$, createComputedSignal as createComputedQrl, createContextId, h as createElement, createSerializer$, createSerializerSignal as createSerializerQrl, createSignal, event$, eventQrl, forceStoreEffects, getDomContainer, getLocale, getPlatform, h, implicit$FirstArg, inlinedQrl, inlinedQrlDEV, isSignal, jsx, jsxDEV, jsxs, noSerialize, qrl, qrlDEV, render, setPlatform, sync$, untrack, unwrapStore, useAsync$, useAsyncQrl, useComputed$, useComputedQrl, useConstant, useContext, useContextProvider, useErrorBoundary, useId, useLexicalScope, useOn, useOnDocument, useOnWindow, useResource$, useResourceQrl, useSerializer$, useSerializerQrl, useServerData, useSignal, useStore, useStyles$, useStylesQrl, useStylesScoped$, useStylesScopedQrl, useTask$, useTaskQrl, useVisibleTask$, useVisibleTaskQrl, version, withLocale };