@qwik.dev/core 2.0.0-beta.3 → 2.0.0-beta.4

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.3-dev+aa098fc
3
+ * @qwik.dev/core 2.0.0-beta.4-dev+9849dcf
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
@@ -55,6 +55,19 @@ const createAndLogError = (asyncThrow, message, ...optionalParams) => {
55
55
  }, 0), err;
56
56
  };
57
57
 
58
+ const isSerializableObject = v => {
59
+ const proto = Object.getPrototypeOf(v);
60
+ return proto === Object.prototype || proto === Array.prototype || null === proto;
61
+ };
62
+
63
+ const isObject = v => "object" == typeof v && null !== v;
64
+
65
+ const isArray = v => Array.isArray(v);
66
+
67
+ const isString = v => "string" == typeof v;
68
+
69
+ const isFunction = v => "function" == typeof v;
70
+
58
71
  const codeToText = code => `Code(Q${code}) https://github.com/QwikDev/qwik/blob/main/packages/qwik/src/core/error/error.ts#L${8 + code}`;
59
72
 
60
73
  const qError = (code, errorMessageArgs = []) => {
@@ -273,19 +286,6 @@ function retryOnPromise(fn, retryCount = 0) {
273
286
  }
274
287
  }
275
288
 
276
- const isSerializableObject = v => {
277
- const proto = Object.getPrototypeOf(v);
278
- return proto === Object.prototype || proto === Array.prototype || null === proto;
279
- };
280
-
281
- const isObject = v => !!v && "object" == typeof v;
282
-
283
- const isArray = v => Array.isArray(v);
284
-
285
- const isString = v => "string" == typeof v;
286
-
287
- const isFunction = v => "function" == typeof v;
288
-
289
289
  const ASSERT_DISCLAIMER = "Internal assert, this is likely caused by a bug in Qwik: ";
290
290
 
291
291
  function assertDefined() {
@@ -413,11 +413,11 @@ class WrappedSignalImpl extends SignalImpl {
413
413
  super(container, NEEDS_COMPUTATION), this.$args$ = args, this.$func$ = fn, this.$funcStr$ = fnStr,
414
414
  this.$flags$ = flags;
415
415
  }
416
- $invalidate$() {
416
+ invalidate() {
417
417
  this.$flags$ |= 1, this.$forceRunEffects$ = !1, this.$container$?.$scheduler$(7, this.$hostElement$, this, this.$effects$);
418
418
  }
419
419
  force() {
420
- this.$flags$ |= 1, this.$forceRunEffects$ = !1, triggerEffects(this.$container$, this, this.$effects$);
420
+ this.$forceRunEffects$ = !0, this.$container$?.$scheduler$(7, this.$hostElement$, this, this.$effects$);
421
421
  }
422
422
  get untrackedValue() {
423
423
  const didChange = this.$computeIfNeeded$();
@@ -524,7 +524,7 @@ const newInvokeContext = (locale, hostElement, element, event, url) => {
524
524
  $event$: event,
525
525
  $qrl$: void 0,
526
526
  $effectSubscriber$: void 0,
527
- $locale$: locale || ("object" == typeof event && event && "locale" in event ? event.locale : void 0),
527
+ $locale$: locale || (event && isObject(event) && "locale" in event ? event.locale : void 0),
528
528
  $container$: void 0
529
529
  };
530
530
  return seal(), ctx;
@@ -565,6 +565,13 @@ const _getContextEvent = () => {
565
565
  }
566
566
  };
567
567
 
568
+ const _getContextContainer = () => {
569
+ const iCtx = tryGetInvokeContext();
570
+ if (iCtx) {
571
+ return iCtx.$container$;
572
+ }
573
+ };
574
+
568
575
  const _jsxBranch = input => input;
569
576
 
570
577
  const _waitUntilRendered = elm => {
@@ -696,7 +703,7 @@ const ERROR_CONTEXT = /*#__PURE__*/ createContextId("qk-error");
696
703
 
697
704
  const isRecoverable = err => !(err && err instanceof Error && "plugin" in err);
698
705
 
699
- const version = "2.0.0-beta.3-dev+aa098fc";
706
+ const version = "2.0.0-beta.4-dev+9849dcf";
700
707
 
701
708
  const EMPTY_ARRAY = [];
702
709
 
@@ -798,6 +805,8 @@ const _VAR_PROPS = Symbol("VAR");
798
805
 
799
806
  const _IMMUTABLE = Symbol("IMMUTABLE");
800
807
 
808
+ const _UNINITIALIZED = Symbol("UNINITIALIZED");
809
+
801
810
  const implicit$FirstArg = fn => function(first, ...rest) {
802
811
  return fn.call(null, dollar(first), ...rest);
803
812
  };
@@ -811,10 +820,10 @@ class ComputedSignalImpl extends SignalImpl {
811
820
  $flags$;
812
821
  $forceRunEffects$=!1;
813
822
  [_EFFECT_BACK_REF]=null;
814
- constructor(container, fn, flags = 1) {
823
+ constructor(container, fn, flags = 17) {
815
824
  super(container, NEEDS_COMPUTATION), this.$computeQrl$ = fn, this.$flags$ = flags;
816
825
  }
817
- $invalidate$() {
826
+ invalidate() {
818
827
  this.$flags$ |= 1, this.$forceRunEffects$ = !1, this.$container$?.$scheduler$(7, null, this, this.$effects$);
819
828
  }
820
829
  force() {
@@ -856,7 +865,7 @@ class ComputedSignalImpl extends SignalImpl {
856
865
 
857
866
  class SerializerSignalImpl extends ComputedSignalImpl {
858
867
  constructor(container, argQrl) {
859
- super(container, argQrl);
868
+ super(container, argQrl, 17);
860
869
  }
861
870
  $didInitialize$=!1;
862
871
  $computeIfNeeded$() {
@@ -869,7 +878,7 @@ class SerializerSignalImpl extends ComputedSignalImpl {
869
878
  const {deserialize, initial} = arg;
870
879
  const update = arg.update;
871
880
  const currentValue = this.$untrackedValue$ === NEEDS_COMPUTATION ? initial : this.$untrackedValue$;
872
- const untrackedValue = trackSignal(() => this.$didInitialize$ ? update?.(currentValue) : deserialize(currentValue), this, ".", this.$container$);
881
+ const untrackedValue = trackSignal(() => this.$didInitialize$ ? update?.(currentValue) || currentValue : deserialize(currentValue), this, ".", this.$container$);
873
882
  const didChange = this.$didInitialize$ && "undefined" !== untrackedValue || untrackedValue !== this.$untrackedValue$;
874
883
  return this.$flags$ &= -2, this.$didInitialize$ = !0, didChange && (this.$untrackedValue$ = untrackedValue),
875
884
  didChange;
@@ -928,7 +937,7 @@ class StoreHandler {
928
937
  if ("toString" === prop && value === Object.prototype.toString) {
929
938
  return this.toString;
930
939
  }
931
- return 1 & this.$flags$ && "object" == typeof value && null !== value && !Object.isFrozen(value) && !isStore(value) && !Object.isFrozen(target) ? getOrCreateStore(value, this.$flags$, this.$container$) : value;
940
+ return 1 & this.$flags$ && isObject(value) && !Object.isFrozen(value) && !isStore(value) && !Object.isFrozen(target) ? getOrCreateStore(value, this.$flags$, this.$container$) : value;
932
941
  }
933
942
  set(target, prop, value) {
934
943
  if ("symbol" == typeof prop) {
@@ -1051,7 +1060,7 @@ class AsyncComputedSignalImpl extends ComputedSignalImpl {
1051
1060
  $loadingEffects$=null;
1052
1061
  $errorEffects$=null;
1053
1062
  $destroy$;
1054
- $promiseValue$=null;
1063
+ $promiseValue$=NEEDS_COMPUTATION;
1055
1064
  [_EFFECT_BACK_REF]=null;
1056
1065
  constructor(container, fn, flags = 1) {
1057
1066
  super(container, fn, flags);
@@ -1074,6 +1083,9 @@ class AsyncComputedSignalImpl extends ComputedSignalImpl {
1074
1083
  get untrackedError() {
1075
1084
  return this.$untrackedError$;
1076
1085
  }
1086
+ invalidate() {
1087
+ super.invalidate(), this.$promiseValue$ = NEEDS_COMPUTATION;
1088
+ }
1077
1089
  $computeIfNeeded$() {
1078
1090
  if (!(1 & this.$flags$)) {
1079
1091
  return !1;
@@ -1081,18 +1093,18 @@ class AsyncComputedSignalImpl extends ComputedSignalImpl {
1081
1093
  const computeQrl = this.$computeQrl$;
1082
1094
  throwIfQRLNotResolved(computeQrl);
1083
1095
  const [cleanup] = cleanupFn(this, err => this.$container$?.handleError(err, null));
1084
- const untrackedValue = this.$promiseValue$ ?? computeQrl.getFn()({
1096
+ const untrackedValue = this.$promiseValue$ === NEEDS_COMPUTATION ? computeQrl.getFn()({
1085
1097
  track: trackFn(this, this.$container$),
1086
1098
  cleanup
1087
- });
1099
+ }) : this.$promiseValue$;
1088
1100
  if (isPromise(untrackedValue)) {
1089
1101
  throw this.untrackedLoading = !0, this.untrackedError = null, untrackedValue.then(promiseValue => {
1090
1102
  this.$promiseValue$ = promiseValue, this.untrackedLoading = !1, this.untrackedError = null;
1091
1103
  }).catch(err => {
1092
- this.untrackedLoading = !1, this.untrackedError = err;
1104
+ this.$promiseValue$ = err, this.untrackedLoading = !1, this.untrackedError = err;
1093
1105
  });
1094
1106
  }
1095
- this.$promiseValue$ = null, this.$flags$ &= -2;
1107
+ this.$promiseValue$ = NEEDS_COMPUTATION, this.$flags$ &= -2;
1096
1108
  const didChange = untrackedValue !== this.$untrackedValue$;
1097
1109
  return didChange && (this.$untrackedValue$ = untrackedValue), didChange;
1098
1110
  }
@@ -1100,14 +1112,18 @@ class AsyncComputedSignalImpl extends ComputedSignalImpl {
1100
1112
 
1101
1113
  const createSignal$1 = value => new SignalImpl(null, value);
1102
1114
 
1103
- const createComputedSignal = qrl => (throwIfQRLNotResolved(qrl), new ComputedSignalImpl(null, qrl));
1115
+ const createComputedSignal = (qrl, options) => new ComputedSignalImpl(options?.container || null, qrl, getComputedSignalFlags(options?.serializationStrategy || "always"));
1116
+
1117
+ const createAsyncComputedSignal = (qrl, options) => new AsyncComputedSignalImpl(options?.container || null, qrl, getComputedSignalFlags(options?.serializationStrategy || "never"));
1104
1118
 
1105
- const createSerializerSignal = arg => (throwIfQRLNotResolved(arg), new SerializerSignalImpl(null, arg));
1119
+ const createSerializerSignal = arg => new SerializerSignalImpl(null, arg);
1106
1120
 
1107
1121
  const createSignal = createSignal$1;
1108
1122
 
1109
1123
  const createComputed$ = /*#__PURE__*/ implicit$FirstArg(createComputedSignal);
1110
1124
 
1125
+ const createAsyncComputed$ = /*#__PURE__*/ implicit$FirstArg(createAsyncComputedSignal);
1126
+
1111
1127
  const createSerializer$ = implicit$FirstArg(createSerializerSignal);
1112
1128
 
1113
1129
  const getValueProp = p0 => p0.value;
@@ -1141,11 +1157,6 @@ const _wrapProp = (...args) => {
1141
1157
  return obj[prop];
1142
1158
  };
1143
1159
 
1144
- const _wrapStore = (obj, prop) => {
1145
- const value = getStoreTarget(obj)[prop];
1146
- return isSignal(value) ? value : new WrappedSignalImpl(null, getProp, [ obj, prop ], null, 1);
1147
- };
1148
-
1149
1160
  const _wrapSignal = (obj, prop) => {
1150
1161
  const r = _wrapProp(obj, prop);
1151
1162
  return r === _IMMUTABLE ? obj[prop] : r;
@@ -1417,7 +1428,10 @@ const executeComponent = (container, renderHost, subscriptionHost, componentQRL,
1417
1428
  return useOnEvents ? addUseOnEvents(jsx, useOnEvents) : jsx;
1418
1429
  }, err => {
1419
1430
  if (isPromise(err) && retryCount < 100) {
1420
- return err.then(() => executeComponentWithPromiseExceptionRetry(retryCount++));
1431
+ return err.then(() => executeComponentWithPromiseExceptionRetry(++retryCount));
1432
+ }
1433
+ if (retryCount >= 100) {
1434
+ throw new Error("Max retry count of component execution reached");
1421
1435
  }
1422
1436
  throw err;
1423
1437
  });
@@ -2798,7 +2812,14 @@ function getResourceValueAsPromise(props) {
2798
2812
  const value = resource.value;
2799
2813
  return value ? value.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected)) : Promise.resolve(void 0);
2800
2814
  }
2801
- return isPromise(resource) ? resource.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected)) : isSignal(resource) ? Promise.resolve(resource.value).then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected)) : Promise.resolve(resource).then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
2815
+ if (isPromise(resource)) {
2816
+ return resource.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
2817
+ }
2818
+ if (isSignal(resource)) {
2819
+ const value = retryOnPromise(() => resource.value);
2820
+ return (isPromise(value) ? value : Promise.resolve(value)).then(useBindInvokeContext(props.onResolved));
2821
+ }
2822
+ return Promise.resolve(resource).then(useBindInvokeContext(props.onResolved));
2802
2823
  }
2803
2824
 
2804
2825
  const _createResourceReturn = opts => ({
@@ -3117,7 +3138,7 @@ const createScheduler = (container, scheduleDrain, journalFlush) => {
3117
3138
  const ctx = newInvokeContext();
3118
3139
  if (ctx.$container$ = container, target instanceof ComputedSignalImpl || target instanceof WrappedSignalImpl) {
3119
3140
  const forceRunEffects = target.$forceRunEffects$;
3120
- if (target.$forceRunEffects$ = !1, !effects?.size) {
3141
+ if (target.$forceRunEffects$ = !1, !effects?.size && !forceRunEffects) {
3121
3142
  break;
3122
3143
  }
3123
3144
  returnValue = maybeThen(retryOnPromise(() => invoke.call(target, ctx, target.$computeIfNeeded$)), didChange => {
@@ -3652,7 +3673,7 @@ const triggerEffects = (container, signal, effects) => {
3652
3673
  1 & consumer.$flags$ && (choreType = 32), container.$scheduler$(choreType, consumer);
3653
3674
  } else if (consumer instanceof SignalImpl) {
3654
3675
  consumer instanceof ComputedSignalImpl && (consumer.$computeQrl$.resolved || container.$scheduler$(1, null, consumer.$computeQrl$)),
3655
- consumer.$invalidate$();
3676
+ consumer.invalidate();
3656
3677
  } else if (":" === property) {
3657
3678
  const host = consumer;
3658
3679
  const qrl = container.getHostProp(host, "q:renderFn");
@@ -3680,7 +3701,20 @@ const triggerEffects = (container, signal, effects) => {
3680
3701
  }
3681
3702
  };
3682
3703
 
3683
- const isSerializerObj = obj => "object" == typeof obj && null !== obj && "function" == typeof obj[SerializerSymbol];
3704
+ const isSerializerObj = obj => isObject(obj) && "function" == typeof obj[SerializerSymbol];
3705
+
3706
+ const getComputedSignalFlags = serializationStrategy => {
3707
+ let flags = 1;
3708
+ switch (serializationStrategy) {
3709
+ case "never":
3710
+ flags |= 8;
3711
+ break;
3712
+
3713
+ case "always":
3714
+ flags |= 16;
3715
+ }
3716
+ return flags;
3717
+ };
3684
3718
 
3685
3719
  const stringifyPath = [];
3686
3720
 
@@ -4698,7 +4732,7 @@ const VNodeArray = class VNode extends Array {
4698
4732
 
4699
4733
  const deserializedProxyMap = new WeakMap;
4700
4734
 
4701
- const isDeserializerProxy = value => "object" == typeof value && null !== value && SERIALIZER_PROXY_UNWRAP in value;
4735
+ const isDeserializerProxy = value => isObject(value) && SERIALIZER_PROXY_UNWRAP in value;
4702
4736
 
4703
4737
  const SERIALIZER_PROXY_UNWRAP = Symbol("UNWRAP");
4704
4738
 
@@ -4856,7 +4890,7 @@ const inflate = (container, target, typeId, data) => {
4856
4890
  asyncComputed.$computeQrl$ = d[0], asyncComputed.$effects$ = new Set(d[1]), asyncComputed.$loadingEffects$ = new Set(d[2]),
4857
4891
  asyncComputed.$errorEffects$ = new Set(d[3]), asyncComputed.$untrackedLoading$ = d[4],
4858
4892
  asyncComputed.$untrackedError$ = d[5];
4859
- d.length > 6 ? asyncComputed.$untrackedValue$ = d[6] : asyncComputed.$flags$ |= 1;
4893
+ d.length > 6 && (asyncComputed.$untrackedValue$ = d[6]), asyncComputed.$flags$ |= 1;
4860
4894
  break;
4861
4895
  }
4862
4896
 
@@ -4956,9 +4990,9 @@ const inflate = (container, target, typeId, data) => {
4956
4990
  return target;
4957
4991
  };
4958
4992
 
4959
- const _constants = [ void 0, null, !0, !1, "", EMPTY_ARRAY, EMPTY_OBJ, NEEDS_COMPUTATION, STORE_ALL_PROPS, Slot, Fragment, NaN, 1 / 0, -1 / 0, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER - 1, Number.MIN_SAFE_INTEGER ];
4993
+ const _constants = [ void 0, null, !0, !1, "", EMPTY_ARRAY, EMPTY_OBJ, NEEDS_COMPUTATION, STORE_ALL_PROPS, _UNINITIALIZED, Slot, Fragment, NaN, 1 / 0, -1 / 0, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER - 1, Number.MIN_SAFE_INTEGER ];
4960
4994
 
4961
- const _constantNames = [ "undefined", "null", "true", "false", "''", "EMPTY_ARRAY", "EMPTY_OBJ", "NEEDS_COMPUTATION", "STORE_ALL_PROPS", "Slot", "Fragment", "NaN", "Infinity", "-Infinity", "MAX_SAFE_INTEGER", "MAX_SAFE_INTEGER-1", "MIN_SAFE_INTEGER" ];
4995
+ 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" ];
4962
4996
 
4963
4997
  const allocate = (container, typeId, value) => {
4964
4998
  if (void 0 === value) {
@@ -4972,7 +5006,8 @@ const allocate = (container, typeId, value) => {
4972
5006
  if (!container.$forwardRefs$) {
4973
5007
  throw qError(18, [ "forward ref" ]);
4974
5008
  }
4975
- return container.$getObjectById$(container.$forwardRefs$[value]);
5009
+ const rootRef = container.$forwardRefs$[value];
5010
+ return -1 === rootRef ? _UNINITIALIZED : container.$getObjectById$(rootRef);
4976
5011
 
4977
5012
  case 2:
4978
5013
  case 4:
@@ -5124,12 +5159,12 @@ const createSerializationContext = (NodeConstructor, DomRefConstructor, symbolTo
5124
5159
  };
5125
5160
  }
5126
5161
  const seenObjsMap = new Map;
5127
- const rootsPathMap = new Map;
5162
+ const objectPathStringCache = new Map;
5128
5163
  const syncFnMap = new Map;
5129
5164
  const syncFns = [];
5130
5165
  const roots = [];
5131
5166
  const $addRootPath$ = obj => {
5132
- const rootPath = rootsPathMap.get(obj);
5167
+ const rootPath = objectPathStringCache.get(obj);
5133
5168
  if (rootPath) {
5134
5169
  return rootPath;
5135
5170
  }
@@ -5143,7 +5178,7 @@ const createSerializationContext = (NodeConstructor, DomRefConstructor, symbolTo
5143
5178
  current = seenObjsMap.get(current.$parent$);
5144
5179
  }
5145
5180
  const pathStr = path.length > 1 ? path.join(" ") : path.length ? path[0] : seen.$index$;
5146
- return rootsPathMap.set(obj, pathStr), pathStr;
5181
+ return objectPathStringCache.set(obj, pathStr), pathStr;
5147
5182
  };
5148
5183
  const isSsrNode = NodeConstructor ? obj => obj instanceof NodeConstructor : () => !1;
5149
5184
  return isDomRef = DomRefConstructor ? obj => obj instanceof DomRefConstructor : () => !1,
@@ -5206,7 +5241,7 @@ const createSerializationContext = (NodeConstructor, DomRefConstructor, symbolTo
5206
5241
  $storeProxyMap$: storeProxyMap,
5207
5242
  $getProp$: getProp,
5208
5243
  $setProp$: setProp,
5209
- $pathMap$: rootsPathMap
5244
+ $objectPathStringCache$: objectPathStringCache
5210
5245
  };
5211
5246
  };
5212
5247
 
@@ -5225,7 +5260,7 @@ const discoverValuesForVNodeData = (vnodeData, callback) => {
5225
5260
  if (isSsrAttrs(value)) {
5226
5261
  for (let i = 1; i < value.length; i += 2) {
5227
5262
  const attrValue = value[i];
5228
- "string" == typeof attrValue || "q:props" === value[i - 1] && 0 === Object.keys(attrValue).length || callback(attrValue);
5263
+ null == attrValue || "string" == typeof attrValue || "q:props" === value[i - 1] && 0 === Object.keys(attrValue).length || callback(attrValue);
5229
5264
  }
5230
5265
  }
5231
5266
  }
@@ -5243,13 +5278,24 @@ class PromiseResult {
5243
5278
  }
5244
5279
  }
5245
5280
 
5281
+ class SerializationWeakRef {
5282
+ $obj$;
5283
+ constructor($obj$) {
5284
+ this.$obj$ = $obj$;
5285
+ }
5286
+ }
5287
+
5288
+ const _serializationWeakRef = obj => new SerializationWeakRef(obj);
5289
+
5246
5290
  async function serialize(serializationContext) {
5247
- const {$writer$, $isSsrNode$, $isDomRef$, $storeProxyMap$, $addRoot$, $pathMap$, $wasSeen$} = serializationContext;
5291
+ const {$writer$, $isSsrNode$, $isDomRef$, $storeProxyMap$, $addRoot$, $objectPathStringCache$, $wasSeen$} = serializationContext;
5248
5292
  let depth = 0;
5293
+ let rootIdx = 0;
5249
5294
  const forwardRefs = [];
5250
5295
  let forwardRefsId = 0;
5251
5296
  const promises = new Set;
5252
5297
  const preloadQrls = new Set;
5298
+ const s11nWeakRefs = new Map;
5253
5299
  let parent = null;
5254
5300
  const outputArray = (value, writeFn) => {
5255
5301
  $writer$.write("[");
@@ -5277,14 +5323,26 @@ async function serialize(serializationContext) {
5277
5323
  }
5278
5324
  };
5279
5325
  const addPreloadQrl = qrl => {
5280
- preloadQrls.add(qrl), serializationContext.$addRoot$(qrl, null);
5326
+ preloadQrls.add(qrl), serializationContext.$addRoot$(qrl);
5281
5327
  };
5282
- const outputRootRef = (value, rootDepth = 0) => {
5328
+ const outputAsRootRef = (value, rootDepth = 0) => {
5283
5329
  const seen = $wasSeen$(value);
5284
- const rootRefPath = $pathMap$.get(value);
5285
- return rootDepth === depth && seen && null !== seen.$parent$ && rootRefPath ? (output(0, rootRefPath),
5286
- !0) : !!(depth > rootDepth && seen && -1 !== seen.$rootIndex$) && (output(0, seen.$rootIndex$),
5287
- !0);
5330
+ const rootRefPath = $objectPathStringCache$.get(value);
5331
+ if (rootDepth === depth && seen && null !== seen.$parent$ && rootRefPath) {
5332
+ return output(0, rootRefPath), !0;
5333
+ }
5334
+ if (depth > rootDepth && seen && -1 !== seen.$rootIndex$) {
5335
+ return output(0, seen.$rootIndex$), !0;
5336
+ }
5337
+ if (s11nWeakRefs.has(value)) {
5338
+ const forwardRefId = s11nWeakRefs.get(value);
5339
+ if (rootDepth !== depth) {
5340
+ const rootRef = $addRoot$(value);
5341
+ return output(0, rootRef), forwardRefs[forwardRefId] = rootRef, !0;
5342
+ }
5343
+ forwardRefs[forwardRefId] = rootIdx;
5344
+ }
5345
+ return !1;
5288
5346
  };
5289
5347
  const writeValue = value => {
5290
5348
  if (fastSkipSerialize(value)) {
@@ -5295,11 +5353,11 @@ async function serialize(serializationContext) {
5295
5353
  output(3, value ? 2 : 3);
5296
5354
  } else if ("function" == typeof value) {
5297
5355
  if (value === Slot) {
5298
- output(3, 9);
5299
- } else if (value === Fragment) {
5300
5356
  output(3, 10);
5357
+ } else if (value === Fragment) {
5358
+ output(3, 11);
5301
5359
  } else if (isQrl(value)) {
5302
- if (!outputRootRef(value)) {
5360
+ if (!outputAsRootRef(value)) {
5303
5361
  const qrl = qrlToString(serializationContext, value);
5304
5362
  const type = preloadQrls.has(value) ? 21 : 20;
5305
5363
  if (0 === depth) {
@@ -5319,7 +5377,7 @@ async function serialize(serializationContext) {
5319
5377
  }
5320
5378
  }
5321
5379
  } else if ("number" == typeof value) {
5322
- Number.isNaN(value) ? output(3, 11) : Number.isFinite(value) ? value === Number.MAX_SAFE_INTEGER ? output(3, 14) : value === Number.MAX_SAFE_INTEGER - 1 ? output(3, 15) : value === Number.MIN_SAFE_INTEGER ? output(3, 16) : output(4, value) : output(3, value < 0 ? 13 : 12);
5380
+ Number.isNaN(value) ? output(3, 12) : Number.isFinite(value) ? value === Number.MAX_SAFE_INTEGER ? output(3, 15) : value === Number.MAX_SAFE_INTEGER - 1 ? output(3, 16) : value === Number.MIN_SAFE_INTEGER ? output(3, 17) : output(4, value) : output(3, value < 0 ? 14 : 13);
5323
5381
  } else if ("object" == typeof value) {
5324
5382
  if (value === EMPTY_ARRAY) {
5325
5383
  output(3, 5);
@@ -5333,20 +5391,22 @@ async function serialize(serializationContext) {
5333
5391
  parent = value, writeObjectValue(value), parent = oldParent, depth--;
5334
5392
  }
5335
5393
  } else if ("string" == typeof value) {
5336
- 0 === value.length ? output(3, 4) : outputRootRef(value) || output(5, value);
5394
+ 0 === value.length ? output(3, 4) : outputAsRootRef(value) || output(5, value);
5337
5395
  } else if (void 0 === value) {
5338
5396
  output(3, 0);
5339
5397
  } else if (value === NEEDS_COMPUTATION) {
5340
5398
  output(3, 7);
5399
+ } else if (value === STORE_ALL_PROPS) {
5400
+ output(3, 8);
5341
5401
  } else {
5342
- if (value !== STORE_ALL_PROPS) {
5402
+ if (value !== _UNINITIALIZED) {
5343
5403
  throw qError(20, [ typeof value ]);
5344
5404
  }
5345
- output(3, 8);
5405
+ output(3, 9);
5346
5406
  }
5347
5407
  };
5348
5408
  const writeObjectValue = value => {
5349
- if (!outputRootRef(value, 1)) {
5409
+ if (!outputAsRootRef(value, 1)) {
5350
5410
  if (isPropsProxy(value)) {
5351
5411
  const varProps = value[_VAR_PROPS];
5352
5412
  const constProps = value[_CONST_PROPS];
@@ -5404,19 +5464,22 @@ async function serialize(serializationContext) {
5404
5464
  const forwardRefId = $resolvePromise$($getCustomSerializerPromise$(value, value.$untrackedValue$), $addRoot$, (resolved, resolvedValue) => new PromiseResult(29, resolved, resolvedValue, value.$effects$, value.$computeQrl$));
5405
5465
  return void output(1, forwardRefId);
5406
5466
  }
5407
- const v = value instanceof ComputedSignalImpl && (1 & value.$flags$ || fastSkipSerialize(value.$untrackedValue$)) ? NEEDS_COMPUTATION : value.$untrackedValue$;
5408
5467
  if (value instanceof WrappedSignalImpl) {
5409
5468
  output(26, [ ...serializeWrappingFn(serializationContext, value), filterEffectBackRefs(value[_EFFECT_BACK_REF]), value.$flags$, value.$hostElement$, ...value.$effects$ || [] ]);
5410
- } else if (value instanceof AsyncComputedSignalImpl) {
5411
- addPreloadQrl(value.$computeQrl$);
5412
- const out = [ value.$computeQrl$, value.$effects$, value.$loadingEffects$, value.$errorEffects$, value.$untrackedLoading$, value.$untrackedError$ ];
5413
- v !== NEEDS_COMPUTATION && out.push(v), output(28, out);
5414
5469
  } else if (value instanceof ComputedSignalImpl) {
5470
+ let v = value.$untrackedValue$;
5471
+ const shouldAlwaysSerialize = 16 & value.$flags$;
5472
+ const shouldNeverSerialize = 8 & value.$flags$;
5473
+ const isInvalid = 1 & value.$flags$;
5474
+ const isSkippable = fastSkipSerialize(value.$untrackedValue$);
5475
+ shouldAlwaysSerialize ? v = value.$untrackedValue$ : (shouldNeverSerialize || isInvalid || isSkippable) && (v = NEEDS_COMPUTATION),
5415
5476
  addPreloadQrl(value.$computeQrl$);
5416
5477
  const out = [ value.$computeQrl$, value.$effects$ ];
5417
- v !== NEEDS_COMPUTATION && out.push(v), output(27, out);
5478
+ const isAsync = value instanceof AsyncComputedSignalImpl;
5479
+ isAsync && out.push(value.$loadingEffects$, value.$errorEffects$, value.$untrackedLoading$, value.$untrackedError$),
5480
+ v !== NEEDS_COMPUTATION && out.push(v), output(isAsync ? 28 : 27, out);
5418
5481
  } else {
5419
- output(25, [ v, ...value.$effects$ || [] ]);
5482
+ output(25, [ value.$untrackedValue$, ...value.$effects$ || [] ]);
5420
5483
  }
5421
5484
  } else if (value instanceof URL) {
5422
5485
  output(7, value.href);
@@ -5494,6 +5557,9 @@ async function serialize(serializationContext) {
5494
5557
  }
5495
5558
  const out = btoa(buf).replace(/=+$/, "");
5496
5559
  output(19, out);
5560
+ } else if (value instanceof SerializationWeakRef) {
5561
+ const forwardRefId = forwardRefsId++;
5562
+ s11nWeakRefs.set(value.$obj$, forwardRefId), forwardRefs[forwardRefId] = -1, output(1, forwardRefId);
5497
5563
  } else {
5498
5564
  if (!vnode_isVNode(value)) {
5499
5565
  throw qError(20, [ typeof value ]);
@@ -5512,20 +5578,19 @@ async function serialize(serializationContext) {
5512
5578
  }
5513
5579
  await (async () => {
5514
5580
  $writer$.write("[");
5515
- let lastRootsLength = 0;
5516
5581
  let rootsLength = serializationContext.$roots$.length;
5517
- for (;lastRootsLength < rootsLength || promises.size; ) {
5518
- 0 !== lastRootsLength && $writer$.write(",");
5582
+ for (;rootIdx < rootsLength || promises.size; ) {
5583
+ 0 !== rootIdx && $writer$.write(",");
5519
5584
  let separator = !1;
5520
- for (let i = lastRootsLength; i < rootsLength; i++) {
5521
- separator ? $writer$.write(",") : separator = !0, writeValue(serializationContext.$roots$[i]);
5585
+ for (;rootIdx < rootsLength; rootIdx++) {
5586
+ separator ? $writer$.write(",") : separator = !0, writeValue(serializationContext.$roots$[rootIdx]);
5522
5587
  }
5523
5588
  if (promises.size) {
5524
5589
  try {
5525
5590
  await Promise.race(promises);
5526
5591
  } catch {}
5527
5592
  }
5528
- lastRootsLength = rootsLength, rootsLength = serializationContext.$roots$.length;
5593
+ rootsLength = serializationContext.$roots$.length;
5529
5594
  }
5530
5595
  forwardRefs.length && ($writer$.write(","), $writer$.write("2,"), outputArray(forwardRefs, value => {
5531
5596
  $writer$.write(String(value));
@@ -5675,7 +5740,7 @@ function preprocessState(data, container) {
5675
5740
  }
5676
5741
 
5677
5742
  function shouldTrackObj(obj) {
5678
- return "object" == typeof obj && null !== obj || "string" == typeof obj && obj.length > 1;
5743
+ return isObject(obj) || "string" == typeof obj && obj.length > 1;
5679
5744
  }
5680
5745
 
5681
5746
  function isObjectLiteral(obj) {
@@ -5687,7 +5752,7 @@ function isResource(value) {
5687
5752
  return "__brand" in value && "resource" === value.__brand;
5688
5753
  }
5689
5754
 
5690
- const frameworkType = obj => "object" == typeof obj && null !== obj && (obj instanceof SignalImpl || obj instanceof Task || isJSXNode(obj)) || isQrl(obj);
5755
+ const frameworkType = obj => isObject(obj) && (obj instanceof SignalImpl || obj instanceof Task || isJSXNode(obj)) || isQrl(obj);
5691
5756
 
5692
5757
  const canSerialize = (value, seen = new WeakSet) => {
5693
5758
  if (null == value || "string" == typeof value || "number" == typeof value || "boolean" == typeof value || "bigint" == typeof value) {
@@ -5757,7 +5822,11 @@ const canSerialize = (value, seen = new WeakSet) => {
5757
5822
  if (isDomRef?.(value)) {
5758
5823
  return !0;
5759
5824
  }
5760
- } else if ("function" == typeof value && (isQrl(value) || isQwikComponent(value))) {
5825
+ } else if ("function" == typeof value) {
5826
+ if (isQrl(value) || isQwikComponent(value)) {
5827
+ return !0;
5828
+ }
5829
+ } else if (value === _UNINITIALIZED) {
5761
5830
  return !0;
5762
5831
  }
5763
5832
  return !1;
@@ -5765,12 +5834,12 @@ const canSerialize = (value, seen = new WeakSet) => {
5765
5834
 
5766
5835
  const QRL_RUNTIME_CHUNK = "mock-chunk";
5767
5836
 
5768
- const _typeIdNames = [ "RootRef", "ForwardRef", "ForwardRefs", "Constant", "Number", "String", "Array", "URL", "Date", "Regex", "VNode", "RefVNode", "BigInt", "URLSearchParams", "Error", "Object", "Promise", "Set", "Map", "Uint8Array", "QRL", "PreloadQRL", "Task", "Resource", "Component", "Signal", "WrappedSignal", "ComputedSignal", "AsyncComputedSignal", "SerializerSignal", "Store", "StoreArray", "FormData", "JSXNode", "PropsProxy", "EffectData" ];
5837
+ const _typeIdNames = [ "RootRef", "ForwardRef", "ForwardRefs", "Constant", "Number", "String", "Array", "URL", "Date", "Regex", "VNode", "RefVNode", "BigInt", "URLSearchParams", "Error", "Object", "Promise", "Set", "Map", "Uint8Array", "QRL", "PreloadQRL", "Task", "Resource", "Component", "Signal", "WrappedSignal", "ComputedSignal", "AsyncComputedSignal", "SerializerSignal", "Store", "StoreArray", "FormData", "JSXNode", "PropsProxy", "SubscriptionData" ];
5769
5838
 
5770
5839
  const circularProofJson = (obj, indent) => {
5771
5840
  const seen = new WeakSet;
5772
- return JSON.stringify(obj, (key, value) => {
5773
- if ("object" == typeof value && null !== value) {
5841
+ return JSON.stringify(obj, (_, value) => {
5842
+ if (isObject(value)) {
5774
5843
  if (seen.has(value)) {
5775
5844
  return `[Circular ${value.constructor.name}]`;
5776
5845
  }
@@ -5800,7 +5869,7 @@ const dumpState = (state, color = !1, prefix = "", limit = 20) => {
5800
5869
  }
5801
5870
  const key = state[i];
5802
5871
  let value = state[++i];
5803
- void 0 === key ? (hasRaw = !0, out.push(`${RED}[raw${"object" == typeof value && value ? ` ${value.constructor.name}` : ""}]${RESET} ${printRaw(value, `${prefix} `)}`)) : (3 === key ? value = constantToName(value) : "string" == typeof value ? (value = JSON.stringify(value),
5872
+ void 0 === key ? (hasRaw = !0, out.push(`${RED}[raw${isObject(value) ? ` ${value.constructor.name}` : ""}]${RESET} ${printRaw(value, `${prefix} `)}`)) : (3 === key ? value = constantToName(value) : "string" == typeof value ? (value = JSON.stringify(value),
5804
5873
  value.length > 120 && (value = value.slice(0, 120) + '"...')) : 2 === key ? value = `[\n${prefix} ${value.join(`\n${prefix} `)}\n${prefix}]` : Array.isArray(value) && (value = value.length ? `[\n${dumpState(value, color, `${prefix} `)}\n${prefix}]` : "[]"),
5805
5874
  out.push(`${RED}${typeIdToName(key)}${RESET} ${value}`));
5806
5875
  }
@@ -5885,17 +5954,13 @@ const _verifySerializable = (value, seen, ctx, preMessage) => {
5885
5954
 
5886
5955
  const noSerializeSet = /*#__PURE__*/ new WeakSet;
5887
5956
 
5888
- const weakSerializeSet = /*#__PURE__*/ new WeakSet;
5889
-
5890
5957
  const shouldSerialize = obj => !isObject(obj) && !isFunction(obj) || !noSerializeSet.has(obj);
5891
5958
 
5892
- const fastSkipSerialize = obj => obj && ("object" == typeof obj || "function" == typeof obj) && (NoSerializeSymbol in obj || noSerializeSet.has(obj));
5959
+ const fastSkipSerialize = obj => obj && (isObject(obj) || "function" == typeof obj) && (NoSerializeSymbol in obj || noSerializeSet.has(obj));
5893
5960
 
5894
- const noSerialize = input => (("object" == typeof input && null !== input || "function" == typeof input) && noSerializeSet.add(input),
5961
+ const noSerialize = input => ((isObject(input) && null !== input || "function" == typeof input) && noSerializeSet.add(input),
5895
5962
  input);
5896
5963
 
5897
- const _weakSerialize = input => (weakSerializeSet.add(input), input);
5898
-
5899
5964
  const NoSerializeSymbol = Symbol("noSerialize");
5900
5965
 
5901
5966
  const SerializerSymbol = Symbol("serialize");
@@ -6391,21 +6456,21 @@ const useConstant = value => {
6391
6456
  return null != val ? val : set(value = isFunction(value) && !isQwikComponent(value) ? value() : value);
6392
6457
  };
6393
6458
 
6394
- const useComputedCommon = (qrl, Class) => {
6459
+ const useComputedCommon = (qrl, createFn, options) => {
6395
6460
  const {val, set} = useSequentialScope();
6396
6461
  if (val) {
6397
6462
  return val;
6398
6463
  }
6399
6464
  assertQrl(qrl);
6400
- const signal = new Class(null, qrl);
6465
+ const signal = createFn(qrl, options);
6401
6466
  return set(signal), throwIfQRLNotResolved(qrl), signal;
6402
6467
  };
6403
6468
 
6404
- const useComputedQrl = qrl => useComputedCommon(qrl, ComputedSignalImpl);
6469
+ const useComputedQrl = (qrl, options) => useComputedCommon(qrl, createComputedSignal, options);
6405
6470
 
6406
6471
  const useComputed$ = implicit$FirstArg(useComputedQrl);
6407
6472
 
6408
- const useSerializerQrl = qrl => useComputedCommon(qrl, SerializerSignalImpl);
6473
+ const useSerializerQrl = qrl => useComputedCommon(qrl, createSerializerSignal);
6409
6474
 
6410
6475
  const useSerializer$ = implicit$FirstArg(useSerializerQrl);
6411
6476
 
@@ -6433,7 +6498,7 @@ const useTask$ = /*#__PURE__*/ implicit$FirstArg(useTaskQrl);
6433
6498
 
6434
6499
  const useVisibleTask$ = /*#__PURE__*/ implicit$FirstArg(useVisibleTaskQrl);
6435
6500
 
6436
- const useAsyncComputedQrl = qrl => useComputedCommon(qrl, AsyncComputedSignalImpl);
6501
+ const useAsyncComputedQrl = (qrl, options) => useComputedCommon(qrl, createAsyncComputedSignal, options);
6437
6502
 
6438
6503
  const useAsyncComputed$ = implicit$FirstArg(useAsyncComputedQrl);
6439
6504
 
@@ -6475,4 +6540,4 @@ const PREFETCH_CODE = /*#__PURE__*/ (c => {
6475
6540
 
6476
6541
  const PrefetchGraph = () => null;
6477
6542
 
6478
- 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, _VAR_PROPS, _deserialize, dumpState as _dumpState, _fnSignal, _getContextElement, _getContextEvent, getDomContainer as _getDomContainer, _getQContainerElement, isJSXNode as _isJSXNode, isStringifiable as _isStringifiable, _jsxBranch, _jsxC, _jsxQ, _jsxS, _jsxSorted, _jsxSplit, _noopQrl, _noopQrlDEV, preprocessState as _preprocessState, _qrlSync, _regSymbol, _restProps, queueQRL as _run, _serialize, scheduleTask as _task, verifySerializable as _verifySerializable, vnode_toString as _vnode_toString, _waitUntilRendered, _walkJSX, _weakSerialize, _wrapProp, _wrapSignal, _wrapStore, component$, componentQrl, createComputed$, createComputedSignal as createComputedQrl, createContextId, h as createElement, createSerializer$, createSerializerSignal as createSerializerQrl, createSignal, event$, eventQrl, getDomContainer, getLocale, getPlatform, h, implicit$FirstArg, inlinedQrl, inlinedQrlDEV, isSignal, jsx, jsxDEV, jsx as jsxs, noSerialize, qrl, qrlDEV, render, setPlatform, sync$, untrack, unwrapStore, useAsyncComputed$, useAsyncComputedQrl, 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 };
6543
+ 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, _deserialize, dumpState as _dumpState, _fnSignal, _getContextContainer, _getContextElement, _getContextEvent, getDomContainer as _getDomContainer, _getQContainerElement, isJSXNode as _isJSXNode, isStringifiable as _isStringifiable, _jsxBranch, _jsxC, _jsxQ, _jsxS, _jsxSorted, _jsxSplit, _noopQrl, _noopQrlDEV, preprocessState as _preprocessState, _qrlSync, _regSymbol, _restProps, queueQRL as _run, _serializationWeakRef, _serialize, scheduleTask as _task, useInvokeContext as _useInvokeContext, verifySerializable as _verifySerializable, vnode_toString as _vnode_toString, _waitUntilRendered, _walkJSX, _wrapProp, _wrapSignal, component$, componentQrl, createAsyncComputed$, createAsyncComputedSignal as createAsyncComputedQrl, createComputed$, createComputedSignal as createComputedQrl, createContextId, h as createElement, createSerializer$, createSerializerSignal as createSerializerQrl, createSignal, event$, eventQrl, getDomContainer, getLocale, getPlatform, h, implicit$FirstArg, inlinedQrl, inlinedQrlDEV, isSignal, jsx, jsxDEV, jsx as jsxs, noSerialize, qrl, qrlDEV, render, setPlatform, sync$, untrack, unwrapStore, useAsyncComputed$, useAsyncComputedQrl, 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 };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qwik.dev/core/loader",
3
- "version": "2.0.0-beta.3-dev+aa098fc",
3
+ "version": "2.0.0-beta.4-dev+9849dcf",
4
4
  "main": "index.mjs",
5
5
  "types": "index.d.ts",
6
6
  "private": true,