@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.
package/dist/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core/server 2.0.0-beta.21-dev+c008e88
3
+ * @qwik.dev/core/server 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
@@ -1202,13 +1202,16 @@ function getBuildBase(opts) {
1202
1202
  return `${import.meta.env.BASE_URL || "/"}build/`;
1203
1203
  }
1204
1204
  var versions = {
1205
- qwik: "2.0.0-beta.21-dev+c008e88",
1205
+ qwik: "2.0.0-beta.23-dev+03de42d",
1206
1206
  qwikDom: "2.1.19"
1207
1207
  };
1208
1208
 
1209
1209
  // packages/qwik/src/server/ssr-container.ts
1210
1210
  import { isDev as isDev6 } from "@qwik.dev/core/build";
1211
1211
  import {
1212
+ _createQRL as createQRL,
1213
+ _qrlToString as qrlToString,
1214
+ _res,
1212
1215
  _SubscriptionData as SubscriptionData,
1213
1216
  _SharedContainer,
1214
1217
  _jsxSorted,
@@ -2726,11 +2729,24 @@ var SSRContainer = class extends _SharedContainer {
2726
2729
  if (!this.serializationCtx.$roots$.length) {
2727
2730
  return;
2728
2731
  }
2729
- this.openElement("script", null, ["type", "qwik/state"]);
2732
+ const attrs = this.stateScriptAttrs();
2733
+ this.openElement("script", null, attrs);
2730
2734
  return maybeThen(this.serializationCtx.$serialize$(), () => {
2731
2735
  this.closeElement();
2732
2736
  });
2733
2737
  }
2738
+ /** Add q-d:qidle attribute to eagerly resume some state if needed */
2739
+ stateScriptAttrs() {
2740
+ const attrs = ["type", "qwik/state"];
2741
+ const eagerResume = this.serializationCtx.$eagerResume$;
2742
+ if (eagerResume.size > 0) {
2743
+ const qrl = createQRL(null, "_res", _res, null, [...eagerResume]);
2744
+ const qrlStr = qrlToString(this.serializationCtx, qrl);
2745
+ attrs.push("q-d:qidle", qrlStr);
2746
+ this.serializationCtx.$eventNames$.add("d:qidle");
2747
+ }
2748
+ return attrs;
2749
+ }
2734
2750
  emitSyncFnsData() {
2735
2751
  const fns = this.serializationCtx.$syncFns$;
2736
2752
  if (fns.length) {
@@ -3109,13 +3125,12 @@ var renderToStream = async (jsx, opts) => {
3109
3125
  await ssrContainer.$renderPromise$;
3110
3126
  flush();
3111
3127
  const snapshotResult = getSnapshotResult(ssrContainer);
3112
- const isDynamic = snapshotResult.resources.some((r) => r._cache !== Infinity);
3113
3128
  const result = {
3114
3129
  snapshotResult,
3115
3130
  flushes: networkFlushes,
3116
3131
  manifest: resolvedManifest?.manifest,
3117
3132
  size: ssrContainer.size,
3118
- isStatic: !isDynamic,
3133
+ isStatic: false,
3119
3134
  timing
3120
3135
  };
3121
3136
  return result;
@@ -16,7 +16,40 @@ declare interface AddRootFn {
16
16
  (obj: unknown, returnRef: true): SeenRef;
17
17
  }
18
18
 
19
- declare type AllSignalFlags = SignalFlags | WrappedSignalFlags | SerializationSignalFlags;
19
+ declare type AllSignalFlags = SignalFlags | WrappedSignalFlags | SerializationSignalFlags | AsyncSignalFlags;
20
+
21
+ /** @public */
22
+ declare interface AsyncSignal<T = unknown> extends ComputedSignal<T> {
23
+ /**
24
+ * Whether the signal is currently loading. This will trigger lazy loading of the signal, so you
25
+ * can use it like this:
26
+ *
27
+ * ```tsx
28
+ * signal.loading ? <Loading /> : signal.error ? <Error /> : <Component
29
+ * value={signal.value} />
30
+ * ```
31
+ */
32
+ loading: boolean;
33
+ /**
34
+ * The error that occurred while computing the signal, if any. This will be cleared when the
35
+ * signal is successfully computed.
36
+ */
37
+ error: Error | undefined;
38
+ /**
39
+ * Poll interval in ms. Writable and immediately effective when the signal has consumers. If set
40
+ * to `0`, polling stops.
41
+ */
42
+ interval: number;
43
+ /** A promise that resolves when the value is computed or rejected. */
44
+ promise(): Promise<void>;
45
+ /** Abort the current computation and run cleanups if needed. */
46
+ abort(reason?: any): void;
47
+ }
48
+
49
+ declare const enum AsyncSignalFlags {
50
+ EAGER_CLEANUP = 32,
51
+ AWAIT_PREVIOUS = 64
52
+ }
20
53
 
21
54
  /** Class for back reference to the EffectSubscription */
22
55
  declare abstract class BackRef {
@@ -45,6 +78,26 @@ declare const enum ChoreBits {
45
78
  DIRTY_MASK = 127
46
79
  }
47
80
 
81
+ /**
82
+ * A computed signal is a signal which is calculated from other signals. When the signals change,
83
+ * the computed signal is recalculated, and if the result changed, all tasks which are tracking the
84
+ * signal will be re-run and all components that read the signal will be re-rendered.
85
+ *
86
+ * @public
87
+ */
88
+ declare interface ComputedSignal<T> extends ReadonlySignal<T> {
89
+ /**
90
+ * Use this to force running subscribers, for example when the calculated value mutates but
91
+ * remains the same object.
92
+ */
93
+ force(): void;
94
+ /**
95
+ * Use this to force recalculation and running subscribers, for example when the calculated value
96
+ * mutates but remains the same object.
97
+ */
98
+ invalidate(): void;
99
+ }
100
+
48
101
  /**
49
102
  * Effect is something which needs to happen (side-effect) due to signal value change.
50
103
  *
@@ -67,8 +120,8 @@ declare interface Container {
67
120
  $buildBase$: string | null;
68
121
  $renderPromise$: Promise<void> | null;
69
122
  $resolveRenderPromise$: (() => void) | null;
70
- $cursorCount$: number;
71
- $pausedCursorCount$: number;
123
+ $pendingCount$: number;
124
+ $checkPendingCount$(): void;
72
125
  handleError(err: any, $host$: HostElement | null): void;
73
126
  getParentHost(host: HostElement): HostElement | null;
74
127
  setContext<T>(host: HostElement, context: ContextId<T>, value: T): void;
@@ -179,7 +232,7 @@ declare interface DescriptorBase<T = unknown, B = unknown> extends BackRef {
179
232
  $el$: HostElement;
180
233
  $qrl$: QRLInternal<T>;
181
234
  $state$: B | undefined;
182
- $destroy$: NoSerialize<() => void> | null;
235
+ $destroy$: (() => void) | null;
183
236
  }
184
237
 
185
238
  declare type DomRef = {
@@ -337,19 +390,9 @@ declare interface NodePropData {
337
390
  $isConst$: boolean;
338
391
  }
339
392
 
340
- /**
341
- * Returned type of the `noSerialize()` function. It will be TYPE or undefined.
342
- *
343
- * @public
344
- * @see noSerialize
345
- */
346
- declare type NoSerialize<T> = (T & {
347
- __no_serialize__: true;
348
- }) | undefined;
349
-
350
393
  declare type ObjToProxyMap = WeakMap<any, any>;
351
394
 
352
- declare type PossibleEvents = Event | SimplifiedServerRequestEvent | typeof TaskEvent | typeof RenderEvent | typeof ResourceEvent;
395
+ declare type PossibleEvents = Event | SimplifiedServerRequestEvent | typeof TaskEvent | typeof RenderEvent;
353
396
 
354
397
  declare type Props = Record<string, unknown>;
355
398
 
@@ -531,18 +574,13 @@ declare interface ReadonlySignal<T = unknown> {
531
574
 
532
575
  declare const RenderEvent = "qRender";
533
576
 
534
- declare const ResourceEvent = "qResource";
535
-
536
577
  declare interface ResourceReturnInternal<T> {
537
578
  __brand: 'resource';
538
- _state: 'pending' | 'resolved' | 'rejected';
539
- _resolved: T | undefined;
540
- _error: Error | undefined;
541
- _cache: number;
542
- _timeout: number;
543
- _generation: number;
544
579
  value: Promise<T>;
545
580
  loading: boolean;
581
+ signal: AsyncSignal<{
582
+ r: T;
583
+ }>;
546
584
  }
547
585
 
548
586
  /** Stores the location of an object. If no parent, it's a root. */
@@ -552,7 +590,7 @@ declare type SeenRef = {
552
590
  };
553
591
 
554
592
  declare interface SerializationContext {
555
- $serialize$: () => void;
593
+ $serialize$: () => ValueOrPromise<void>;
556
594
  $symbolToChunkResolver$: SymbolToChunkResolver;
557
595
  /**
558
596
  * Map from object to parent and index reference.
@@ -586,9 +624,10 @@ declare interface SerializationContext {
586
624
  $syncFns$: string[];
587
625
  $eventQrls$: Set<QRL>;
588
626
  $eventNames$: Set<string>;
589
- $resources$: Set<ResourceReturnInternal<unknown>>;
590
627
  $renderSymbols$: Set<string>;
591
628
  $storeProxyMap$: ObjToProxyMap;
629
+ $eagerResume$: Set<unknown>;
630
+ $resources$: Set<ResourceReturnInternal<any>>;
592
631
  $getProp$: (obj: any, prop: string) => any;
593
632
  $setProp$: (obj: any, prop: string, value: any) => void;
594
633
  }
@@ -700,14 +739,14 @@ declare class SubscriptionData {
700
739
 
701
740
  declare type SymbolToChunkResolver = (symbol: string) => string;
702
741
 
703
- declare class Task<T = unknown, B = T> extends BackRef implements DescriptorBase<unknown, Signal<B> | ResourceReturnInternal<B>> {
742
+ declare class Task<T = unknown, B = T> extends BackRef implements DescriptorBase<unknown, Signal<B>> {
704
743
  $flags$: number;
705
744
  $index$: number;
706
745
  $el$: HostElement;
707
746
  $qrl$: QRLInternal<T>;
708
- $state$: Signal<B> | ResourceReturnInternal<B> | undefined;
709
- $destroy$: NoSerialize<() => void> | null;
710
- constructor($flags$: number, $index$: number, $el$: HostElement, $qrl$: QRLInternal<T>, $state$: Signal<B> | ResourceReturnInternal<B> | undefined, $destroy$: NoSerialize<() => void> | null);
747
+ $state$: Signal<B> | undefined;
748
+ $destroy$: (() => void) | null;
749
+ constructor($flags$: number, $index$: number, $el$: HostElement, $qrl$: QRLInternal<T>, $state$: Signal<B> | undefined, $destroy$: (() => void) | null);
711
750
  }
712
751
 
713
752
  declare const TaskEvent = "qTask";
@@ -895,11 +934,6 @@ declare class WrappedSignalImpl<T> extends SignalImpl<T> implements BackRef {
895
934
  [_EFFECT_BACK_REF]: Map<EffectProperty | string, EffectSubscription> | undefined;
896
935
  constructor(container: Container | null, fn: (...args: any[]) => T, args: any[], fnStr: string | null, flags?: SignalFlags);
897
936
  invalidate(): void;
898
- /**
899
- * Use this to force running subscribers, for example when the calculated value has mutated but
900
- * remained the same object.
901
- */
902
- force(): void;
903
937
  get untrackedValue(): T;
904
938
  $computeIfNeeded$(): void;
905
939
  $unwrapIfSignal$(): SignalImpl<T> | WrappedSignalImpl<T>;