@qwik.dev/core 2.0.0-beta.36 → 2.0.0-beta.38

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.
@@ -108,7 +108,7 @@ declare type AllEventsMap = Omit<AllEventMapRaw, keyof EventCorrectionMap> & Eve
108
108
 
109
109
  declare type _AllowPlainQrl<Q> = QRLEventHandlerMulti<any, any> extends Q ? Q extends QRLEventHandlerMulti<infer EV, infer EL> ? Q | (EL extends Element ? EventHandler<EV, EL> : never) : Q : Q extends QRL<infer U> ? Q | U : NonNullable<Q> extends never ? Q : QRL<Q> | Q;
110
110
 
111
- declare type AllSignalFlags = SignalFlags | WrappedSignalFlags | SerializationSignalFlags | AsyncSignalFlags;
111
+ declare type AllSignalFlags = ComputedSignalFlags | SerializationSignalFlags | AsyncSignalFlags;
112
112
 
113
113
  /**
114
114
  * TS defines these with the React syntax which is not compatible with Qwik. E.g. `ariaAtomic`
@@ -366,56 +366,17 @@ declare interface AriaAttributes {
366
366
  /** @public */
367
367
  declare type AriaRole = 'alert' | 'alertdialog' | 'application' | 'article' | 'banner' | 'button' | 'cell' | 'checkbox' | 'columnheader' | 'combobox' | 'complementary' | 'contentinfo' | 'definition' | 'dialog' | 'directory' | 'document' | 'feed' | 'figure' | 'form' | 'grid' | 'gridcell' | 'group' | 'heading' | 'img' | 'link' | 'list' | 'listbox' | 'listitem' | 'log' | 'main' | 'marquee' | 'math' | 'menu' | 'menubar' | 'menuitem' | 'menuitemcheckbox' | 'menuitemradio' | 'navigation' | 'none' | 'note' | 'option' | 'presentation' | 'progressbar' | 'radio' | 'radiogroup' | 'region' | 'row' | 'rowgroup' | 'rowheader' | 'scrollbar' | 'search' | 'searchbox' | 'separator' | 'slider' | 'spinbutton' | 'status' | 'switch' | 'tab' | 'table' | 'tablist' | 'tabpanel' | 'term' | 'textbox' | 'timer' | 'toolbar' | 'tooltip' | 'tree' | 'treegrid' | 'treeitem' | (string & {});
368
368
 
369
- declare type AsyncCtx<T = unknown> = {
370
- track: Tracker;
371
- /**
372
- * Register a cleanup callback to be called when the async computation is aborted or completed.
373
- * The next invocation will await the previous cleanup. If you do not want this, do not return a
374
- * Promise.
375
- */
376
- cleanup: (callback: () => void | Promise<void>) => void;
377
- /**
378
- * A lazily created AbortSignal, for interrupting the async computation when needed, e.g. when the
379
- * component is unmounted or the computation is invalidated. Pass it to `fetch` or other APIs that
380
- * support it to ensure that unnecessary work is not performed.
381
- */
382
- readonly abortSignal: AbortSignal;
383
- /** The result of the previous computation, if any */
384
- readonly previous: T | undefined;
385
- /** Extra info passed to `invalidate(info)` for this computation, if any. */
386
- readonly info?: unknown;
387
- };
388
-
389
369
  /**
390
- * Note, we don't pass the generic type to AsyncCtx because it causes TypeScript to not infer the
370
+ * Note, we don't pass the generic type to ComputeCtx because it causes TypeScript to not infer the
391
371
  * type of the resource correctly. The type is only used for the `previous` property, which is not
392
372
  * commonly used, and can be easily cast if needed.
393
373
  *
374
+ * @deprecated Use `useComputed$` with an async function instead.
394
375
  * @public
395
376
  */
396
- export declare type AsyncFn<T> = (ctx: AsyncCtx) => ValueOrPromise<T>;
397
-
398
- /** Retains job metadata and also serves as the argument for the compute function */
399
- declare class AsyncJob<T> implements AsyncCtx<T> {
400
- readonly $signal$: AsyncSignalImpl<T>;
401
- /** First holds the compute promise and then the cleanup promise */
402
- $promise$: Promise<void> | null | void;
403
- $cleanupRequested$: boolean;
404
- $canWrite$: boolean;
405
- $track$: AsyncCtx<T>['track'] | undefined;
406
- $cleanups$: Parameters<AsyncCtx<T>['cleanup']>[0][] | undefined;
407
- $abortController$: AbortController | undefined;
408
- info: unknown;
409
- $infoVersion$: number | undefined;
410
- constructor($signal$: AsyncSignalImpl<T>, info: unknown, $infoVersion$: number | undefined);
411
- get track(): AsyncCtx<T>['track'];
412
- get abortSignal(): AbortSignal;
413
- /** Backward compatible cache method for resource */
414
- cache(): void;
415
- get previous(): T | undefined;
416
- cleanup(callback: () => void): void;
417
- }
377
+ export declare type AsyncFn<T> = (ctx: ComputeCtx) => ValueOrPromise<T>;
418
378
 
379
+ /** @deprecated Use `ComputeQRL` instead. */
419
380
  declare type AsyncQRL<T> = _QRLInternal<AsyncFn<T>>;
420
381
 
421
382
  /**
@@ -440,70 +401,20 @@ declare type AsyncQRL<T> = _QRLInternal<AsyncFn<T>>;
440
401
  * If the async function threw an error, reading the `.value` will throw that same error. Read from
441
402
  * `.error` to check if there was an error.
442
403
  *
404
+ * @deprecated Use `ComputedSignal` instead, it has async support now.
443
405
  * @public
444
406
  */
445
- export declare interface AsyncSignal<T = unknown> extends ComputedSignal<T> {
446
- /**
447
- * Whether the signal is currently loading. This will trigger lazy loading of the signal, so you
448
- * can use it like this:
449
- *
450
- * ```tsx
451
- * signal.loading ? <Loading /> : signal.error ? <Error /> : <Component
452
- * value={signal.value} />
453
- * ```
454
- */
455
- loading: boolean;
456
- /**
457
- * Lets you read the loading state without subscribing to `.loading` updates. It also triggers
458
- * lazy loading of the signal.
459
- *
460
- * Setting it will trigger listeners for `.loading`.
461
- */
462
- untrackedLoading: boolean;
463
- /**
464
- * The error that occurred while computing the signal, if any. This will be cleared when the
465
- * signal is successfully computed. It does not trigger lazy loading of the signal.
466
- */
467
- error: Error | undefined;
468
- /**
469
- * Lets you read the error state without subscribing to `.error` updates. It does not trigger lazy
470
- * loading of the signal.
471
- *
472
- * Setting it will trigger listeners for `.error`.
473
- */
474
- untrackedError: Error | undefined;
475
- /**
476
- * Expiration time in ms. Writable and immediately effective.
477
- *
478
- * When set, the signal is invalidated after this many ms. Whether it auto-recomputes depends on
479
- * the `poll` property. `0` means no expiration.
480
- */
481
- expires: number;
482
- /**
483
- * Whether to automatically re-run the function when the value expires. Writable and immediately
484
- * effective. Only relevant when `expires` is set.
485
- *
486
- * Defaults to `true`.
487
- */
488
- poll: boolean;
489
- /** @deprecated Use `expires` and `poll` instead. Will be removed before v2 */
490
- interval: number;
491
- /** A promise that resolves when the value is computed or rejected. */
492
- promise(): Promise<void>;
493
- /** Abort the current computation and run cleanups if needed. */
494
- abort(reason?: any): void;
495
- /**
496
- * Use this to force recalculation. If you pass `info`, it will be provided to the calculation
497
- * function.
498
- */
499
- invalidate(info?: unknown): void;
500
- }
407
+ export declare type AsyncSignal<T = unknown> = ComputedSignal<T>;
501
408
 
502
409
  declare const enum AsyncSignalFlags {
503
410
  EAGER_CLEANUP = 32,
504
411
  CLIENT_ONLY = 64,
505
412
  CLEAR_ON_INVALIDATE = 128,
506
- NO_POLL = 256
413
+ NO_POLL = 256,
414
+ /** The compute fn is async: the async engine (jobs, loading, error) is active */
415
+ ASYNC_MODE = 512,
416
+ /** Invoke the compute fn AsyncSignal-style: pass the ComputeCtx argument, no auto-tracking */
417
+ CTX_ARG = 1024
507
418
  }
508
419
 
509
420
  /**
@@ -513,157 +424,21 @@ declare const enum AsyncSignalFlags {
513
424
  *
514
425
  * # ================================
515
426
  *
427
+ * The async engine (jobs, loading, error, polling) lives in ComputedSignalImpl; this subclass
428
+ * configures it from options and switches the compute invocation to CTX_ARG mode: the compute fn
429
+ * receives the ComputeCtx argument and tracks only via its explicit `track()` (no auto-tracking).
430
+ *
516
431
  * @internal
517
432
  */
518
- declare class AsyncSignalImpl<T> extends ComputedSignalImpl<T, AsyncQRL<T>> implements BackRef, AsyncSignal<T> {
519
- $untrackedLoading$: boolean;
520
- $untrackedError$: Error | undefined;
521
- $current$: AsyncJob<T> | null;
522
- $jobs$: AsyncJob<T>[] | undefined;
523
- $concurrency$: number | undefined;
524
- $expires$: number | undefined;
525
- $timeoutMs$: number | undefined;
526
- $loadingEffects$: undefined | Set<EffectSubscription>;
527
- $errorEffects$: undefined | Set<EffectSubscription>;
528
- $pollTimeoutId$: ReturnType<typeof setTimeout> | undefined;
529
- $computationTimeoutId$: ReturnType<typeof setTimeout> | undefined;
530
- $info$: unknown | undefined;
531
- $infoVersion$: number | undefined;
532
- [_EFFECT_BACK_REF]: Map<EffectProperty | string, EffectSubscription> | undefined;
533
- constructor(container: _Container | null, fn: AsyncQRL<T>, flags?: SignalFlags | SerializationSignalFlags, options?: AsyncSignalOptions<T>);
534
- get untrackedValue(): T;
535
- set untrackedValue(value: T);
536
- /**
537
- * Read the value, subscribing if in a tracking context. Triggers computation if needed.
538
- *
539
- * Setting the value will mark the signal as not loading and clear any error, and prevent any
540
- * pending computations from writing their results.
541
- *
542
- * If you want to set the value without affecting loading or error state, set `untrackedValue`
543
- * instead and make sure to trigger effects manually if needed.
544
- *
545
- * If you want to abort pending computations when setting, you have to call `abort()` manually.
546
- */
547
- get value(): T;
548
- set value(value: T);
549
- /**
550
- * Loading is true if the signal is still waiting for the promise to resolve, false if the promise
551
- * has resolved or rejected.
552
- *
553
- * Accessing .loading will trigger computation if needed, since it's often used like
554
- * `signal.loading ? <Loading /> : signal.value`.
555
- */
556
- get loading(): boolean;
557
- set untrackedLoading(value: boolean);
558
- get untrackedLoading(): boolean;
559
- /** The error that occurred when the signal was resolved. */
560
- get error(): Error | undefined;
561
- set untrackedError(value: Error | undefined);
562
- get untrackedError(): Error | undefined;
563
- get expires(): number;
564
- set expires(value: number);
565
- get poll(): boolean;
566
- set poll(value: boolean);
567
- /** @deprecated Use `expires` and `poll` instead. */
568
- get interval(): number;
569
- set interval(value: number);
570
- /** Invalidates the signal, causing it to re-compute its value. */
571
- invalidate(info?: unknown): Promise<void>;
572
- $setInvalid$(allowRecalc: boolean, mustClear: boolean | number): void;
573
- /** Abort the current computation and run cleanups if needed. */
574
- abort(reason?: any): void;
575
- /** Schedule eager cleanup on next macro task if no subscribers remain. */
576
- $scheduleEagerCleanup$(): void;
577
- /** Returns a promise resolves when the signal finished computing. */
578
- promise(): Promise<void>;
579
- /** Run the computation if needed */
580
- $computeIfNeeded$(): void;
581
- $runComputation$(running: AsyncJob<T>): Promise<void>;
582
- /**
583
- * Sets the error from the given job. We only accept errors from the current job and we ignore
584
- * AbortErrors.
585
- */
586
- $setError$(job: AsyncJob<T>, error: Error): void;
587
- /** Called after SSR/unmount */
588
- $destroy$(): Promise<void>;
589
- private $clearNextPoll$;
590
- private $scheduleNextPoll$;
591
- private $hasSubscribers$;
592
- $requestCleanups$(job: AsyncJob<T>, reason?: any): void;
593
- /** Clean up and trigger signal compute once complete */
594
- $runCleanups$(job: AsyncJob<T>): Promise<void> | undefined;
433
+ export declare class _AsyncSignalImpl<T> extends ComputedSignalImpl<T, AsyncQRL<T>> implements AsyncSignal<T> {
434
+ constructor(container: _Container | null, fn: AsyncQRL<T>, flags?: number, options?: AsyncSignalOptions<T>);
595
435
  }
596
436
 
597
- /** @public */
598
- export declare interface AsyncSignalOptions<T> extends ComputedOptions {
599
- /** Like useSignal's `initial`; prevents the throw on first read when uninitialized */
600
- initial?: T | (() => T);
601
- /**
602
- * Maximum number of concurrent computations. Use `0` for unlimited.
603
- *
604
- * Defaults to `1`.
605
- */
606
- concurrency?: number;
607
- /**
608
- * When subscribers drop to 0, run cleanup in the next tick, instead of waiting for the function
609
- * inputs to change.
610
- *
611
- * Defaults to `false`, meaning cleanup happens only when inputs change.
612
- */
613
- eagerCleanup?: boolean;
614
- /**
615
- * Time in milliseconds after which the value expires.
616
- *
617
- * When the value expires and subscribers exist, the signal is invalidated. If `poll` is `true`
618
- * (default), the function is re-run automatically. If `poll` is `false`, the value is marked
619
- * stale and recomputation happens when reading `.value` or `.loading`.
620
- *
621
- * `0` (default) means no expiration.
622
- */
623
- expires?: number;
624
- /**
625
- * Whether to automatically re-run the function when the value expires. Only relevant when
626
- * `expires` is set.
627
- *
628
- * Defaults to `true`.
629
- */
630
- poll?: boolean;
631
- /** @deprecated Use `expires` and `poll` instead. Will be removed before v2 */
632
- interval?: number;
633
- /**
634
- * When true, the async computation is postponed to the browser. On SSR, the signal remains
635
- * INVALID and does not execute the function. On the client, it will compute on first read.
636
- *
637
- * Defaults to `false`.
638
- */
639
- clientOnly?: boolean;
640
- /**
641
- * When true (default), the previous value is kept while the signal re-computes after
642
- * invalidation, so reads return stale data instead of throwing a promise. Reactivity will then
643
- * update the readers when the new value is ready.
644
- *
645
- * When false, invalidation clears the value so reads throw the computation promise (like the
646
- * initial load), which is useful for navigations where showing old data would be confusing.
647
- *
648
- * Note that polling invalidations (`expires` with `poll: true`) are not affected by this option
649
- * and will keep the old value while the new value is loading, to avoid flashing loaders.
650
- *
651
- * This option only affects manual invalidations via `invalidate()`, and non-polling expirations
652
- * (`poll: false`, or there are no subscribers).
653
- *
654
- * Defaults to `true`.
655
- */
656
- allowStale?: boolean;
657
- /**
658
- * Maximum time in milliseconds to wait for the async computation to complete. If exceeded, the
659
- * computation is aborted and an error is thrown.
660
- *
661
- * If `0`, no timeout is applied.
662
- *
663
- * Defaults to `0`.
664
- */
665
- timeout?: number;
666
- }
437
+ /**
438
+ * @deprecated Use `ComputedOptions` instead.
439
+ * @public
440
+ */
441
+ export declare type AsyncSignalOptions<T> = ComputedOptions<T>;
667
442
 
668
443
  /**
669
444
  * Replace given element's props with custom types and return all props specific to the element. Use
@@ -709,7 +484,7 @@ export declare let _captures: Readonly<unknown[]> | null;
709
484
  *
710
485
  * @internal
711
486
  */
712
- export declare function _chk(this: string | undefined, _: any, element: HTMLInputElement): void;
487
+ export declare function _chk(this: string | undefined, _: any, element: HTMLInputElement): void | Promise<void>;
713
488
 
714
489
  declare const enum ChoreBits {
715
490
  NONE = 0,
@@ -838,17 +613,117 @@ declare type ComponentChildren<PROPS> = PROPS extends {
838
613
  /** @internal */
839
614
  export declare const componentQrl: <PROPS extends Record<any, any>>(componentQrl: QRL<OnRenderFn<PROPS>>) => Component<PROPS>;
840
615
 
841
- /** @public */
842
- export declare type ComputedFn<T> = () => T;
616
+ declare type ComputeCtx<T = unknown> = {
617
+ /**
618
+ * Track reactive reads so the computation re-runs when they change. Computed functions track
619
+ * synchronous reads automatically, but after the first `await` the tracking context is lost, so
620
+ * later reads must go through `track()`.
621
+ */
622
+ readonly track: Tracker;
623
+ /**
624
+ * Register a cleanup callback to be called when the async computation is aborted or completed.
625
+ * The next invocation will await the previous cleanup. If you do not want this, do not return a
626
+ * Promise.
627
+ */
628
+ cleanup: (callback: () => void | Promise<void>) => void;
629
+ /**
630
+ * A lazily created AbortSignal, for interrupting the async computation when needed, e.g. when the
631
+ * component is unmounted or the computation is invalidated. Pass it to `fetch` or other APIs that
632
+ * support it to ensure that unnecessary work is not performed.
633
+ */
634
+ readonly abortSignal: AbortSignal;
635
+ /** The result of the previous computation, if any */
636
+ readonly previous: T | undefined;
637
+ /** Extra info passed to `invalidate(info)` for this computation, if any. */
638
+ readonly info?: unknown;
639
+ };
640
+
641
+ /**
642
+ * The compute function. The context provides `track()`, `previous` (the last computed value),
643
+ * `info` (the argument of the `invalidate(info)` call that triggered this computation), `cleanup()`
644
+ * and `abortSignal`. Synchronous reactive state reads are tracked automatically, use `untrack()` to
645
+ * read signals without tracking. Return a `Promise` (or use an `async` function) for async values.
646
+ * After the first `await`, reads are no longer tracked automatically and must use `track()`.
647
+ *
648
+ * @public
649
+ */
650
+ export declare type ComputedFn<T> = (ctx: ComputeCtx) => ValueOrPromise<T>;
843
651
 
844
652
  /** @public */
845
- export declare interface ComputedOptions {
653
+ export declare interface ComputedOptions<T = unknown> {
846
654
  serializationStrategy?: SerializationStrategy;
847
655
  container?: _Container;
656
+ /** Like useSignal's `initial`; prevents the throw on first read when uninitialized */
657
+ initial?: Awaited<T> | (() => Awaited<T>);
658
+ /**
659
+ * Maximum number of concurrent computations. Use `0` for unlimited.
660
+ *
661
+ * Defaults to `1`.
662
+ */
663
+ concurrency?: number;
664
+ /**
665
+ * When subscribers drop to 0, run cleanup in the next tick, instead of waiting for the function
666
+ * inputs to change.
667
+ *
668
+ * Defaults to `false`, meaning cleanup happens only when inputs change.
669
+ */
670
+ eagerCleanup?: boolean;
671
+ /**
672
+ * Time in milliseconds after which the value expires.
673
+ *
674
+ * When the value expires and subscribers exist, the signal is invalidated. If `poll` is `true`
675
+ * (default), the function is re-run automatically. If `poll` is `false`, the value is marked
676
+ * stale and recomputation happens when reading `.value` or `.loading`.
677
+ *
678
+ * `0` (default) means no expiration.
679
+ */
680
+ expires?: number;
681
+ /**
682
+ * Whether to automatically re-run the function when the value expires. Only relevant when
683
+ * `expires` is set.
684
+ *
685
+ * Defaults to `true`.
686
+ */
687
+ poll?: boolean;
688
+ /** @deprecated Use `expires` and `poll` instead. Will be removed before v2 */
689
+ interval?: number;
690
+ /**
691
+ * When true, the async computation is postponed to the browser. On SSR, the signal remains
692
+ * INVALID and does not execute the function. On the client, it will compute on first read.
693
+ *
694
+ * Defaults to `false`.
695
+ */
696
+ clientOnly?: boolean;
697
+ /**
698
+ * When true (default), the previous value is kept while the signal re-computes after
699
+ * invalidation, so reads return stale data instead of throwing a promise. Reactivity will then
700
+ * update the readers when the new value is ready.
701
+ *
702
+ * When false, invalidation clears the value so reads throw the computation promise (like the
703
+ * initial load), which is useful for navigations where showing old data would be confusing.
704
+ *
705
+ * Note that polling invalidations (`expires` with `poll: true`) are not affected by this option
706
+ * and will keep the old value while the new value is loading, to avoid flashing loaders.
707
+ *
708
+ * This option only affects manual invalidations via `invalidate()`, and non-polling expirations
709
+ * (`poll: false`, or there are no subscribers).
710
+ *
711
+ * Defaults to `true`.
712
+ */
713
+ allowStale?: boolean;
714
+ /**
715
+ * Maximum time in milliseconds to wait for the async computation to complete. If exceeded, the
716
+ * computation is aborted and an error is thrown.
717
+ *
718
+ * If `0`, no timeout is applied.
719
+ *
720
+ * Defaults to `0`.
721
+ */
722
+ timeout?: number;
848
723
  }
849
724
 
850
725
  /** @public */
851
- export declare type ComputedReturnType<T> = T extends Promise<any> ? never : ComputedSignal<T>;
726
+ export declare type ComputedReturnType<T> = ComputedSignal<Awaited<T>>;
852
727
 
853
728
  /**
854
729
  * A computed signal is a signal which is calculated from other signals. When the signals change,
@@ -862,28 +737,194 @@ export declare interface ComputedSignal<T> extends Signal<T> {
862
737
  force(): void;
863
738
  /** Use this to force recalculation. */
864
739
  invalidate(): void;
740
+ /**
741
+ * Whether the signal is currently loading. This will trigger lazy computation of the signal, so
742
+ * you can use it like this:
743
+ *
744
+ * ```tsx
745
+ * signal.pending ? <Loading /> : signal.error ? <Error /> : <Component
746
+ * value={signal.value} />
747
+ * ```
748
+ */
749
+ pending: boolean;
750
+ /**
751
+ * Lets you read the pending state without subscribing to `.pending` updates. It also triggers
752
+ * lazy computation of the signal.
753
+ *
754
+ * Setting it will trigger listeners for `.pending`.
755
+ */
756
+ untrackedPending: boolean;
757
+ /** @deprecated Use `pending` instead */
758
+ loading: boolean;
759
+ /** @deprecated Use `untrackedPending` instead */
760
+ untrackedLoading: boolean;
761
+ /**
762
+ * The error that occurred while computing the signal, if any, including synchronous throws. This
763
+ * will be cleared when the signal is successfully computed. It also triggers lazy computation of
764
+ * the signal. While the error is set, reading `.value` throws it.
765
+ */
766
+ error: Error | undefined;
767
+ /**
768
+ * Lets you read the error state without subscribing to `.error` updates. It also triggers lazy
769
+ * computation of the signal.
770
+ *
771
+ * Setting it will trigger listeners for `.error`.
772
+ */
773
+ untrackedError: Error | undefined;
774
+ /**
775
+ * Expiration time in ms. Writable and immediately effective.
776
+ *
777
+ * When set, the signal is invalidated after this many ms. Whether it auto-recomputes depends on
778
+ * the `poll` property. `0` means no expiration.
779
+ */
780
+ expires: number;
781
+ /**
782
+ * Whether to automatically re-run the function when the value expires. Writable and immediately
783
+ * effective. Only relevant when `expires` is set.
784
+ *
785
+ * Defaults to `true`.
786
+ */
787
+ poll: boolean;
788
+ /** @deprecated Use `expires` and `poll` instead. Will be removed before v2 */
789
+ interval: number;
790
+ /** A promise that resolves when the value is computed or rejected. */
791
+ promise(): Promise<void>;
792
+ /** Abort the current computation and run cleanups if needed. */
793
+ abort(reason?: any): void;
794
+ /**
795
+ * Use this to force recalculation. If you pass `info`, it will be provided to the calculation
796
+ * function.
797
+ */
798
+ invalidate(info?: unknown): void;
799
+ }
800
+
801
+ declare const enum ComputedSignalFlags {
802
+ INVALID = 1,
803
+ RUN_EFFECTS = 2,
804
+ PRESERVE_ON_SEQ_CLEANUP = 4
865
805
  }
866
806
 
867
807
  /**
868
808
  * A signal which is computed from other signals.
869
809
  *
870
- * The value is available synchronously, but the computation is done lazily.
810
+ * Sync compute functions resolve synchronously and every read they perform is auto-tracked. When
811
+ * the compute function turns out to be async (it returned a promise), the signal lazily switches on
812
+ * the async engine — jobs, `loading`, `error`, polling — giving it the same API as an AsyncSignal.
813
+ * Auto-tracking only covers reads before the first await point (the invoke context is lost after
814
+ * it); later reads must use the ComputeCtx `track()`.
871
815
  */
872
816
  declare class ComputedSignalImpl<T, S extends _QRLInternal = ComputeQRL<T>> extends SignalImpl<T> implements BackRef {
873
817
  /**
874
818
  * The compute function is stored here.
875
819
  *
876
- * The computed functions must be executed synchronously (because of this we need to eagerly
877
- * resolve the QRL during the mark dirty phase so that any call to it will be synchronous). )
820
+ * Sync computed functions must be executed synchronously (because of this we need to eagerly
821
+ * resolve the QRL during the mark dirty phase so that any call to it will be synchronous).
878
822
  */
879
823
  $computeQrl$: S;
880
- $flags$: SignalFlags | SerializationSignalFlags;
881
- [_EFFECT_BACK_REF]: Map<EffectProperty | string, EffectSubscription> | undefined;
882
- constructor(container: _Container | null, fn: S, flags?: SignalFlags | SerializationSignalFlags);
883
- invalidate(): void;
824
+ $flags$: number;
825
+ [_EFFECT_BACK_REF]: Map<_EffectProperty | string, EffectSubscription> | undefined;
826
+ $untrackedPending$: boolean | undefined;
827
+ $untrackedError$: Error | undefined;
828
+ $current$: Job<T> | null | undefined;
829
+ $jobs$: Job<T>[] | undefined;
830
+ $concurrency$: number | undefined;
831
+ $expires$: number | undefined;
832
+ $timeoutMs$: number | undefined;
833
+ $loadingEffects$: undefined | Set<EffectSubscription>;
834
+ $errorEffects$: undefined | Set<EffectSubscription>;
835
+ $pollTimeoutId$: ReturnType<typeof setTimeout> | undefined;
836
+ $computationTimeoutId$: ReturnType<typeof setTimeout> | undefined;
837
+ $info$: unknown | undefined;
838
+ $infoVersion$: number | undefined;
839
+ constructor(container: _Container | null, fn: S, flags?: number, options?: ComputedOptions<T>);
840
+ invalidate(info?: unknown): void;
841
+ /**
842
+ * Read the value, subscribing if in a tracking context. Triggers computation if needed.
843
+ *
844
+ * Setting the value will mark the signal as not loading and clear any error, and prevent any
845
+ * pending computations from writing their results.
846
+ *
847
+ * If you want to set the value without affecting loading or error state, set `untrackedValue`
848
+ * instead and make sure to trigger effects manually if needed.
849
+ *
850
+ * If you want to abort pending computations when setting, you have to call `abort()` manually.
851
+ */
852
+ get value(): T;
853
+ set value(value: T);
884
854
  get untrackedValue(): T;
885
855
  set untrackedValue(value: T);
856
+ /**
857
+ * Loading is true if the signal is still waiting for the promise to resolve, false if the promise
858
+ * has resolved or rejected (or the compute function is synchronous).
859
+ *
860
+ * Accessing `.pending` will trigger computation if needed, since it's often used like
861
+ *
862
+ * ```ts
863
+ * signal.pending ? <Loading /> : signal.value
864
+ * ```
865
+ */
866
+ get pending(): boolean;
867
+ set untrackedPending(value: boolean);
868
+ get untrackedPending(): boolean;
869
+ /** @deprecated Use `pending` instead */
870
+ get loading(): boolean;
871
+ /** @deprecated Use `untrackedPending` instead */
872
+ get untrackedLoading(): boolean;
873
+ set untrackedLoading(value: boolean);
874
+ /**
875
+ * The error the compute function threw or rejected with.
876
+ *
877
+ * Accessing .error will trigger computation if needed, since it's often used like
878
+ *
879
+ * ```ts
880
+ * signal.error ? <Failed /> : signal.value
881
+ * ```
882
+ */
883
+ get error(): Error | undefined;
884
+ set untrackedError(value: Error | undefined);
885
+ get untrackedError(): Error | undefined;
886
+ get expires(): number;
887
+ set expires(value: number);
888
+ get poll(): boolean;
889
+ set poll(value: boolean);
890
+ /** @deprecated Use `expires` and `poll` instead. */
891
+ get interval(): number;
892
+ set interval(value: number);
893
+ $setInvalid$(allowRecalc: boolean, mustClear: boolean | number): void;
894
+ /** Abort the current computation and run cleanups if needed. */
895
+ abort(reason?: any): void;
896
+ /** Schedule eager cleanup on next macro task if no subscribers remain. */
897
+ $scheduleEagerCleanup$(): void;
898
+ /** Returns a promise resolves when the signal finished computing. */
899
+ promise(): Promise<void>;
900
+ /** Run the computation if needed */
886
901
  $computeIfNeeded$(): void;
902
+ /**
903
+ * Invoke the compute fn with the ComputeCtx argument. CTX_ARG signals (useAsync$, useResource$)
904
+ * only track via its explicit track(). Computeds auto-track every synchronous read instead; after
905
+ * the first await they must use the explicit track() too.
906
+ */
907
+ $invokeComputeFn$(fn: Function, job: Job<T>): T | Promise<T>;
908
+ /** Start an async computation (the async engine; assumes the INVALID flag is set) */
909
+ $computeAsync$(): void;
910
+ $runComputation$(running: Job<T>): Promise<void>;
911
+ /** Await the computation and publish its result, error, and loading transitions. */
912
+ $settleComputation$(running: Job<T>, compute: () => ValueOrPromise<T>): Promise<void>;
913
+ /**
914
+ * Sets the error from the given job. We only accept errors from the current job and we ignore
915
+ * AbortErrors.
916
+ */
917
+ $setError$(job: Job<T>, error: Error): void;
918
+ /** Called after SSR/unmount */
919
+ $destroy$(): Promise<void>;
920
+ private $clearNextPoll$;
921
+ private $scheduleNextPoll$;
922
+ private $hasSubscribers$;
923
+ $requestCleanups$(job: Job<T>, reason?: any): void;
924
+ /** Run a job's cleanup callbacks, returning a promise when any of them are async. */
925
+ $runCleanupCallbacks$(job: Job<T>): Promise<void> | undefined;
926
+ /** Clean up and trigger signal compute once complete */
927
+ $runCleanups$(job: Job<T>): Promise<void> | undefined;
887
928
  }
888
929
 
889
930
  declare type ComputeQRL<T> = _QRLInternal<ComputedFn<T>>;
@@ -900,7 +941,7 @@ export declare const _CONST_PROPS: unique symbol;
900
941
  * - `VNode` and `ISsrNode`: Either a component or `<Signal>`
901
942
  * - `Signal2`: A derived signal which contains a computation function.
902
943
  */
903
- declare type Consumer = Task | _VNode | SignalImpl | ISsrNode;
944
+ declare type Consumer = _Task | _VNode | SignalImpl | ISsrNode;
904
945
 
905
946
  /** @internal */
906
947
  export declare interface _Container {
@@ -918,13 +959,13 @@ export declare interface _Container {
918
959
  $resolveRenderPromise$: (() => void) | null;
919
960
  $pendingCount$: number;
920
961
  $checkPendingCount$(): void;
921
- handleError(err: any, $host$: HostElement | null): void;
922
- getParentHost(host: HostElement): HostElement | null;
923
- setContext<T>(host: HostElement, context: ContextId<T>, value: T): void;
924
- resolveContext<T>(host: HostElement, contextId: ContextId<T>): T | undefined;
925
- setHostProp<T>(host: HostElement, name: string, value: T): void;
926
- getHostProp<T>(host: HostElement, name: string): T | null;
927
- $appendStyle$(content: string, styleId: string, host: HostElement, scoped: boolean): void;
962
+ handleError(err: any, $host$: _HostElement | null): void;
963
+ getParentHost(host: _HostElement): _HostElement | null;
964
+ setContext<T>(host: _HostElement, context: ContextId<T>, value: T): void;
965
+ resolveContext<T>(host: _HostElement, contextId: ContextId<T>): T | undefined;
966
+ setHostProp<T>(host: _HostElement, name: string, value: T): void;
967
+ getHostProp<T>(host: _HostElement, name: string): T | null;
968
+ $appendStyle$(content: string, styleId: string, host: _HostElement, scoped: boolean): void;
928
969
  /**
929
970
  * When component is about to be executed, it may add/remove children. This can cause problems
930
971
  * with the projection because deleting content will prevent the projection references from
@@ -933,7 +974,7 @@ export declare interface _Container {
933
974
  *
934
975
  * @param renderHost - Host element to ensure projection is resolved.
935
976
  */
936
- ensureProjectionResolved(host: HostElement): void;
977
+ ensureProjectionResolved(host: _HostElement): void;
937
978
  serializationCtxFactory(NodeConstructor: {
938
979
  new (...rest: any[]): {
939
980
  __brand__: 'SsrNode';
@@ -945,6 +986,13 @@ export declare interface _Container {
945
986
  } | null, symbolToChunkResolver: SymbolToChunkResolver, writer?: StreamWriter): SerializationContext;
946
987
  }
947
988
 
989
+ declare const enum ContainerDataProcessState {
990
+ NotStarted = 0,
991
+ ProcessingVNode = 1,
992
+ ProcessingState = 2,
993
+ ProcessingStateDone = 3
994
+ }
995
+
948
996
  /** @internal */
949
997
  export declare interface _ContainerElement extends HTMLElement {
950
998
  qContainer?: ClientContainer;
@@ -962,6 +1010,7 @@ export declare interface _ContainerElement extends HTMLElement {
962
1010
  qVNodeRefs?: Map<number, Element | _ElementVNode>;
963
1011
  /** String from `<script type="qwik/vnode">` tag. */
964
1012
  qVnodeData?: string;
1013
+ qDestroy?: () => void;
965
1014
  /** Segment-local strings from `<script type="qwik/vnode" q:r="...">` tags. */
966
1015
  qSegmentVnodeData?: Map<string, string>;
967
1016
  }
@@ -1096,12 +1145,13 @@ export declare interface CorrectedToggleEvent extends Event {
1096
1145
  * Create a signal holding a `.value` which is calculated from the given async function (QRL). The
1097
1146
  * standalone version of `useAsync$`.
1098
1147
  *
1148
+ * @deprecated Use `createComputed$` instead, it has async support now.
1099
1149
  * @public
1100
1150
  */
1101
- export declare const createAsync$: <T>(qrl: (arg: AsyncCtx<T>) => Promise<T>, options?: AsyncSignalOptions<T>) => AsyncSignal<T>;
1151
+ export declare const createAsync$: <T>(qrl: (arg: ComputeCtx<T>) => Promise<T>, options?: AsyncSignalOptions<T>) => AsyncSignal<T>;
1102
1152
 
1103
1153
  /** @internal */
1104
- export declare const createAsyncQrl: <T>(qrl: QRL<AsyncFn<T>>, options?: AsyncSignalOptions<T>) => AsyncSignalImpl<T>;
1154
+ export declare const createAsyncQrl: <T>(qrl: QRL<AsyncFn<T>>, options?: AsyncSignalOptions<T>) => _AsyncSignalImpl<T>;
1105
1155
 
1106
1156
  /**
1107
1157
  * Create a computed signal which is calculated from the given QRL. A computed signal is a signal
@@ -1109,16 +1159,17 @@ export declare const createAsyncQrl: <T>(qrl: QRL<AsyncFn<T>>, options?: AsyncSi
1109
1159
  * recalculated.
1110
1160
  *
1111
1161
  * The QRL must be a function which returns the value of the signal. The function must not have side
1112
- * effects, and it must be synchronous.
1113
- *
1114
- * If you need the function to be async, use `createAsync$` instead (don't forget to use `track()`).
1162
+ * effects. Every synchronous signal or store read is tracked automatically; reads after the first
1163
+ * `await` must use the `track()` provided on the context argument. When the function is async, the
1164
+ * returned signal exposes the async API (`.pending`, `.error`, `.promise()`), and reading an
1165
+ * unresolved `.value` throws the computation promise.
1115
1166
  *
1116
1167
  * @public
1117
1168
  */
1118
- export declare const createComputed$: <T>(qrl: () => T, options?: ComputedOptions) => ComputedReturnType<T>;
1169
+ export declare const createComputed$: <T>(qrl: (ctx: ComputeCtx) => ValueOrPromise<T>, options?: ComputedOptions<T>) => ComputedReturnType<T>;
1119
1170
 
1120
1171
  /** @internal */
1121
- export declare const createComputedQrl: <T>(qrl: QRL<() => T>, options?: ComputedOptions) => ComputedSignalImpl<T>;
1172
+ export declare const createComputedQrl: <T>(qrl: QRL<ComputedFn<T>>, options?: ComputedOptions<T>) => ComputedSignalImpl<T>;
1122
1173
 
1123
1174
  /**
1124
1175
  * Create a context ID to be used in your application. The name should be written with no spaces.
@@ -1188,7 +1239,7 @@ export declare function _createDeserializeContainer(stateData: unknown[]): Deser
1188
1239
  *
1189
1240
  * @internal
1190
1241
  */
1191
- export declare const _createQRL: <TYPE>(chunk: string | null, symbol: string, symbolRef?: null | ValueOrPromise<TYPE>, symbolFn?: null | (() => Promise<Record<string, TYPE>>), captures?: Readonly<unknown[]> | string | null, container?: _Container) => _QRLInternal<TYPE>;
1242
+ export declare const _createQRL: <TYPE>(chunk: string | null, symbol: string, symbolRef?: null | ValueOrPromise<TYPE>, symbolFn?: null | (() => Promise<Record<string, TYPE>>), captures?: QrlCaptures, container?: _Container) => _QRLInternal<TYPE>;
1192
1243
 
1193
1244
  /**
1194
1245
  * Create a signal that holds a custom serializable value. See {@link useSerializer$} for more
@@ -1216,6 +1267,9 @@ export declare const createSignal: {
1216
1267
  <T>(value: T): Signal<T>;
1217
1268
  };
1218
1269
 
1270
+ /** @internal */
1271
+ export declare function _createStore<T extends object>(container: _Container | null | undefined, obj: T, flags: _StoreFlags): T;
1272
+
1219
1273
  /** @public */
1220
1274
  export declare interface CSSProperties extends CSS_2.Properties<string | number>, CSS_2.PropertiesHyphen<string | number> {
1221
1275
  /**
@@ -1228,31 +1282,29 @@ export declare interface CSSProperties extends CSS_2.Properties<string | number>
1228
1282
  [v: `--${string}`]: string | number | undefined;
1229
1283
  }
1230
1284
 
1285
+ /** @internal */
1286
+ export declare const _delay: (timeout: number) => Promise<unknown>;
1287
+
1231
1288
  declare class DeleteOperation {
1232
1289
  target: Element | Text;
1233
1290
  constructor(target: Element | Text);
1234
1291
  }
1235
1292
 
1236
- declare interface DescriptorBase<T = unknown, B = unknown> extends BackRef {
1237
- $flags$: number;
1238
- $index$: number;
1239
- $el$: HostElement;
1240
- $qrl$: _QRLInternal<T>;
1241
- $state$: B | undefined;
1242
- $destroy$: (() => void) | null;
1243
- }
1244
-
1245
1293
  /**
1246
- * Deserialize data from string to an array of objects.
1294
+ * Deserialize data from string.
1247
1295
  *
1248
1296
  * @param rawStateData - Data to deserialize
1249
1297
  * @internal
1250
1298
  */
1251
- export declare function _deserialize<T>(rawStateData: string): T;
1299
+ export declare function _deserialize<T>(rawStateData: string): Promise<T>;
1252
1300
 
1253
1301
  declare interface DeserializeContainer {
1254
1302
  $getObjectById$: (id: number | string) => unknown;
1255
1303
  $getForwardRef$: (id: number) => number | string | undefined;
1304
+ $pendingStoreTargets$?: Map<object, {
1305
+ t: number;
1306
+ v: unknown;
1307
+ }>;
1256
1308
  element: HTMLElement | null;
1257
1309
  getSyncFn: (id: number) => (...args: unknown[]) => unknown;
1258
1310
  $state$?: unknown[];
@@ -1289,15 +1341,17 @@ declare class DomContainer extends _SharedContainer implements ClientContainer {
1289
1341
  $instanceHash$: string;
1290
1342
  $forwardRefs$: Array<number | string> | null;
1291
1343
  vNodeLocate: (id: string | Element) => _VNode;
1344
+ $containerDataProcessState$: ContainerDataProcessState;
1345
+ $containerStateReadyCallbacks$: Array<() => void> | undefined;
1346
+ $containerStateDataState$: unknown;
1292
1347
  private $rawStateData$;
1293
1348
  private $stateData$;
1294
1349
  private $rootForwardRefs$;
1295
1350
  private $styleIds$;
1296
1351
  constructor(element: _ContainerElement);
1352
+ $processContainerData$(): Generator<void, void, void>;
1297
1353
  /** Tear down this container so stale references fail gracefully. */
1298
1354
  $destroy$(): void;
1299
- private $processRootStateScript$;
1300
- private $stateScriptSelector$;
1301
1355
  /**
1302
1356
  * The first time we render we need to hoist the styles. (Meaning we need to move all styles from
1303
1357
  * component inline to <head>)
@@ -1313,8 +1367,8 @@ declare class DomContainer extends _SharedContainer implements ClientContainer {
1313
1367
  setContext<T>(host: _VNode, context: ContextId<T>, value: T): void;
1314
1368
  resolveContext<T>(host: _VNode, contextId: ContextId<T>): T | undefined;
1315
1369
  getParentHost(host: _VNode): _VNode | null;
1316
- setHostProp<T>(host: HostElement, name: string, value: T): void;
1317
- getHostProp<T>(host: HostElement, name: string): T | null;
1370
+ setHostProp<T>(host: _HostElement, name: string, value: T): void;
1371
+ getHostProp<T>(host: _HostElement, name: string): T | null;
1318
1372
  ensureProjectionResolved(vNode: _VirtualVNode): void;
1319
1373
  $getObjectById$: (id: number | string) => unknown;
1320
1374
  $getForwardRef$(id: number): number | string | undefined;
@@ -1355,7 +1409,8 @@ export declare const _EFFECT_BACK_REF: unique symbol;
1355
1409
 
1356
1410
  declare type EffectBackRef = SignalImpl | StoreTarget | PropsProxy;
1357
1411
 
1358
- declare const enum EffectProperty {
1412
+ /** @internal */
1413
+ export declare const enum _EffectProperty {
1359
1414
  COMPONENT = ":",
1360
1415
  VNODE = "."
1361
1416
  }
@@ -1398,12 +1453,15 @@ declare const enum EffectProperty {
1398
1453
  */
1399
1454
  declare class EffectSubscription {
1400
1455
  consumer: Consumer;
1401
- property: EffectProperty | string;
1456
+ property: _EffectProperty | string;
1402
1457
  backRef: Set<EffectBackRef> | null;
1403
1458
  data: _SubscriptionData | null;
1404
- constructor(consumer: Consumer, property: EffectProperty | string, backRef?: Set<EffectBackRef> | null, data?: _SubscriptionData | null);
1459
+ constructor(consumer: Consumer, property: _EffectProperty | string, backRef?: Set<EffectBackRef> | null, data?: _SubscriptionData | null);
1405
1460
  }
1406
1461
 
1462
+ /** @internal */
1463
+ export declare const _ELEMENT_SEQ = "q:seq";
1464
+
1407
1465
  /** @internal */
1408
1466
  export declare class _ElementVNode extends _VirtualVNode {
1409
1467
  node: Element;
@@ -1509,7 +1567,7 @@ export declare const _getContextContainer: () => _Container | undefined;
1509
1567
  export declare const _getContextEvent: () => unknown;
1510
1568
 
1511
1569
  /** @internal */
1512
- export declare const _getContextHostElement: () => HostElement | undefined;
1570
+ export declare const _getContextHostElement: () => _HostElement | undefined;
1513
1571
 
1514
1572
  /** @public */
1515
1573
  declare function getDomContainer(element: Element): ClientContainer;
@@ -1543,6 +1601,9 @@ export declare const getPlatform: () => CorePlatform;
1543
1601
  /** @internal */
1544
1602
  export declare function _getQContainerElement(element: Element): Element | null;
1545
1603
 
1604
+ /** @internal */
1605
+ export declare function _getSubscriber(effect: Consumer, prop: _EffectProperty | string, data?: _SubscriptionData): EffectSubscription;
1606
+
1546
1607
  /** Used by the optimizer for spread props operations @internal */
1547
1608
  export declare const _getVarProps: (props: PropsProxy | Record<string, unknown> | null | undefined) => Props | null;
1548
1609
 
@@ -1574,9 +1635,10 @@ export declare const _hasStoreEffects: (value: StoreTarget, prop: keyof StoreTar
1574
1635
  export declare const _hmr: (this: string | undefined, event: CustomEvent<{
1575
1636
  files: string[];
1576
1637
  t: number;
1577
- }>, element: Element) => void;
1638
+ }>, element: Element) => void | Promise<void>;
1578
1639
 
1579
- declare type HostElement = _VNode | ISsrNode;
1640
+ /** @internal */
1641
+ export declare type _HostElement = _VNode | ISsrNode;
1580
1642
 
1581
1643
  /** @public */
1582
1644
  declare type HTMLAttributeAnchorTarget = '_self' | '_blank' | '_parent' | '_top' | (string & {});
@@ -1687,6 +1749,16 @@ export declare const _IMMUTABLE: unique symbol;
1687
1749
  */
1688
1750
  export declare const implicit$FirstArg: <FIRST, REST extends any[], RET>(fn: (qrl: QRL<FIRST>, ...rest: REST) => RET) => ((qrl: FIRST, ...rest: REST) => RET);
1689
1751
 
1752
+ /**
1753
+ * Inject a pre-loaded value into a signal while preserving subscriptions. Calls `invalidate({__v})`
1754
+ * so the compute function reads the value from `info`, then triggers an immediate synchronous
1755
+ * compute via the private `$computeIfNeeded$()` method (which is mangled in core builds, so callers
1756
+ * from other packages must go through this helper).
1757
+ *
1758
+ * @internal
1759
+ */
1760
+ export declare const _injectAsyncSignalValue: (signal: ComputedSignal<unknown>, value: unknown) => void;
1761
+
1690
1762
  /**
1691
1763
  * Create an inlined QRL. This is mostly useful on the server side for serialization.
1692
1764
  *
@@ -1741,10 +1813,17 @@ declare type IntrinsicSVGElements = {
1741
1813
  [K in keyof Omit<SVGElementTagNameMap, keyof HTMLElementTagNameMap>]: LenientSVGProps<SVGElementTagNameMap[K]>;
1742
1814
  };
1743
1815
 
1816
+ /**
1817
+ * Call a function with the given InvokeContext and given arguments.
1818
+ *
1819
+ * @internal
1820
+ */
1821
+ export declare function _invoke<FN extends (...args: any[]) => any>(this: unknown, context: InvokeContext | undefined, fn: FN, ...args: Parameters<FN>): ReturnType<FN>;
1822
+
1744
1823
  /** The shared state during an invoke() call */
1745
1824
  declare interface InvokeContext {
1746
1825
  /** The Virtual parent component for the current component code */
1747
- $hostElement$: HostElement | undefined;
1826
+ $hostElement$: _HostElement | undefined;
1748
1827
  /** The event we're currently handling */
1749
1828
  $event$: PossibleEvents | undefined;
1750
1829
  $effectSubscriber$: EffectSubscription | undefined;
@@ -1795,7 +1874,7 @@ declare interface ISsrNode {
1795
1874
  children: ISsrNode[] | null;
1796
1875
  vnodeData: VNodeData;
1797
1876
  currentFile: string | null;
1798
- readonly [_EFFECT_BACK_REF]: Map<EffectProperty | string, EffectSubscription> | null;
1877
+ readonly [_EFFECT_BACK_REF]: Map<_EffectProperty | string, EffectSubscription> | null;
1799
1878
  setProp(name: string, value: any): void;
1800
1879
  getProp(name: string): any;
1801
1880
  removeProp(name: string): void;
@@ -1810,7 +1889,7 @@ export declare const _isStore: (value: object) => boolean;
1810
1889
  export declare function _isStringifiable(value: unknown): value is _Stringifiable;
1811
1890
 
1812
1891
  /** @internal */
1813
- export declare const _isTask: (value: any) => value is Task;
1892
+ export declare const _isTask: (value: any) => value is _Task;
1814
1893
 
1815
1894
  /** @internal */
1816
1895
  declare interface IStreamHandler {
@@ -1820,6 +1899,27 @@ declare interface IStreamHandler {
1820
1899
  streamBlockEnd(): ValueOrPromise<void>;
1821
1900
  }
1822
1901
 
1902
+ /** Retains job metadata and also serves as the argument for CTX_ARG compute functions */
1903
+ declare class Job<T> implements ComputeCtx<T> {
1904
+ readonly $signal$: ComputedSignalImpl<T, any>;
1905
+ /** First holds the compute promise and then the cleanup promise */
1906
+ $promise$: Promise<void> | null | void;
1907
+ $cleanupRequested$: boolean;
1908
+ $canWrite$: boolean;
1909
+ $track$: Tracker | undefined;
1910
+ $cleanups$: Parameters<ComputeCtx<T>['cleanup']>[0][] | undefined;
1911
+ $abortController$: AbortController | undefined;
1912
+ info: unknown;
1913
+ $infoVersion$: number | undefined;
1914
+ constructor($signal$: ComputedSignalImpl<T, any>, info: unknown, $infoVersion$: number | undefined);
1915
+ get track(): Tracker;
1916
+ get abortSignal(): AbortSignal;
1917
+ /** Backward compatible cache method for resource */
1918
+ cache(): void;
1919
+ get previous(): T | undefined;
1920
+ cleanup(callback: () => void): void;
1921
+ }
1922
+
1823
1923
  /**
1824
1924
  * Used by the JSX transpilers to create a JSXNode. Note that the optimizer will normally not use
1825
1925
  * this, instead using _jsxSplit and _jsxSorted directly.
@@ -2087,6 +2187,16 @@ export declare const _mapArray_get: <T>(array: (T | null)[], key: string, start:
2087
2187
  /** @internal */
2088
2188
  export declare const _mapArray_set: <T>(array: (T | null)[], key: string, value: T | null, start: number, allowNullValue?: boolean) => void;
2089
2189
 
2190
+ /**
2191
+ * Mark this signal as owned outside of the component that read it.
2192
+ *
2193
+ * Externally owned signals are preserved when found in a component's sequential scope during
2194
+ * component cleanup.
2195
+ *
2196
+ * @internal
2197
+ */
2198
+ export declare const _markSignalAsExternallyOwned: (signal: ComputedSignal<unknown>) => void;
2199
+
2090
2200
  declare class MaybeAsyncSignal {
2091
2201
  }
2092
2202
 
@@ -2130,6 +2240,9 @@ export declare type NativeUIEvent = UIEvent;
2130
2240
  /** @public @deprecated Use `WheelEvent` and use the second argument to the handler function for the current event target */
2131
2241
  export declare type NativeWheelEvent = WheelEvent;
2132
2242
 
2243
+ /** @internal */
2244
+ export declare function _newInvokeContext(locale?: string, hostElement?: _HostElement, event?: Exclude<PossibleEvents, typeof RenderEvent>): InvokeContext;
2245
+
2133
2246
  declare interface NodePropData {
2134
2247
  $scopedStyleIdPrefix$: string | null;
2135
2248
  $isConst$: boolean;
@@ -2399,6 +2512,14 @@ export declare type PublicProps<PROPS> = (PROPS extends Record<any, any> ? Omit<
2399
2512
  /** @internal */
2400
2513
  export declare interface _QDocument extends Document {
2401
2514
  qVNodeData: WeakMap<Element, string>;
2515
+ /** True once root document VNode data has been scheduled at least once. */
2516
+ qVNodeDataStarted?: boolean;
2517
+ /** True when root, segment, and patch VNode data work is fully drained. */
2518
+ qVNodeDataReady?: boolean;
2519
+ /** Internal yielding state for queued VNode data jobs. */
2520
+ qVNodeDataState?: unknown;
2521
+ /** Callbacks waiting for root, segment, and patch VNode data work to drain. */
2522
+ qVNodeDataCallbacks?: Array<() => void>;
2402
2523
  /** True once the root document VNode data has been fully processed. */
2403
2524
  qVNodeDataProcessed?: boolean;
2404
2525
  /** Processes one vnode patch script. */
@@ -2558,6 +2679,8 @@ export declare const qrl: <T = any>(chunkOrFn: string | (() => Promise<any>), sy
2558
2679
 
2559
2680
  declare type QrlArgs<T> = T extends (...args: infer ARGS) => any ? ARGS : unknown[];
2560
2681
 
2682
+ declare type QrlCaptures = Readonly<unknown[]> | string | null;
2683
+
2561
2684
  /** @public */
2562
2685
  declare interface QRLDev {
2563
2686
  file: string;
@@ -2582,8 +2705,8 @@ declare type QRLInternalMethods<TYPE> = {
2582
2705
  readonly $chunk$: string | null;
2583
2706
  readonly $symbol$: string;
2584
2707
  readonly $hash$: string;
2585
- /** If it's a string it's serialized */
2586
- readonly $captures$?: Readonly<unknown[]> | string | null;
2708
+ /** Captures are stored lazily after deserialization. */
2709
+ readonly $captures$?: QrlCaptures;
2587
2710
  dev?: QRLDev | null;
2588
2711
  resolve(container?: _Container): Promise<TYPE>;
2589
2712
  resolved: undefined | TYPE;
@@ -2600,7 +2723,7 @@ declare type QRLInternalMethods<TYPE> = {
2600
2723
  * method but we need to have a stable name because it gets called in user code by the optimizer,
2601
2724
  * after the $name$ props are mangled
2602
2725
  */
2603
- w(captures: Readonly<unknown[]> | string | null): _QRLInternal<TYPE>;
2726
+ w(captures: QrlCaptures): _QRLInternal<TYPE>;
2604
2727
  /**
2605
2728
  * "set ref" - Set the ref of the QRL. It's an internal method but we need to have a stable name
2606
2729
  * because it gets called in user code by the optimizer, after the $name$ props are mangled
@@ -2929,7 +3052,7 @@ export declare const _reR: () => boolean;
2929
3052
  *
2930
3053
  * @internal
2931
3054
  */
2932
- export declare function _res(this: string | undefined, _: any, element: Element): void;
3055
+ export declare function _res(this: string | undefined, _: any, element: Element): void | Promise<void>;
2933
3056
 
2934
3057
  /** @internal */
2935
3058
  export declare const _resolveContextWithoutSequentialScope: <STATE>(context: ContextId<STATE>) => STATE | undefined;
@@ -2971,7 +3094,7 @@ export declare const _resolveContextWithoutSequentialScope: <STATE>(context: Con
2971
3094
  export declare const Resource: <T>({ value, onResolved, onPending, onRejected, }: ResourceProps<T>) => JSXOutput;
2972
3095
 
2973
3096
  /** @public */
2974
- export declare interface ResourceCtx<T = unknown> extends AsyncCtx<T> {
3097
+ export declare interface ResourceCtx<T = unknown> extends ComputeCtx<T> {
2975
3098
  /** @deprecated Does not do anything */
2976
3099
  cache(policyOrMilliseconds: number | 'immutable'): void;
2977
3100
  }
@@ -3031,6 +3154,14 @@ export declare const _restProps: (props: PropsProxy, omit?: string[], target?: P
3031
3154
  /** @internal */
3032
3155
  export declare const _reT: ({ cleanup }: TaskCtx) => void;
3033
3156
 
3157
+ /**
3158
+ * Retries a function that throws a promise. If you pass `onError`, you're responsible for handling
3159
+ * errors.
3160
+ *
3161
+ * @internal
3162
+ */
3163
+ export declare function _retryOnPromise<T>(fn: () => ValueOrPromise<T>, onError?: (e: any) => ValueOrPromise<T>): ValueOrPromise<T>;
3164
+
3034
3165
  /** @public @experimental */
3035
3166
  export declare const Reveal: typeof _reC;
3036
3167
 
@@ -3312,7 +3443,7 @@ export declare abstract class _SharedContainer implements _Container {
3312
3443
  $resolveRenderPromise$: (() => void) | null;
3313
3444
  $pendingCount$: number;
3314
3445
  constructor(serverData: Record<string, any>, locale: string);
3315
- trackSignalValue<T>(signal: Signal, subscriber: HostElement, property: string, data: _SubscriptionData): T;
3446
+ trackSignalValue<T>(signal: Signal, subscriber: _HostElement, property: string, data: _SubscriptionData): T;
3316
3447
  serializationCtxFactory(NodeConstructor: {
3317
3448
  new (...rest: any[]): {
3318
3449
  __brand__: 'SsrNode';
@@ -3323,16 +3454,35 @@ export declare abstract class _SharedContainer implements _Container {
3323
3454
  };
3324
3455
  } | null, symbolToChunkResolver: SymbolToChunkResolver, writer?: StreamWriter): SerializationContext;
3325
3456
  $checkPendingCount$(): void;
3326
- abstract ensureProjectionResolved(host: HostElement): void;
3327
- abstract handleError(err: any, $host$: HostElement | null): void;
3328
- abstract getParentHost(host: HostElement): HostElement | null;
3329
- abstract setContext<T>(host: HostElement, context: ContextId<T>, value: T): void;
3330
- abstract resolveContext<T>(host: HostElement, contextId: ContextId<T>): T | undefined;
3331
- abstract setHostProp<T>(host: HostElement, name: string, value: T): void;
3332
- abstract getHostProp<T>(host: HostElement, name: string): T | null;
3333
- abstract $appendStyle$(content: string, styleId: string, host: HostElement, scoped: boolean): void;
3457
+ abstract ensureProjectionResolved(host: _HostElement): void;
3458
+ abstract handleError(err: any, $host$: _HostElement | null): void;
3459
+ abstract getParentHost(host: _HostElement): _HostElement | null;
3460
+ abstract setContext<T>(host: _HostElement, context: ContextId<T>, value: T): void;
3461
+ abstract resolveContext<T>(host: _HostElement, contextId: ContextId<T>): T | undefined;
3462
+ abstract setHostProp<T>(host: _HostElement, name: string, value: T): void;
3463
+ abstract getHostProp<T>(host: _HostElement, name: string): T | null;
3464
+ abstract $appendStyle$(content: string, styleId: string, host: _HostElement, scoped: boolean): void;
3465
+ }
3466
+
3467
+ /** @internal */
3468
+ export declare const _shC: (props: ShowProps<any>) => JSXNode<unknown>;
3469
+
3470
+ /** @public @experimental */
3471
+ export declare const Show: ShowComponent;
3472
+
3473
+ /** @public @experimental */
3474
+ export declare type ShowComponent = <WHEN = unknown, THEN extends JSXOutput = JSXOutput, ELSE extends JSXOutput = JSXOutput>(props: PublicProps<ShowProps<WHEN, THEN, ELSE>>, key: string | null, flags: number, dev?: DevJSX) => JSXOutput;
3475
+
3476
+ /** @public @experimental */
3477
+ export declare interface ShowProps<WHEN = unknown, THEN extends JSXOutput = JSXOutput, ELSE extends JSXOutput = JSXOutput> {
3478
+ when$: QRL<() => WHEN>;
3479
+ then$: QRL<(when: WHEN) => THEN>;
3480
+ else$?: QRL<(when: WHEN) => ELSE>;
3334
3481
  }
3335
3482
 
3483
+ /** @internal */
3484
+ export declare const _shT: ({ track }: TaskCtx) => ValueOrPromise<void | undefined>;
3485
+
3336
3486
  /**
3337
3487
  * A signal is a reactive value which can be read and written. When the signal is written, all tasks
3338
3488
  * which are tracking the signal will be re-run and all components that read the signal will be
@@ -3357,11 +3507,6 @@ export declare interface Signal<T = any> {
3357
3507
  trigger(): void;
3358
3508
  }
3359
3509
 
3360
- declare const enum SignalFlags {
3361
- INVALID = 1,
3362
- RUN_EFFECTS = 2
3363
- }
3364
-
3365
3510
  declare class SignalImpl<T = any> implements Signal<T> {
3366
3511
  $untrackedValue$: T;
3367
3512
  /** Store a list of effects which are dependent on this signal. */
@@ -3720,11 +3865,13 @@ export declare type SSRHintProps = {
3720
3865
  declare interface SSRInternalStreamWriter extends StreamWriter {
3721
3866
  writeRootRef(id: number): ValueOrPromise<void>;
3722
3867
  writeRootRefPath(path: number[]): ValueOrPromise<void>;
3868
+ writeRootRefDelta(id: number, base: number): ValueOrPromise<void>;
3723
3869
  toString(remap?: number[]): string;
3724
3870
  }
3725
3871
 
3726
3872
  declare const enum SsrNodeFlags {
3727
- Updatable = 1
3873
+ Updatable = 1,
3874
+ WarnedStreamedChore = 2
3728
3875
  }
3729
3876
 
3730
3877
  declare type SSROutOfOrderSegment = SegmentRenderContext;
@@ -3743,6 +3890,12 @@ declare type SSRRevealSlotProps = {
3743
3890
  coordinator: OutOfOrderRevealCoordinator;
3744
3891
  };
3745
3892
 
3893
+ /** @internal */
3894
+ declare interface SSRRootRefDeltaChunk {
3895
+ readonly id: number;
3896
+ readonly base: number;
3897
+ }
3898
+
3746
3899
  /** @internal */
3747
3900
  declare interface SSRRootRefPathChunk {
3748
3901
  readonly path: number[];
@@ -3764,6 +3917,10 @@ declare type SSRSegmentWriteChunk = string | {
3764
3917
  } | {
3765
3918
  readonly type: 'root-ref-path';
3766
3919
  readonly localPath: number[];
3920
+ } | {
3921
+ readonly type: 'root-ref-delta';
3922
+ readonly localId: number;
3923
+ readonly localBaseId: number;
3767
3924
  };
3768
3925
 
3769
3926
  /** @public */
@@ -3788,7 +3945,7 @@ export declare interface SSRStreamWriter {
3788
3945
  }
3789
3946
 
3790
3947
  /** @internal */
3791
- declare type SSRWriteChunk = string | number | SSRRootRefPathChunk;
3948
+ declare type SSRWriteChunk = string | number | SSRRootRefPathChunk | SSRRootRefDeltaChunk;
3792
3949
 
3793
3950
  declare type StackFn = () => ValueOrPromise<void>;
3794
3951
 
@@ -3798,6 +3955,13 @@ declare type StopPropagation = {
3798
3955
  [K in keyof HTMLElementEventMap as `stoppropagation:${K}`]?: boolean;
3799
3956
  };
3800
3957
 
3958
+ /** @internal */
3959
+ export declare const enum _StoreFlags {
3960
+ NONE = 0,
3961
+ RECURSIVE = 1,
3962
+ IMMUTABLE = 2
3963
+ }
3964
+
3801
3965
  declare type StoreTarget = Record<string | symbol, any>;
3802
3966
 
3803
3967
  /** @internal */
@@ -4146,16 +4310,16 @@ declare type TableCellSpecialAttrs = {
4146
4310
  valign?: 'top' | 'middle' | 'bottom' | 'baseline' | undefined;
4147
4311
  };
4148
4312
 
4149
- declare class Task<T = unknown, B = T> extends BackRef implements DescriptorBase<unknown, Signal<B>> {
4150
- $flags$: number;
4313
+ /** @internal */
4314
+ export declare class _Task<T = unknown, B = T> extends BackRef {
4315
+ $flags$: TaskFlags;
4151
4316
  $index$: number;
4152
- $el$: HostElement;
4317
+ $el$: _HostElement;
4153
4318
  $qrl$: _QRLInternal<T>;
4154
- $state$: Signal<B> | undefined;
4155
4319
  $destroy$: (() => void) | null;
4156
4320
  $destroyPromise$: Promise<void> | undefined;
4157
4321
  $taskPromise$: Promise<void> | null;
4158
- constructor($flags$: number, $index$: number, $el$: HostElement, $qrl$: _QRLInternal<T>, $state$: Signal<B> | undefined, $destroy$: (() => void) | null);
4322
+ constructor($flags$: TaskFlags, $index$: number, $el$: _HostElement, $qrl$: _QRLInternal<T>, $destroy$: (() => void) | null);
4159
4323
  }
4160
4324
 
4161
4325
  /**
@@ -4164,7 +4328,7 @@ declare class Task<T = unknown, B = T> extends BackRef implements DescriptorBase
4164
4328
  *
4165
4329
  * @internal
4166
4330
  */
4167
- export declare function _task(this: string, _event: Event, element: Element): void;
4331
+ export declare function _task(this: string, _event: Event, element: Element): void | Promise<void>;
4168
4332
 
4169
4333
  /** @public */
4170
4334
  export declare interface TaskCtx {
@@ -4174,6 +4338,16 @@ export declare interface TaskCtx {
4174
4338
 
4175
4339
  declare const TaskEvent = "qTask";
4176
4340
 
4341
+ /** @internal */
4342
+ declare const enum TaskFlags {
4343
+ VISIBLE_TASK = 1,
4344
+ TASK = 2,
4345
+ DIRTY = 4,
4346
+ RENDER_BLOCKING = 8,
4347
+ NEEDS_CLEANUP = 16,
4348
+ EVENTS_REGISTERED = 32
4349
+ }
4350
+
4177
4351
  /** @public */
4178
4352
  export declare type TaskFn = (ctx: TaskCtx) => ValueOrPromise<void | (() => ValueOrPromise<void>)>;
4179
4353
 
@@ -4330,11 +4504,16 @@ export declare function _updateProjectionProps(container: _Container, vnode: _Vi
4330
4504
  * will subscribe to it and return the last resolved value until the new value is ready. As soon as
4331
4505
  * the new value is ready, the subscribers will be updated.
4332
4506
  *
4507
+ * @deprecated Use `useComputed$` instead, it has async support now. It auto-tracks synchronous
4508
+ * reads; after the first `await`, use the provided `track()` like before.
4333
4509
  * @public
4334
4510
  */
4335
4511
  export declare const useAsync$: <T>(qrl: AsyncFn<T>, options?: AsyncSignalOptions<T> | undefined) => AsyncSignal<T>;
4336
4512
 
4337
- /** @internal */
4513
+ /**
4514
+ * @deprecated Use `useComputed$` instead, it has async support now.
4515
+ * @internal
4516
+ */
4338
4517
  export declare const useAsyncQrl: <T>(qrl: QRL<AsyncFn<T>>, options?: AsyncSignalOptions<T>) => AsyncSignal<T>;
4339
4518
 
4340
4519
  /**
@@ -4343,14 +4522,20 @@ export declare const useAsyncQrl: <T>(qrl: QRL<AsyncFn<T>>, options?: AsyncSigna
4343
4522
  * recalculated, and if the result changed, all tasks which are tracking the signal will be re-run
4344
4523
  * and all components that read the signal will be re-rendered.
4345
4524
  *
4346
- * The function must be synchronous and must not have any side effects.
4525
+ * Every synchronous signal or store read is tracked automatically. Reads after an `await` are not:
4526
+ * the tracking context is lost, so track them explicitly with the `track()` provided on the context
4527
+ * argument. When the function is async, the returned signal exposes the async API: reading an
4528
+ * unresolved `.value` throws the computation promise, and `.pending` and `.error` expose the
4529
+ * computation state.
4530
+ *
4531
+ * The function must not have any side effects.
4347
4532
  *
4348
4533
  * @public
4349
4534
  */
4350
- export declare const useComputed$: <T>(qrl: ComputedFn<T>, options?: ComputedOptions | undefined) => ComputedReturnType<T>;
4535
+ export declare const useComputed$: <T>(qrl: ComputedFn<T>, options?: ComputedOptions<T> | undefined) => ComputedReturnType<T>;
4351
4536
 
4352
4537
  /** @internal */
4353
- export declare const useComputedQrl: <T>(qrl: QRL<ComputedFn<T>>, options?: ComputedOptions) => ComputedReturnType<T>;
4538
+ export declare const useComputedQrl: <T>(qrl: QRL<ComputedFn<T>>, options?: ComputedOptions<T>) => ComputedReturnType<T>;
4354
4539
 
4355
4540
  /**
4356
4541
  * Stores a value which is retained for the lifetime of the component. Subsequent calls to
@@ -4610,11 +4795,11 @@ export declare const useOnWindow: <T extends KnownEventNames>(event: T | T[], ev
4610
4795
  * Be careful when using a `try/catch` statement in `useResource$`. If you catch the error and don't
4611
4796
  * re-throw it (or a new Error), the resource status will never be `rejected`.
4612
4797
  *
4613
- * @deprecated Use `useAsync$` instead, which is more powerful and flexible. `useResource$` is still
4614
- * available for backward compatibility but it is recommended to migrate to `useAsync$` for new
4615
- * code and when updating existing code.
4798
+ * @deprecated Use `useComputed$` instead, which is more powerful and flexible. `useResource$` is
4799
+ * still available for backward compatibility but it is recommended to migrate to `useComputed$`
4800
+ * for new code and when updating existing code.
4616
4801
  * @public
4617
- * @see useAsync$
4802
+ * @see useComputed$
4618
4803
  * @see Resource
4619
4804
  * @see ResourceReturn
4620
4805
  */
@@ -4973,7 +5158,7 @@ export declare const useVisibleTaskQrl: (qrl: QRL<TaskFn>, opts?: OnVisibleTaskO
4973
5158
  *
4974
5159
  * @internal
4975
5160
  */
4976
- export declare function _val(this: string | undefined, _: any, element: HTMLInputElement): void;
5161
+ export declare function _val(this: string | undefined, _: any, element: HTMLInputElement): void | Promise<void>;
4977
5162
 
4978
5163
  /**
4979
5164
  * Type representing a value which is either resolve or a promise.
@@ -4989,7 +5174,7 @@ export declare const _VAR_PROPS: unique symbol;
4989
5174
  export declare const _verifySerializable: <T>(value: T, preMessage?: string) => T;
4990
5175
 
4991
5176
  /**
4992
- * 2.0.0-beta.36-dev+3268fab
5177
+ * 2.0.0-beta.38-dev+0339f17
4993
5178
  *
4994
5179
  * @public
4995
5180
  */
@@ -5171,18 +5356,14 @@ export declare function withLocale<T>(locale: string, fn: () => T): T;
5171
5356
 
5172
5357
  declare type WrappedProp<T extends object, P extends keyof T> = T extends Signal ? WrappedSignalImpl<PropType<T, P>> : PropType<T, P>;
5173
5358
 
5174
- declare const enum WrappedSignalFlags {
5175
- UNWRAP = 4
5176
- }
5177
-
5178
5359
  declare class WrappedSignalImpl<T> extends SignalImpl<T> {
5179
5360
  $args$: any[];
5180
5361
  $func$: (...args: any[]) => T;
5181
5362
  $funcStr$: string | null;
5182
5363
  $flags$: AllSignalFlags;
5183
- $hostElement$: HostElement | undefined;
5184
- [_EFFECT_BACK_REF]: Map<EffectProperty | string, EffectSubscription> | undefined;
5185
- constructor(container: _Container | null, fn: (...args: any[]) => T, args: any[], fnStr: string | null, flags?: SignalFlags);
5364
+ $hostElement$: _HostElement | undefined;
5365
+ [_EFFECT_BACK_REF]: Map<_EffectProperty | string, EffectSubscription> | undefined;
5366
+ constructor(container: _Container | null, fn: (...args: any[]) => T, args: any[], fnStr: string | null, flags?: AllSignalFlags);
5186
5367
  invalidate(): void;
5187
5368
  get untrackedValue(): T;
5188
5369
  $computeIfNeeded$(): void;