@qwik.dev/core 2.0.0-beta.30 → 2.0.0-beta.32

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.
@@ -380,6 +380,8 @@ declare type AsyncCtx<T = unknown> = {
380
380
  readonly abortSignal: AbortSignal;
381
381
  /** The result of the previous computation, if any */
382
382
  readonly previous: T | undefined;
383
+ /** Extra info passed to `invalidate(info)` for this computation, if any. */
384
+ readonly info?: unknown;
383
385
  };
384
386
 
385
387
  /**
@@ -395,13 +397,15 @@ export declare type AsyncFn<T> = (ctx: AsyncCtx) => ValueOrPromise<T>;
395
397
  declare class AsyncJob<T> implements AsyncCtx<T> {
396
398
  readonly $signal$: AsyncSignalImpl<T>;
397
399
  /** First holds the compute promise and then the cleanup promise */
398
- $promise$: Promise<void> | null;
400
+ $promise$: Promise<void> | null | void;
399
401
  $cleanupRequested$: boolean;
400
402
  $canWrite$: boolean;
401
403
  $track$: AsyncCtx<T>['track'] | undefined;
402
404
  $cleanups$: Parameters<AsyncCtx<T>['cleanup']>[0][] | undefined;
403
405
  $abortController$: AbortController | undefined;
404
- constructor($signal$: AsyncSignalImpl<T>);
406
+ info: unknown;
407
+ $infoVersion$: number | undefined;
408
+ constructor($signal$: AsyncSignalImpl<T>, info: unknown, $infoVersion$: number | undefined);
405
409
  get track(): AsyncCtx<T>['track'];
406
410
  get abortSignal(): AbortSignal;
407
411
  /** Backward compatible cache method for resource */
@@ -447,25 +451,57 @@ export declare interface AsyncSignal<T = unknown> extends ComputedSignal<T> {
447
451
  * ```
448
452
  */
449
453
  loading: boolean;
454
+ /**
455
+ * Lets you read the loading state without subscribing to `.loading` updates. It also triggers
456
+ * lazy loading of the signal.
457
+ *
458
+ * Setting it will trigger listeners for `.loading`.
459
+ */
460
+ untrackedLoading: boolean;
450
461
  /**
451
462
  * The error that occurred while computing the signal, if any. This will be cleared when the
452
- * signal is successfully computed.
463
+ * signal is successfully computed. It does not trigger lazy loading of the signal.
453
464
  */
454
465
  error: Error | undefined;
455
466
  /**
456
- * Poll interval in ms. Writable and immediately effective when the signal has consumers. If set
457
- * to `0`, polling stops.
467
+ * Lets you read the error state without subscribing to `.error` updates. It does not trigger lazy
468
+ * loading of the signal.
469
+ *
470
+ * Setting it will trigger listeners for `.error`.
471
+ */
472
+ untrackedError: Error | undefined;
473
+ /**
474
+ * Expiration time in ms. Writable and immediately effective.
475
+ *
476
+ * When set, the signal is invalidated after this many ms. Whether it auto-recomputes depends on
477
+ * the `poll` property. `0` means no expiration.
478
+ */
479
+ expires: number;
480
+ /**
481
+ * Whether to automatically re-run the function when the value expires. Writable and immediately
482
+ * effective. Only relevant when `expires` is set.
483
+ *
484
+ * Defaults to `true`.
458
485
  */
486
+ poll: boolean;
487
+ /** @deprecated Use `expires` and `poll` instead. Will be removed before v2 */
459
488
  interval: number;
460
489
  /** A promise that resolves when the value is computed or rejected. */
461
490
  promise(): Promise<void>;
462
491
  /** Abort the current computation and run cleanups if needed. */
463
492
  abort(reason?: any): void;
493
+ /**
494
+ * Use this to force recalculation. If you pass `info`, it will be provided to the calculation
495
+ * function.
496
+ */
497
+ invalidate(info?: unknown): void;
464
498
  }
465
499
 
466
500
  declare const enum AsyncSignalFlags {
467
501
  EAGER_CLEANUP = 32,
468
- CLIENT_ONLY = 64
502
+ CLIENT_ONLY = 64,
503
+ CLEAR_ON_INVALIDATE = 128,
504
+ NO_POLL = 256
469
505
  }
470
506
 
471
507
  /**
@@ -474,23 +510,40 @@ declare const enum AsyncSignalFlags {
474
510
  * AsyncSignalImpl
475
511
  *
476
512
  * # ================================
513
+ *
514
+ * @internal
477
515
  */
478
516
  declare class AsyncSignalImpl<T> extends ComputedSignalImpl<T, AsyncQRL<T>> implements BackRef, AsyncSignal<T> {
479
517
  $untrackedLoading$: boolean;
480
518
  $untrackedError$: Error | undefined;
481
- $loadingEffects$: undefined | Set<EffectSubscription>;
482
- $errorEffects$: undefined | Set<EffectSubscription>;
483
519
  $current$: AsyncJob<T> | null;
484
- $jobs$: AsyncJob<T>[];
485
- $concurrency$: number;
486
- $interval$: number;
520
+ $jobs$: AsyncJob<T>[] | undefined;
521
+ $concurrency$: number | undefined;
522
+ $expires$: number | undefined;
487
523
  $timeoutMs$: number | undefined;
524
+ $loadingEffects$: undefined | Set<EffectSubscription>;
525
+ $errorEffects$: undefined | Set<EffectSubscription>;
488
526
  $pollTimeoutId$: ReturnType<typeof setTimeout> | undefined;
489
527
  $computationTimeoutId$: ReturnType<typeof setTimeout> | undefined;
528
+ $info$: unknown | undefined;
529
+ $infoVersion$: number | undefined;
490
530
  [_EFFECT_BACK_REF]: Map<EffectProperty | string, EffectSubscription> | undefined;
491
531
  constructor(container: _Container | null, fn: AsyncQRL<T>, flags?: SignalFlags | SerializationSignalFlags, options?: AsyncSignalOptions<T>);
492
532
  get untrackedValue(): T;
493
533
  set untrackedValue(value: T);
534
+ /**
535
+ * Read the value, subscribing if in a tracking context. Triggers computation if needed.
536
+ *
537
+ * Setting the value will mark the signal as not loading and clear any error, and prevent any
538
+ * pending computations from writing their results.
539
+ *
540
+ * If you want to set the value without affecting loading or error state, set `untrackedValue`
541
+ * instead and make sure to trigger effects manually if needed.
542
+ *
543
+ * If you want to abort pending computations when setting, you have to call `abort()` manually.
544
+ */
545
+ get value(): T;
546
+ set value(value: T);
494
547
  /**
495
548
  * Loading is true if the signal is still waiting for the promise to resolve, false if the promise
496
549
  * has resolved or rejected.
@@ -505,10 +558,16 @@ declare class AsyncSignalImpl<T> extends ComputedSignalImpl<T, AsyncQRL<T>> impl
505
558
  get error(): Error | undefined;
506
559
  set untrackedError(value: Error | undefined);
507
560
  get untrackedError(): Error | undefined;
561
+ get expires(): number;
562
+ set expires(value: number);
563
+ get poll(): boolean;
564
+ set poll(value: boolean);
565
+ /** @deprecated Use `expires` and `poll` instead. */
508
566
  get interval(): number;
509
567
  set interval(value: number);
510
568
  /** Invalidates the signal, causing it to re-compute its value. */
511
- invalidate(): Promise<void>;
569
+ invalidate(info?: unknown): Promise<void>;
570
+ $setInvalid$(allowRecalc: boolean, mustClear: boolean | number): void;
512
571
  /** Abort the current computation and run cleanups if needed. */
513
572
  abort(reason?: any): void;
514
573
  /** Schedule eager cleanup on next macro task if no subscribers remain. */
@@ -518,14 +577,19 @@ declare class AsyncSignalImpl<T> extends ComputedSignalImpl<T, AsyncQRL<T>> impl
518
577
  /** Run the computation if needed */
519
578
  $computeIfNeeded$(): void;
520
579
  $runComputation$(running: AsyncJob<T>): Promise<void>;
580
+ /**
581
+ * Sets the error from the given job. We only accept errors from the current job and we ignore
582
+ * AbortErrors.
583
+ */
584
+ $setError$(job: AsyncJob<T>, error: Error): void;
521
585
  /** Called after SSR/unmount */
522
586
  $destroy$(): Promise<void>;
523
587
  private $clearNextPoll$;
524
588
  private $scheduleNextPoll$;
525
589
  private $hasSubscribers$;
526
- $requestCleanups$(job: AsyncJob<T>, reason?: any): Promise<void | null>;
590
+ $requestCleanups$(job: AsyncJob<T>, reason?: any): void;
527
591
  /** Clean up and trigger signal compute once complete */
528
- $runCleanups$(job: AsyncJob<T>): Promise<void>;
592
+ $runCleanups$(job: AsyncJob<T>): Promise<void> | undefined;
529
593
  }
530
594
 
531
595
  /** @public */
@@ -546,19 +610,23 @@ export declare interface AsyncSignalOptions<T> extends ComputedOptions {
546
610
  */
547
611
  eagerCleanup?: boolean;
548
612
  /**
549
- * Wait for previous invocation to complete before running again.
613
+ * Time in milliseconds after which the value expires.
550
614
  *
551
- * Defaults to `true`.
615
+ * When the value expires and subscribers exist, the signal is invalidated. If `poll` is `true`
616
+ * (default), the function is re-run automatically. If `poll` is `false`, the value is marked
617
+ * stale and recomputation happens when reading `.value` or `.loading`.
552
618
  *
553
- * @deprecated Not implemented yet
619
+ * `0` (default) means no expiration.
554
620
  */
555
- awaitPrevious?: boolean;
621
+ expires?: number;
556
622
  /**
557
- * In the browser, re-run the function after `interval` ms if subscribers exist, even when no
558
- * input state changed. If `0`, does not poll.
623
+ * Whether to automatically re-run the function when the value expires. Only relevant when
624
+ * `expires` is set.
559
625
  *
560
- * Defaults to `0`.
626
+ * Defaults to `true`.
561
627
  */
628
+ poll?: boolean;
629
+ /** @deprecated Use `expires` and `poll` instead. Will be removed before v2 */
562
630
  interval?: number;
563
631
  /**
564
632
  * When true, the async computation is postponed to the browser. On SSR, the signal remains
@@ -567,6 +635,23 @@ export declare interface AsyncSignalOptions<T> extends ComputedOptions {
567
635
  * Defaults to `false`.
568
636
  */
569
637
  clientOnly?: boolean;
638
+ /**
639
+ * When true (default), the previous value is kept while the signal re-computes after
640
+ * invalidation, so reads return stale data instead of throwing a promise. Reactivity will then
641
+ * update the readers when the new value is ready.
642
+ *
643
+ * When false, invalidation clears the value so reads throw the computation promise (like the
644
+ * initial load), which is useful for navigations where showing old data would be confusing.
645
+ *
646
+ * Note that polling invalidations (`expires` with `poll: true`) are not affected by this option
647
+ * and will keep the old value while the new value is loading, to avoid flashing loaders.
648
+ *
649
+ * This option only affects manual invalidations via `invalidate()`, and non-polling expirations
650
+ * (`poll: false`, or there are no subscribers).
651
+ *
652
+ * Defaults to `true`.
653
+ */
654
+ allowStale?: boolean;
570
655
  /**
571
656
  * Maximum time in milliseconds to wait for the async computation to complete. If exceeded, the
572
657
  * computation is aborted and an error is thrown.
@@ -604,6 +689,10 @@ declare type BivariantQrlFn<ARGS extends any[], RETURN> = {
604
689
  /** @public */
605
690
  declare type Booleanish = boolean | `${boolean}`;
606
691
 
692
+ declare type Capture = {
693
+ [K in keyof HTMLElementEventMap as `capture:${K}`]?: boolean;
694
+ };
695
+
607
696
  /**
608
697
  * The current captured scope during QRL invocation. This is used to provide the lexical scope for
609
698
  * QRL functions. It is used one time per invocation, synchronously, so it is safe to store it in
@@ -630,7 +719,8 @@ declare const enum ChoreBits {
630
719
  CHILDREN = 32,
631
720
  CLEANUP = 64,
632
721
  RECONCILE = 128,
633
- DIRTY_MASK = 255
722
+ ERROR_WRAP = 256,
723
+ DIRTY_MASK = 511
634
724
  }
635
725
 
636
726
  /**
@@ -1164,7 +1254,7 @@ export declare interface DOMAttributes<EL extends Element> extends DOMAttributes
1164
1254
  class?: ClassList | Signal<ClassList> | undefined;
1165
1255
  }
1166
1256
 
1167
- declare interface DOMAttributesBase<EL extends Element> extends QwikIntrinsicAttributes, PreventDefault, StopPropagation, RefAttr<EL> {
1257
+ declare interface DOMAttributesBase<EL extends Element> extends QwikIntrinsicAttributes, PreventDefault, StopPropagation, Capture, Passive, RefAttr<EL> {
1168
1258
  dangerouslySetInnerHTML?: string | undefined;
1169
1259
  }
1170
1260
 
@@ -1439,11 +1529,18 @@ export { h }
1439
1529
  export declare const _hasStoreEffects: (value: StoreTarget, prop: keyof StoreTarget) => boolean;
1440
1530
 
1441
1531
  /**
1442
- * HMR event handler. Replaces the component QRL with a fresh one and marks dirty.
1532
+ * HMR event handler. The host VNode is captured at registration time via QRL captures.
1533
+ *
1534
+ * When called by the qwikloader or the test dispatch, `this` is the serialized captures string
1535
+ * which we deserialize to get the host VNode. When called through `_qDispatch` (client-rendered),
1536
+ * `_captures` is already set by `ensureQrlCaptures` in the QRL call chain.
1443
1537
  *
1444
1538
  * @internal
1445
1539
  */
1446
- export declare const _hmr: (event: Event, element: Element) => void;
1540
+ export declare const _hmr: (this: string | undefined, event: CustomEvent<{
1541
+ files: string[];
1542
+ t: number;
1543
+ }>, element: Element) => void;
1447
1544
 
1448
1545
  declare type HostElement = _VNode | ISsrNode;
1449
1546
 
@@ -1875,6 +1972,7 @@ declare class LazyRef<TYPE = unknown> {
1875
1972
  $ref$?: (null | ValueOrPromise<TYPE>) | undefined;
1876
1973
  $container$: _Container | undefined;
1877
1974
  dev?: QRLDev | null | undefined;
1975
+ qrls?: Set<any>;
1878
1976
  constructor($chunk$: string | null, $symbol$: string, $symbolFn$: undefined | null | (() => Promise<Record<string, TYPE>>), $ref$?: (null | ValueOrPromise<TYPE>) | undefined, container?: _Container | null);
1879
1977
  /** We don't read hash very often so let's not allocate a string for every QRL */
1880
1978
  get $hash$(): string;
@@ -2065,6 +2163,10 @@ declare type PascalCaseName<T extends string> = T extends keyof LcEventNameMap ?
2065
2163
  */
2066
2164
  declare type PascalCaseNames = 'AnimationEnd' | 'AnimationIteration' | 'AnimationStart' | 'AuxClick' | 'BeforeToggle' | 'CanPlay' | 'CanPlayThrough' | 'CompositionEnd' | 'CompositionStart' | 'CompositionUpdate' | 'ContextMenu' | 'DblClick' | 'DragEnd' | 'DragEnter' | 'DragExit' | 'DragLeave' | 'DragOver' | 'DragStart' | 'DurationChange' | 'FocusIn' | 'FocusOut' | 'FullscreenChange' | 'FullscreenError' | 'GotPointerCapture' | 'KeyDown' | 'KeyPress' | 'KeyUp' | 'LoadedData' | 'LoadedMetadata' | 'LoadEnd' | 'LoadStart' | 'LostPointerCapture' | 'MouseDown' | 'MouseEnter' | 'MouseLeave' | 'MouseMove' | 'MouseOut' | 'MouseOver' | 'MouseUp' | 'PointerCancel' | 'PointerDown' | 'PointerEnter' | 'PointerLeave' | 'PointerMove' | 'PointerOut' | 'PointerOver' | 'PointerUp' | 'QIdle' | 'QInit' | 'QResume' | 'QSymbol' | 'QVisible' | 'QViewTransition' | 'RateChange' | 'RateChange' | 'SecurityPolicyViolation' | 'SelectionChange' | 'SelectStart' | 'TimeUpdate' | 'TouchCancel' | 'TouchEnd' | 'TouchMove' | 'TouchStart' | 'TransitionCancel' | 'TransitionEnd' | 'TransitionRun' | 'TransitionStart' | 'VisibilityChange' | 'VolumeChange';
2067
2165
 
2166
+ declare type Passive = {
2167
+ [K in keyof HTMLElementEventMap as `passive:${K}`]?: boolean;
2168
+ };
2169
+
2068
2170
  declare type PopoverTargetAction = 'hide' | 'show' | 'toggle';
2069
2171
 
2070
2172
  declare type PossibleEvents = Event | SimplifiedServerRequestEvent | typeof TaskEvent | typeof RenderEvent;
@@ -2409,6 +2511,7 @@ declare type QRLInternalMethods<TYPE> = {
2409
2511
  /** If this returns false, the function execution will be skipped */
2410
2512
  beforeFn?: () => void | false): TYPE extends (...args: any) => any ? (...args: Parameters<TYPE>) => ValueOrPromise<ReturnType<TYPE> | undefined> : unknown;
2411
2513
  $callFn$(withThis: unknown, ...args: QrlArgs<TYPE>): ValueOrPromise<QrlReturn<TYPE>>;
2514
+ $setDev$(dev: QRLDev | null): void;
2412
2515
  /**
2413
2516
  * "with captures" - Get a new QRL for these captures, reusing the lazy ref. It's an internal
2414
2517
  * method but we need to have a stable name because it gets called in user code by the optimizer,
@@ -3390,6 +3493,7 @@ declare interface SSRContainer extends _Container {
3390
3493
  readonly resolvedManifest: ResolvedManifest;
3391
3494
  additionalHeadNodes: Array<JSXNodeInternal>;
3392
3495
  additionalBodyNodes: Array<JSXNodeInternal>;
3496
+ $noScriptHere$: number;
3393
3497
  write(text: string): void;
3394
3498
  openContainer(): void;
3395
3499
  closeContainer(): ValueOrPromise<void>;
@@ -4165,7 +4269,7 @@ export declare const useLexicalScope: <VARS extends any[]>() => VARS;
4165
4269
  * @public
4166
4270
  * @see `useOn`, `useOnWindow`, `useOnDocument`.
4167
4271
  */
4168
- export declare const useOn: <T extends KnownEventNames>(event: T | T[], eventQrl: EventQRL<T>) => void;
4272
+ export declare const useOn: <T extends KnownEventNames>(event: T | T[], eventQrl: EventQRL<T>, options?: UseOnOptions) => void;
4169
4273
 
4170
4274
  /**
4171
4275
  * Register a listener on `document`.
@@ -4194,7 +4298,21 @@ export declare const useOn: <T extends KnownEventNames>(event: T | T[], eventQrl
4194
4298
  * });
4195
4299
  * ```
4196
4300
  */
4197
- export declare const useOnDocument: <T extends KnownEventNames>(event: T | T[], eventQrl: EventQRL<T>) => void;
4301
+ export declare const useOnDocument: <T extends KnownEventNames>(event: T | T[], eventQrl: EventQRL<T>, options?: UseOnOptions) => void;
4302
+
4303
+ /** @public */
4304
+ export declare type UseOnOptions = UseOnOptionsBase & ({
4305
+ passive?: boolean;
4306
+ preventdefault?: never;
4307
+ } | {
4308
+ passive?: never;
4309
+ preventdefault?: boolean;
4310
+ });
4311
+
4312
+ declare interface UseOnOptionsBase {
4313
+ capture?: boolean;
4314
+ stoppropagation?: boolean;
4315
+ }
4198
4316
 
4199
4317
  /**
4200
4318
  * Register a listener on `window`.
@@ -4224,7 +4342,7 @@ export declare const useOnDocument: <T extends KnownEventNames>(event: T | T[],
4224
4342
  * });
4225
4343
  * ```
4226
4344
  */
4227
- export declare const useOnWindow: <T extends KnownEventNames>(event: T | T[], eventQrl: EventQRL<T>) => void;
4345
+ export declare const useOnWindow: <T extends KnownEventNames>(event: T | T[], eventQrl: EventQRL<T>, options?: UseOnOptions) => void;
4228
4346
 
4229
4347
  /**
4230
4348
  * This method works like an async memoized function that runs whenever some tracked value changes
@@ -4621,7 +4739,7 @@ export declare const _VAR_PROPS: unique symbol;
4621
4739
  export declare const _verifySerializable: <T>(value: T, preMessage?: string) => T;
4622
4740
 
4623
4741
  /**
4624
- * 2.0.0-beta.30-dev+5421ed4
4742
+ * 2.0.0-beta.32-dev+0e29f8a
4625
4743
  *
4626
4744
  * @public
4627
4745
  */