@qwik.dev/router 2.0.0-beta.28 → 2.0.0-beta.29

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.
Files changed (42) hide show
  1. package/lib/adapters/azure-swa/vite/index.mjs +31 -36
  2. package/lib/adapters/bun-server/vite/index.mjs +0 -3
  3. package/lib/adapters/cloud-run/vite/index.mjs +0 -3
  4. package/lib/adapters/cloudflare-pages/vite/index.mjs +15 -9
  5. package/lib/adapters/deno-server/vite/index.mjs +7 -5
  6. package/lib/adapters/netlify-edge/vite/index.mjs +13 -23
  7. package/lib/adapters/node-server/vite/index.mjs +0 -3
  8. package/lib/adapters/shared/vite/index.d.ts +1 -7
  9. package/lib/adapters/shared/vite/index.mjs +164 -136
  10. package/lib/adapters/ssg/vite/index.mjs +3 -4
  11. package/lib/adapters/vercel-edge/vite/index.mjs +25 -9
  12. package/lib/chunks/error-handler.mjs +26 -26
  13. package/lib/chunks/fs.mjs +28 -138
  14. package/lib/chunks/http-error.qwik.mjs +27 -0
  15. package/lib/chunks/not-found-wrapper.qwik.mjs +25 -0
  16. package/lib/chunks/pathname.mjs +105 -0
  17. package/lib/chunks/routing.qwik.mjs +592 -216
  18. package/lib/chunks/system.mjs +328 -0
  19. package/lib/chunks/use-functions.qwik.mjs +35 -0
  20. package/lib/chunks/worker-thread.mjs +271 -0
  21. package/lib/index.d.ts +136 -102
  22. package/lib/index.qwik.mjs +699 -751
  23. package/lib/middleware/aws-lambda/index.mjs +7 -1
  24. package/lib/middleware/azure-swa/index.mjs +7 -2
  25. package/lib/middleware/bun/index.mjs +20 -5
  26. package/lib/middleware/cloudflare-pages/index.mjs +8 -2
  27. package/lib/middleware/deno/index.mjs +19 -5
  28. package/lib/middleware/netlify-edge/index.mjs +8 -2
  29. package/lib/middleware/node/index.mjs +10 -14
  30. package/lib/middleware/request-handler/index.d.ts +82 -12
  31. package/lib/middleware/request-handler/index.mjs +661 -524
  32. package/lib/middleware/vercel-edge/index.mjs +8 -2
  33. package/lib/modules.d.ts +7 -4
  34. package/lib/ssg/index.d.ts +48 -16
  35. package/lib/ssg/index.mjs +320 -7
  36. package/lib/vite/index.d.ts +6 -0
  37. package/lib/vite/index.mjs +1098 -641
  38. package/modules.d.ts +7 -4
  39. package/package.json +4 -4
  40. package/lib/chunks/format-error.mjs +0 -137
  41. package/lib/chunks/index.mjs +0 -896
  42. package/lib/chunks/types.qwik.mjs +0 -22
package/lib/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  /// <reference path="./modules.d.ts" />
2
2
 
3
- import type { AsyncSignal } from '@qwik.dev/core/internal';
3
+ import type { AsyncSignal } from '@qwik.dev/core';
4
4
  import { Component } from '@qwik.dev/core';
5
5
  import { Cookie } from '@qwik.dev/router/middleware/request-handler';
6
6
  import { CookieOptions } from '@qwik.dev/router/middleware/request-handler';
7
7
  import { CookieValue } from '@qwik.dev/router/middleware/request-handler';
8
8
  import { DeferReturn } from '@qwik.dev/router/middleware/request-handler';
9
9
  import type { EnvGetter } from '@qwik.dev/router/middleware/request-handler';
10
- import { JSXOutput as JSXOutput_2 } from '@qwik.dev/core';
10
+ import { JSXOutput } from '@qwik.dev/core';
11
11
  import { QRL } from '@qwik.dev/core';
12
12
  import { QRLEventHandlerMulti } from '@qwik.dev/core';
13
13
  import { QwikIntrinsicElements } from '@qwik.dev/core';
@@ -161,6 +161,17 @@ export declare type ActionStore<RETURN, INPUT, OPTIONAL extends boolean = true>
161
161
 
162
162
  declare type AnchorAttributes = QwikIntrinsicElements['a'];
163
163
 
164
+ /**
165
+ * The cacheKey export type. When exported from a page module alongside eTag, enables in-memory SSR
166
+ * caching.
167
+ *
168
+ * - `true`: use the default cache key `status|eTag|pathname`
169
+ * - Function: receives status, eTag, and pathname; returns a cache key string or null (no cache)
170
+ *
171
+ * @public
172
+ */
173
+ export declare type CacheKeyFn = true | ((status: number, eTag: string, pathname: string) => string | null);
174
+
164
175
  /** @public */
165
176
  export declare interface ContentHeading {
166
177
  readonly text: string;
@@ -177,9 +188,17 @@ export declare interface ContentMenu {
177
188
 
178
189
  declare type ContentModule = PageModule | LayoutModule;
179
190
 
180
- declare type ContentModuleHead = DocumentHead | ResolvedDocumentHead;
191
+ /**
192
+ * The eTag export type: a static string or a function receiving DocumentHeadProps.
193
+ *
194
+ * @public
195
+ */
196
+ export declare type ContentModuleETag = string | ((props: DocumentHeadProps) => string | null);
197
+
198
+ /** @public */
199
+ export declare type ContentModuleHead = DocumentHead | ResolvedDocumentHead;
181
200
 
182
- declare type ContentModuleLoader = () => Promise<ContentModule>;
201
+ declare type ContentModuleLoader = () => ValueOrPromise<ContentModule>;
183
202
 
184
203
  /** @public */
185
204
  declare interface ContentState {
@@ -221,7 +240,7 @@ export { CookieValue }
221
240
  * @public
222
241
  */
223
242
  export declare const createRenderer: (getOptions: (options: RendererOptions) => {
224
- jsx: JSXOutput_2;
243
+ jsx: JSXOutput;
225
244
  options: RendererOutputOptions;
226
245
  }) => Render;
227
246
 
@@ -232,20 +251,14 @@ export declare type DataValidator<T extends Record<string, any> = {}> = {
232
251
 
233
252
  export { DeferReturn }
234
253
 
235
- /** @public */
236
- declare interface DevJSX {
237
- fileName: string;
238
- lineNumber: number;
239
- columnNumber: number;
240
- stack?: string;
241
- }
242
-
243
254
  /** @public */
244
255
  export declare type DocumentHead = DocumentHeadValue | ((props: DocumentHeadProps) => DocumentHeadValue);
245
256
 
246
257
  /** @public */
247
258
  export declare interface DocumentHeadProps extends RouteLocation {
248
259
  readonly head: ResolvedDocumentHead;
260
+ /** The HTTP status code of the response (e.g. 200, 404). */
261
+ readonly status: number;
249
262
  /** @deprecated This is not necessary, it works correctly without */
250
263
  readonly withLocale: <T>(fn: () => T) => T;
251
264
  readonly resolveValue: ResolveSyncValue;
@@ -339,10 +352,11 @@ export declare type DocumentStyle = Readonly<((Omit<QwikIntrinsicElements['style
339
352
  style?: never;
340
353
  })>;
341
354
 
342
- declare type EndpointModuleLoader = () => Promise<RouteModule>;
355
+ declare type EndpointModuleLoader = () => ValueOrPromise<RouteModule>;
343
356
 
344
357
  declare interface EndpointResponse {
345
358
  status: number;
359
+ statusMessage?: string;
346
360
  loaders: Record<string, unknown>;
347
361
  loadersSerializationStrategy: Map<string, SerializationStrategy>;
348
362
  formData?: FormData;
@@ -368,7 +382,7 @@ export declare type FailOfRest<REST extends readonly DataValidator[]> = REST ext
368
382
  export declare type FailReturn<T> = T & Failed;
369
383
 
370
384
  /** @public */
371
- export declare const Form: <O, I>({ action, spaReset, reloadDocument, onSubmit$, ...rest }: FormProps<O, I>, key: string | null) => JSXOutput_2;
385
+ export declare const Form: <O, I>({ action, spaReset, reloadDocument, onSubmit$, ...rest }: FormProps<O, I>, key: string | null) => JSXOutput;
372
386
 
373
387
  /** @public */
374
388
  export declare interface FormProps<O, I> extends Omit<QwikJSX.IntrinsicElements['form'], 'action' | 'method'> {
@@ -399,17 +413,6 @@ export declare interface FormSubmitSuccessDetail<T> {
399
413
  value: T;
400
414
  }
401
415
 
402
- /**
403
- * Any function taking a props object that returns JSXOutput.
404
- *
405
- * The `key`, `flags` and `dev` parameters are for internal use.
406
- *
407
- * @public
408
- */
409
- declare type FunctionComponent<P = unknown> = {
410
- renderFn(props: P, key: string | null, flags: number, dev?: DevJSX): JSXOutput;
411
- }['renderFn'];
412
-
413
416
  /** @public */
414
417
  export declare type GetValidatorInputType<VALIDATOR extends TypedDataValidator> = VALIDATOR extends ValibotDataValidator<infer TYPE> ? v.InferInput<TYPE> : VALIDATOR extends ZodDataValidator<infer TYPE> ? z_2.input<TYPE> : never;
415
418
 
@@ -424,6 +427,14 @@ export declare const globalAction$: ActionConstructor;
424
427
 
425
428
  /* Excluded from this release type: globalActionQrl */
426
429
 
430
+ /** @public */
431
+ export declare type HttpErrorProps = {
432
+ /** The HTTP status code, e.g. 404 */
433
+ status: number;
434
+ /** The error message, e.g. "Not Found" */
435
+ message: string;
436
+ };
437
+
427
438
  declare type IsAny<Type> = 0 extends 1 & Type ? true : false;
428
439
 
429
440
  /** @public */
@@ -436,31 +447,9 @@ export declare type JSONValue = string | number | boolean | {
436
447
  [x: string]: JSONValue;
437
448
  } | Array<JSONValue>;
438
449
 
439
- /** @public */
440
- declare type JSXChildren = string | number | boolean | null | undefined | Function | RegExp | JSXChildren[] | Promise<JSXChildren> | Signal_2<JSXChildren> | JSXNode;
441
-
442
- /**
443
- * A JSX Node, an internal structure. You probably want to use `JSXOutput` instead.
444
- *
445
- * @public
446
- */
447
- declare interface JSXNode<T extends string | FunctionComponent | unknown = unknown> {
448
- type: T;
449
- props: T extends FunctionComponent<infer P> ? P : Record<any, unknown>;
450
- children: JSXChildren | null;
451
- key: string | null;
452
- dev?: DevJSX;
453
- }
454
-
455
- /**
456
- * Any valid output for a component
457
- *
458
- * @public
459
- */
460
- declare type JSXOutput = JSXNode | string | number | boolean | null | undefined | JSXOutput[];
461
-
462
450
  declare interface LayoutModule extends RouteModule {
463
- readonly default: unknown;
451
+ readonly default?: (props: Record<string, never>) => JSXOutput;
452
+ readonly routeConfig?: RouteConfig;
464
453
  readonly head?: ContentModuleHead;
465
454
  }
466
455
 
@@ -491,13 +480,23 @@ export declare interface LinkProps extends AnchorAttributes {
491
480
  scroll?: boolean;
492
481
  }
493
482
 
494
- declare type LoadedRoute = [
495
- routeName: string,
496
- params: PathParams,
497
- mods: (RouteModule | ContentModule)[],
498
- menu: ContentMenu | undefined,
499
- routeBundleNames: string[] | undefined
500
- ];
483
+ /** The route to render */
484
+ declare interface LoadedRoute {
485
+ /** The canonical path of the route, e.g. `/products/[id]` */
486
+ $routeName$: string;
487
+ /** The route parameters, e.g. `{ id: '123' }` */
488
+ $params$: PathParams;
489
+ /** The modules associated with this route (on 404, contains only the error component) */
490
+ $mods$: (RouteModule | ContentModule)[];
491
+ /** The menu associated with this route */
492
+ $menu$?: ContentMenu | undefined;
493
+ /** The bundle names for this route */
494
+ $routeBundleNames$?: string[] | undefined;
495
+ /** Whether this route is a not-found (404) route */
496
+ $notFound$?: boolean;
497
+ /** The error module loader (nearest _E ancestor), for rendering ServerErrors */
498
+ $errorLoader$?: ContentModuleLoader;
499
+ }
501
500
 
502
501
  /** @public */
503
502
  declare type Loader_2<RETURN> = {
@@ -531,9 +530,6 @@ declare type LoaderOptions = {
531
530
  /** @public */
532
531
  export declare type LoaderSignal<TYPE> = (TYPE extends () => ValueOrPromise<infer VALIDATOR> ? Signal<ValueOrPromise<VALIDATOR>> : Signal<TYPE>) & Pick<AsyncSignal, 'promise' | 'loading' | 'error'>;
533
532
 
534
- /** @public */
535
- export declare type MenuData = [pathname: string, menuLoader: MenuModuleLoader];
536
-
537
533
  declare interface MenuModule {
538
534
  readonly default: ContentMenu;
539
535
  }
@@ -555,12 +551,15 @@ export { NavigationType_2 as NavigationType }
555
551
  export declare function omitProps<T, KEYS extends keyof T>(obj: T, keys: KEYS[]): Omit<T, KEYS>;
556
552
 
557
553
  /** @public */
558
- export declare interface PageModule extends RouteModule {
559
- readonly default: unknown;
554
+ export declare type PageModule = RouteModule & {
555
+ readonly default: (props: Record<string, never>) => JSXOutput;
556
+ readonly routeConfig?: RouteConfig;
560
557
  readonly head?: ContentModuleHead;
558
+ readonly eTag?: ContentModuleETag;
559
+ readonly cacheKey?: CacheKeyFn;
561
560
  readonly headings?: ContentHeading[];
562
561
  readonly onStaticGenerate?: StaticGenerateHandler;
563
- }
562
+ };
564
563
 
565
564
  /** @public */
566
565
  export declare type PathParams = Record<string, string>;
@@ -620,12 +619,13 @@ export declare const QwikCityProvider: Component<QwikRouterProps>;
620
619
 
621
620
  /** @public */
622
621
  export declare interface QwikRouterConfig {
623
- readonly routes: RouteData[];
622
+ readonly routes: RouteData;
624
623
  readonly serverPlugins?: RouteModule[];
625
624
  readonly basePathname?: string;
626
- readonly menus?: MenuData[];
627
625
  readonly trailingSlash?: boolean;
628
626
  readonly cacheModules?: boolean;
627
+ /** When true, return null instead of rendering the 404 page, letting the adapter handle it */
628
+ readonly fallthrough?: boolean;
629
629
  }
630
630
 
631
631
  /** @public */
@@ -634,7 +634,7 @@ export declare interface QwikRouterEnvData {
634
634
  ev: RequestEvent;
635
635
  params: PathParams;
636
636
  response: EndpointResponse;
637
- loadedRoute: LoadedRoute | null;
637
+ loadedRoute: LoadedRoute;
638
638
  }
639
639
 
640
640
  /** @public */
@@ -752,18 +752,73 @@ declare type RouteActionResolver = {
752
752
  result: unknown;
753
753
  };
754
754
 
755
- /** @public */
756
- export declare type RouteData = [
757
- routeName: string,
758
- moduleLoaders: ModuleLoader[]
759
- ] | [
760
- routeName: string,
761
- moduleLoaders: ModuleLoader[],
762
- /** The actual src/routes pathname, not rewritten */
763
- originalPathname: string,
764
- /** The bundles that contain the loaders */
765
- routeBundleNames: string[]
766
- ];
755
+ /**
756
+ * Unified route configuration export. Groups head, eTag, and cacheKey with the same resolution
757
+ * rules as DocumentHead: can be a static object or a function receiving DocumentHeadProps.
758
+ *
759
+ * When a module exports `routeConfig`, the separate `head`, `eTag`, and `cacheKey` exports are
760
+ * ignored for that module.
761
+ *
762
+ * @public
763
+ */
764
+ export declare type RouteConfig = RouteConfigValue | ((props: DocumentHeadProps) => RouteConfigValue);
765
+
766
+ /**
767
+ * The value shape returned by a routeConfig export (object form or function return).
768
+ *
769
+ * @public
770
+ */
771
+ export declare interface RouteConfigValue {
772
+ readonly head?: DocumentHeadValue;
773
+ readonly eTag?: ContentModuleETag;
774
+ readonly cacheKey?: CacheKeyFn;
775
+ }
776
+
777
+ /**
778
+ * A nested route trie structure. The root represents `/` and each level represents a URL segment.
779
+ *
780
+ * Keys starting with `_` are metadata; all other keys are child route segments.
781
+ *
782
+ * - Use `_W` as the key for a single dynamic segment (param); `_P` on that node names the param.
783
+ * - Use `_A` as the key for a rest/catch-all segment; `_P` on that node names the param.
784
+ * - For infix params like `pre[slug]post`, use `_W` with `_0` (prefix) and `_9` (suffix).
785
+ * - Use `_M` for an array of group (pathless layout) nodes, sorted by group name.
786
+ *
787
+ * When matching, exact segments are tried first (case-insensitive), then `_W` (with optional
788
+ * prefix/suffix), then `_A`. When no route matches, the closest `_E` (error.tsx) or `_4` (404.tsx)
789
+ * loader in the ancestor chain is used to render the error page.
790
+ *
791
+ * @public
792
+ */
793
+ export declare interface RouteData {
794
+ /** This node's layout loader (single). Runtime accumulates these during trie traversal. */
795
+ _L?: ContentModuleLoader;
796
+ /**
797
+ * This node's index/page loader. Single = normal (runtime prepends gathered _L). Array = override
798
+ * (layout stop / named layout — IS the complete chain).
799
+ */
800
+ _I?: ContentModuleLoader | ModuleLoader[];
801
+ /** Rewrite/goto target path. Matcher re-walks trie from root using this path's keys. */
802
+ _G?: string;
803
+ /** The JS bundle names for this route (SSR only) */
804
+ _B?: string[];
805
+ /** The not-found (404) module loader for this subtree */
806
+ _4?: ContentModuleLoader;
807
+ /** The error page module loader for this subtree (error.tsx, takes precedence over _4) */
808
+ _E?: ContentModuleLoader;
809
+ /** The parameter name when this node is reached via `_W` or `_A` from the parent */
810
+ _P?: string;
811
+ /** Prefix for infix params (e.g. "pre" for `pre[slug]post`) — only on `_W` nodes */
812
+ _0?: string;
813
+ /** Suffix for infix params (e.g. "post" for `pre[slug]post`) — only on `_W` nodes */
814
+ _9?: string;
815
+ /** Group (pathless layout) nodes merged into this level, sorted by group name */
816
+ _M?: RouteData[];
817
+ /** Menu loader for this subtree (from menu.md). Runtime uses nearest ancestor during traversal. */
818
+ _N?: MenuModuleLoader;
819
+ /** Child route segments (any key not starting with `_`) */
820
+ [part: string]: RouteData | RouteData[] | ModuleLoader[] | ContentModuleLoader | MenuModuleLoader | string[] | string | undefined;
821
+ }
767
822
 
768
823
  /** @public */
769
824
  export declare const routeLoader$: LoaderConstructor;
@@ -856,30 +911,6 @@ export declare const ServiceWorkerRegister: (props: {
856
911
  nonce?: string;
857
912
  }) => JSXOutput;
858
913
 
859
- /**
860
- * A signal is a reactive value which can be read and written. When the signal is written, all tasks
861
- * which are tracking the signal will be re-run and all components that read the signal will be
862
- * re-rendered.
863
- *
864
- * Furthermore, when a signal value is passed as a prop to a component, the optimizer will
865
- * automatically forward the signal. This means that `return <div title={signal.value}>hi</div>`
866
- * will update the `title` attribute when the signal changes without having to re-render the
867
- * component.
868
- *
869
- * @public
870
- */
871
- declare interface Signal_2<T = any> {
872
- /** Reading from this subscribes to updates; writing to this triggers updates. */
873
- value: T;
874
- /** Reading from this does not subscribe to updates; writing to this does not trigger updates. */
875
- untrackedValue: T;
876
- /**
877
- * Use this to trigger running subscribers, for example when the value mutated but remained the
878
- * same object.
879
- */
880
- trigger(): void;
881
- }
882
-
883
914
  /** @public */
884
915
  export declare interface StaticGenerate {
885
916
  params?: PathParams[];
@@ -916,6 +947,9 @@ export declare const useContent: () => ContentState;
916
947
  */
917
948
  export declare const useDocumentHead: <FrontMatter extends Record<string, unknown> = Record<string, any>>() => Required<ResolvedDocumentHead<FrontMatter>>;
918
949
 
950
+ /** @public */
951
+ export declare const useHttpStatus: () => HttpErrorProps;
952
+
919
953
  /** @public */
920
954
  export declare const useLocation: () => RouteLocation;
921
955