@qwik.dev/router 2.0.0-rc.4 → 2.0.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { t as ensureSlash } from "../../../chunks/pathname.mjs";
2
- import { r as LOADER_REGEX } from "../../../chunks/request-path.mjs";
2
+ import { i as LOADER_REGEX } from "../../../chunks/request-path.mjs";
3
3
  import fs from "node:fs";
4
4
  import { basename, dirname, join, resolve } from "node:path";
5
5
  import { spawn } from "node:child_process";
@@ -1,5 +1,5 @@
1
1
  import { t as ensureSlash } from "./pathname.mjs";
2
- import { o as getLoaderName } from "./request-path.mjs";
2
+ import { s as getLoaderName } from "./request-path.mjs";
3
3
  import { i as RedirectMessage, n as throwIfControlFlowSignal, t as ServerError } from "./server-error.mjs";
4
4
  import { n as isStaticTrieKey, r as unescapeStaticTrieKey, t as escapeStaticTrieKey } from "./route-trie-key.mjs";
5
5
  import { _capturesObj, createComputedQrl, createContextId, implicit$FirstArg, inlinedQrl, isBrowser, isDev, isServer, untrack, useServerData, withLocale } from "@qwik.dev/core";
@@ -21,6 +21,66 @@ var _asyncRequestStore = isServer$1 ? _registerSingleton("routerRequestStore", c
21
21
  var RequestEvRouterConfig = /*#__PURE__*/ _qwikSymbol("router.config");
22
22
  /** The config of the app serving the current request, for a router copy that holds none. */
23
23
  var getServingRouterConfig = () => _asyncRequestStore?.getStore()?.[RequestEvRouterConfig];
24
+ /**
25
+ * FNV-1a 32-bit hash for generating eTags from response data. Cheap to compute, sufficient
26
+ * collision resistance for cache validation (not cryptographic).
27
+ */
28
+ function hash(str) {
29
+ let hash = 2166136261;
30
+ for (let i = 0; i < str.length; i++) {
31
+ hash ^= str.charCodeAt(i);
32
+ hash = hash * 16777619 | 0;
33
+ }
34
+ return (hash >>> 0).toString(36);
35
+ }
36
+ /**
37
+ * Normalize an ETag header value (or a single `If-None-Match` entry) into a canonical form so byte
38
+ * equality compares the same logical tag. Strips weak ETag syntax (`W/"..."`), quotes, and any
39
+ * character outside RFC 7232's `etagc` grammar (printable ASCII except DQUOTE — no escape mechanism
40
+ * exists, and non-ASCII bytes are mangled by many HTTP stacks even though `obs-text` technically
41
+ * permits them). Idempotent.
42
+ */
43
+ function normalizeETag(raw) {
44
+ let tag = raw.trim();
45
+ if (tag.endsWith("\"") && tag.startsWith("W/\"")) tag = tag.slice(3);
46
+ tag = tag.replace(/[^!#-~]/g, "");
47
+ return tag;
48
+ }
49
+ function setETagHeader(requestEv, normalizedETag) {
50
+ const headerETag = `"${normalizedETag}"`;
51
+ requestEv.headers.set("ETag", headerETag);
52
+ }
53
+ /**
54
+ * Set the strong ETag header on the response and check the request's `If-None-Match` against it.
55
+ * The eTag argument must already be normalized. Returns true if a 304 was sent (caller should stop
56
+ * processing).
57
+ */
58
+ function performETagMatch(requestEv, normalizedETag, beforeNotModified) {
59
+ setETagHeader(requestEv, normalizedETag);
60
+ const ifNoneMatch = requestEv.request.headers.get("If-None-Match");
61
+ if (ifNoneMatch) {
62
+ let found = ifNoneMatch.trim() === "*";
63
+ if (!found) {
64
+ for (const entry of ifNoneMatch.split(",")) if (normalizeETag(entry) === normalizedETag) {
65
+ found = true;
66
+ break;
67
+ }
68
+ }
69
+ if (found) {
70
+ beforeNotModified?.();
71
+ requestEv.status(304);
72
+ requestEv.send(304, "");
73
+ return true;
74
+ }
75
+ }
76
+ return false;
77
+ }
78
+ /** Resolve eTag from a static string or function (before running the loader). */
79
+ function resolvePreETag(eTagOption, requestEv) {
80
+ if (typeof eTagOption === "string") return normalizeETag(eTagOption);
81
+ const result = eTagOption(requestEv);
82
+ return result ? normalizeETag(result) : "";
83
+ }
24
84
  var QACTION_KEY = "qaction";
25
85
  var QFN_KEY = "qfunc";
26
86
  var QDATA_KEY = "qdata";
@@ -132,6 +192,45 @@ var getBasePathname = () => findRouterConfig()?.basePathname ?? globalThis.__QWI
132
192
  var getTrailingSlash = () => findRouterConfig()?.trailingSlash ?? !globalThis.__NO_TRAILING_SLASH__;
133
193
  /** @internal */
134
194
  var _getServiceWorkerUrl = () => findRouterConfig()?.serviceWorkerUrl;
195
+ /** Gets an absolute url path string (url.pathname + url.search + url.hash) */
196
+ var toPath = (url) => url.pathname + url.search + url.hash;
197
+ /** Create a URL from a string and baseUrl */
198
+ var toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
199
+ /** Resolves a redirect without allowing executable URL schemes. */
200
+ var toSafeRedirectUrl = (url, baseUrl) => {
201
+ const redirectUrl = toUrl(url, baseUrl);
202
+ if (redirectUrl.protocol !== "http:" && redirectUrl.protocol !== "https:") throw new Error(`Unsupported redirect protocol: ${redirectUrl.protocol}`);
203
+ return redirectUrl;
204
+ };
205
+ /** Checks only if the origins are the same. */
206
+ var isSameOrigin = (a, b) => a.origin === b.origin;
207
+ /** Checks only if the pathnames are the same for the URLs (doesn't include search and hash) */
208
+ var isSamePathname = ({ pathname: a }, { pathname: b }) => {
209
+ const lDiff = Math.abs(a.length - b.length);
210
+ return lDiff === 0 ? a === b : lDiff === 1 && ensureSlash(a) === ensureSlash(b);
211
+ };
212
+ /** Checks only if the search query strings are the same for the URLs */
213
+ var isSameSearchQuery = (a, b) => a.search === b.search;
214
+ /** Checks only if the pathname + search are the same for the URLs. */
215
+ var isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
216
+ var getClientNavPath = (props, baseUrl) => {
217
+ const href = props.href;
218
+ if (typeof href === "string" && typeof props.target !== "string" && !props.reload) try {
219
+ const linkUrl = toUrl(href.trim(), baseUrl.url);
220
+ if (isSameOrigin(linkUrl, toUrl("", baseUrl.url))) return toPath(linkUrl);
221
+ } catch (e) {
222
+ console.error(e);
223
+ }
224
+ else if (props.reload) return toPath(toUrl("", baseUrl.url));
225
+ return null;
226
+ };
227
+ var shouldPreload = (clientNavPath, currentLoc) => {
228
+ if (clientNavPath) return !isSamePathname(toUrl(clientNavPath, currentLoc.url), toUrl("", currentLoc.url));
229
+ return false;
230
+ };
231
+ var isPromise = (value) => {
232
+ return value && typeof value.then === "function";
233
+ };
135
234
  /**
136
235
  * Route loaders read data before the route rendering starts, based on the route being navigated to.
137
236
  * They automatically update when the route changes on the client.
@@ -214,14 +313,21 @@ var ServerRouteLoaderCapture = class {
214
313
  qrl;
215
314
  validators;
216
315
  blockSSR;
316
+ loader;
217
317
  requestEv;
218
- constructor(hash2, qrl1, validators1, blockSSR1, requestEv1) {
318
+ constructor(hash2, qrl1, validators1, blockSSR1, loader1, requestEv1) {
219
319
  this.hash = hash2;
220
320
  this.qrl = qrl1;
221
321
  this.validators = validators1;
222
322
  this.blockSSR = blockSSR1;
323
+ this.loader = loader1;
223
324
  this.requestEv = requestEv1;
224
325
  }
326
+ /** The eTag the q-loader endpoint will send for a value that isn't serialized. */
327
+ eTag() {
328
+ const option = this.loader.__eTag;
329
+ if (this.requestEv && option !== void 0 && this.loader.__serializationStrategy !== "always") return resolvePreETag(option, getLoaderRequestEvent(this.loader, this.requestEv));
330
+ }
225
331
  load() {
226
332
  const requestEv2 = this.requestEv;
227
333
  if (!requestEv2) throw new Error("Unable to determine the current RequestEvent.");
@@ -255,7 +361,7 @@ var fetchRouteLoaderData = async (loaderId, routePath, manifestHash, opts) => {
255
361
  if (!globalThis.__STRICT_LOADERS__) headers[FULLPATH_HEADER] = pageUrl.pathname;
256
362
  else if (isDev) headers[ROUTE_PATH_HEADER] = pageUrl.pathname;
257
363
  }
258
- const cacheKey = `${url}\n${headers["X-Qwik-fullpath"] ?? ""}`;
364
+ const cacheKey = `${url}\n${headers["X-Qwik-fullpath"] ?? headers["X-Qwik-route-path"] ?? ""}`;
259
365
  const cache = navFetchCache;
260
366
  if (!opts?.ignoreCache) {
261
367
  const entry = cache.get(cacheKey);
@@ -282,7 +388,10 @@ var fetchRouteLoaderData = async (loaderId, routePath, manifestHash, opts) => {
282
388
  if (!response.ok) return;
283
389
  const raw = await response.text();
284
390
  opts?.signal?.throwIfAborted();
285
- return { raw };
391
+ return {
392
+ raw,
393
+ eTag: response.headers.get("ETag") ?? void 0
394
+ };
286
395
  };
287
396
  if (opts?.ignoreCache) return request();
288
397
  if (opts?.signal) return request().then((value) => {
@@ -311,14 +420,17 @@ var retainLoaderValue = (previous, abortSignal) => {
311
420
  abortSignal.addEventListener("abort", () => reject(abortSignal.reason), { once: true });
312
421
  });
313
422
  };
314
- var createRouteLoaderSignal = (loader, routeLoaderCtx, state, requestEv3) => {
315
- const id = loader.__id;
316
- const capture = isServer ? new ServerRouteLoaderCapture(id, loader.__qrl, loader.__validators, loader.__blockSSR, requestEv3 ?? useServerData("qwikrouter")?.ev) : id;
317
- const searchFilter = loader.__search;
318
- const loaderHash = isDev ? loader.__qrl.getHash() : id;
423
+ var createRouteLoaderSignal = (loader2, routeLoaderCtx, state, requestEv3) => {
424
+ const id = loader2.__id;
425
+ const capture = isServer ? new ServerRouteLoaderCapture(id, loader2.__qrl, loader2.__validators, loader2.__blockSSR, loader2, requestEv3 ?? useServerData("qwikrouter")?.ev) : id;
426
+ const searchFilter = loader2.__search;
427
+ const loaderHash = isDev ? loader2.__qrl.getHash() : id;
319
428
  const signal = createComputedQrl(/*#__PURE__*/ inlinedQrl(async (ctx) => {
320
429
  let capture = _capturesObj._[0], id = _capturesObj._[1], lastFetch = _capturesObj._[2], loaderHash = _capturesObj._[3], routeLoaderCtx = _capturesObj._[4], searchFilter = _capturesObj._[5], state = _capturesObj._[6];
321
- if (!!ctx.info && typeof ctx.info === "object" && "__v" in ctx.info) {
430
+ const hasInjectedValue = !!ctx.info && typeof ctx.info === "object" && "__v" in ctx.info;
431
+ const eTag1 = isServer && capture.eTag();
432
+ if (eTag1) lastFetch.e = eTag1;
433
+ if (hasInjectedValue) {
322
434
  const value = ctx.info.__v;
323
435
  lastFetch.raw = void 0;
324
436
  return value;
@@ -329,12 +441,13 @@ var createRouteLoaderSignal = (loader, routeLoaderCtx, state, requestEv3) => {
329
441
  const pageUrl = new URL(request.pageUrl);
330
442
  const mHash = untrack(() => routeLoaderCtx.manifestHash) || "dev";
331
443
  const basePath = getBasePathname();
444
+ const fetchRoutePath = request.routePath;
332
445
  let fetchUrl = pageUrl;
333
446
  if (searchFilter) {
334
447
  fetchUrl = new URL(pageUrl.href);
335
448
  fetchUrl.search = filterSearchParams(pageUrl.searchParams, searchFilter);
336
449
  }
337
- const result = await fetchRouteLoaderData(id, request.routePath, mHash, {
450
+ const result = await fetchRouteLoaderData(id, fetchRoutePath, mHash, {
338
451
  pageUrl: fetchUrl,
339
452
  basePath,
340
453
  ignoreCache: ctx.info === true,
@@ -351,13 +464,30 @@ var createRouteLoaderSignal = (loader, routeLoaderCtx, state, requestEv3) => {
351
464
  }
352
465
  assertCurrentLoaderRequest(routeLoaderCtx, state[id], request, ctx.abortSignal);
353
466
  if (response.r) {
467
+ const redirectUrl = toSafeRedirectUrl(response.r, pageUrl);
354
468
  const goto = routeLoaderCtx.goto;
355
- if (goto) goto(response.r, { replaceState: true });
356
- else location.href = response.r;
357
- return retainLoaderValue(ctx.previous, ctx.abortSignal);
469
+ const prepared = Promise.resolve().then(() => {
470
+ assertCurrentLoaderRequest(routeLoaderCtx, state[id], request, ctx.abortSignal);
471
+ if (goto) return goto(redirectUrl.href, { replaceState: true });
472
+ location.href = redirectUrl.href;
473
+ return new Promise(() => {});
474
+ });
475
+ request.redirect = prepared;
476
+ return wrapWithAbort(prepared, ctx.abortSignal).then(() => {
477
+ assertCurrentLoaderRequest(routeLoaderCtx, state[id], request, ctx.abortSignal);
478
+ try {
479
+ return state[id].untrackedValue;
480
+ } catch {
481
+ throw new Error("Route loader redirect completed without data.");
482
+ }
483
+ }).finally(() => {
484
+ if (request.redirect === prepared) request.redirect = void 0;
485
+ });
358
486
  }
359
487
  if (response.e) throw response.e;
360
488
  lastFetch.raw = result.raw;
489
+ if (ctx.previous === void 0 && lastFetch.e && lastFetch.e === normalizeETag(result.eTag || "")) state[id].untrackedValue = response.d;
490
+ lastFetch.e = void 0;
361
491
  const onValue = routeLoaderCtx.onValue;
362
492
  if (onValue) Promise.resolve().then(() => state[id].promise()).then(() => onValue(REFRESH_HEAD));
363
493
  return response.d;
@@ -369,7 +499,7 @@ var createRouteLoaderSignal = (loader, routeLoaderCtx, state, requestEv3) => {
369
499
  routeLoaderCtx,
370
500
  searchFilter,
371
501
  state
372
- ]), { serializationStrategy: loader.__serializationStrategy });
502
+ ]), { serializationStrategy: loader2.__serializationStrategy });
373
503
  _markSignalAsExternallyOwned(signal);
374
504
  return signal;
375
505
  };
@@ -388,7 +518,7 @@ function getLoaderOptions(rest) {
388
518
  let id;
389
519
  let serializationStrategy = DEFAULT_LOADERS_SERIALIZATION_STRATEGY();
390
520
  let cacheControl;
391
- let eTag;
521
+ let eTag2;
392
522
  let cacheKey;
393
523
  let search;
394
524
  let blockSSR2 = true;
@@ -402,7 +532,7 @@ function getLoaderOptions(rest) {
402
532
  if (options.serializationStrategy) serializationStrategy = options.serializationStrategy;
403
533
  if (options.validation) validators2.push(...options.validation);
404
534
  if ("cacheControl" in options) cacheControl = options.cacheControl;
405
- if ("eTag" in options) eTag = options.eTag;
535
+ if ("eTag" in options) eTag2 = options.eTag;
406
536
  if ("cacheKey" in options) cacheKey = options.cacheKey;
407
537
  if (options.search) search = options.search;
408
538
  else if (globalThis.__STRICT_LOADERS__) search = [];
@@ -418,7 +548,7 @@ function getLoaderOptions(rest) {
418
548
  validators: validators2.reverse(),
419
549
  serializationStrategy,
420
550
  cacheControl,
421
- eTag,
551
+ eTag: eTag2,
422
552
  cacheKey,
423
553
  search,
424
554
  blockSSR: blockSSR2
@@ -517,7 +647,7 @@ var isImmutableLoader = (loaderId) => immutableLoaderIds.has(loaderId);
517
647
  function abortRouteLoaderNavigation(ctx) {
518
648
  for (const [signal, request] of clientRouteLoaders.get(ctx)?.current.requests ?? []) {
519
649
  if (signal.untrackedPending) request.isAborted = true;
520
- signal.abort();
650
+ if (!request.redirect) signal.abort();
521
651
  }
522
652
  }
523
653
  /** Search-filtered loaders ignore changes to unlisted params. */
@@ -538,15 +668,15 @@ function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navC
538
668
  };
539
669
  const loaders = ensureRouteLoaderSignals(mods, state, ctx);
540
670
  const routeLoaders = /* @__PURE__ */ new Map();
541
- for (const loader of loaders) {
542
- routeLoaders.set(loader.__id, loader);
543
- current.paths[loader.__id] ||= current.paths[loader.__qrl.getHash()] || pageUrl.pathname;
671
+ for (const loader3 of loaders) {
672
+ routeLoaders.set(loader3.__id, loader3);
673
+ current.paths[loader3.__id] ||= current.paths[loader3.__qrl.getHash()] || pageUrl.pathname;
544
674
  }
545
675
  for (const id in state) {
546
676
  const signal = state[id];
547
677
  const old = previous.requests.get(signal);
548
- const loader = routeLoaders.get(id);
549
- const hash3 = loader?.__qrl.getHash() || old?.hash;
678
+ const loader4 = routeLoaders.get(id);
679
+ const hash3 = loader4?.__qrl.getHash() || old?.hash;
550
680
  const routePath = current.paths[id] || hash3 && current.paths[hash3];
551
681
  if (!routePath) {
552
682
  if (old) current.requests.set(signal, {
@@ -556,7 +686,7 @@ function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navC
556
686
  signal.abort();
557
687
  continue;
558
688
  }
559
- const keepRequest = old?.active && !old.isAborted && old.routePath === routePath && (old.pageUrl === pageUrl.href ? isImmutableLoader(id) : hasSameListedSearch(new URL(old.pageUrl), pageUrl, loader?.__search));
689
+ const keepRequest = old?.active && !old.isAborted && old.routePath === routePath && (old.pageUrl === pageUrl.href ? isImmutableLoader(id) : hasSameListedSearch(new URL(old.pageUrl), pageUrl, loader4?.__search));
560
690
  current.requests.set(signal, keepRequest ? old : {
561
691
  routePath,
562
692
  pageUrl: pageUrl.href,
@@ -598,9 +728,9 @@ function restoreRouteLoaders(state, ctx, navCount) {
598
728
  pruneRouteLoaders(state, ctx);
599
729
  for (const signal of client.current.requests.keys()) signal.invalidate();
600
730
  }
601
- var ensureRouteLoaderSignal = (loader, state, routeLoaderCtx, requestEv12) => {
602
- if (loader.__cacheControl === "immutable") immutableLoaderIds.add(loader.__id);
603
- return state[loader.__id] ||= createRouteLoaderSignal(loader, routeLoaderCtx, state, requestEv12);
731
+ var ensureRouteLoaderSignal = (loader5, state, routeLoaderCtx, requestEv12) => {
732
+ if (loader5.__cacheControl === "immutable") immutableLoaderIds.add(loader5.__id);
733
+ return state[loader5.__id] ||= createRouteLoaderSignal(loader5, routeLoaderCtx, state, requestEv12);
604
734
  };
605
735
  var ensureRouteLoaderSignals = (mods, state, routeLoaderCtx, requestEv13) => {
606
736
  const loaders = getModuleRouteLoaders(mods);
@@ -618,10 +748,10 @@ var setLoaderSignalValue = (signal, value) => {
618
748
  _injectAsyncSignalValue(signal, value);
619
749
  };
620
750
  var resolveRouteLoaderByHash = (routeLoaders, loaderId) => {
621
- return routeLoaders.find((loader) => matchesRouteLoaderId(loader, loaderId));
751
+ return routeLoaders.find((loader6) => matchesRouteLoaderId(loader6, loaderId));
622
752
  };
623
- var matchesRouteLoaderId = (loader, loaderId) => {
624
- return typeof loaderId === "string" && (loader.__id === loaderId || isDev && loader.__qrl.getHash() === loaderId);
753
+ var matchesRouteLoaderId = (loader7, loaderId) => {
754
+ return typeof loaderId === "string" && (loader7.__id === loaderId || isDev && loader7.__qrl.getHash() === loaderId);
625
755
  };
626
756
  /** Run a loader and return its raw value. Errors/redirects propagate as exceptions. */
627
757
  var getRouteLoaderData = async (loaderQrl, validators3, requestEv14) => {
@@ -652,24 +782,24 @@ var loadRouteLoaderByQrl = (loaderId, loaderQrl, validators4, requestEv15) => {
652
782
  return promise;
653
783
  };
654
784
  /** @internal */
655
- var getLoaderRequestEvent = (loader, requestEv16) => {
785
+ var getLoaderRequestEvent = (loader8, requestEv16) => {
656
786
  let rootRequestEv = requestEv16.sharedMap.get(REQUEST_ROUTE_LOADER_ROOT_EVENT);
657
787
  if (!rootRequestEv) {
658
788
  rootRequestEv = requestEv16;
659
789
  requestEv16.sharedMap.set(REQUEST_ROUTE_LOADER_ROOT_EVENT, rootRequestEv);
660
790
  }
661
791
  const url = new URL(rootRequestEv.url);
662
- const pathname = globalThis.__STRICT_LOADERS__ ? getRouteLoaderCtx(rootRequestEv).loaderPaths[loader.__id] || rootRequestEv.url.pathname : rootRequestEv.url.pathname;
663
- const filteredSearch = loader.__search ? filterSearchParams(url.searchParams, loader.__search) : rootRequestEv.url.search;
792
+ const pathname = globalThis.__STRICT_LOADERS__ ? getRouteLoaderCtx(rootRequestEv).loaderPaths[loader8.__id] || rootRequestEv.url.pathname : rootRequestEv.url.pathname;
793
+ const filteredSearch = loader8.__search ? filterSearchParams(url.searchParams, loader8.__search) : rootRequestEv.url.search;
664
794
  const isSameUrl = pathname === rootRequestEv.url.pathname && filteredSearch === rootRequestEv.url.search;
665
- const params = globalThis.__STRICT_LOADERS__ ? getRouteLoaderParams(rootRequestEv)[loader.__id] ?? (pathname === rootRequestEv.url.pathname ? rootRequestEv.params : {}) : rootRequestEv.params;
795
+ const params = globalThis.__STRICT_LOADERS__ ? getRouteLoaderParams(rootRequestEv)[loader8.__id] ?? (pathname === rootRequestEv.url.pathname ? rootRequestEv.params : {}) : rootRequestEv.params;
666
796
  if (isSameUrl && params === rootRequestEv.params) return rootRequestEv;
667
797
  let events = rootRequestEv.sharedMap.get(REQUEST_ROUTE_LOADER_EVENTS);
668
798
  if (!events) {
669
799
  events = /* @__PURE__ */ new Map();
670
800
  rootRequestEv.sharedMap.set(REQUEST_ROUTE_LOADER_EVENTS, events);
671
801
  }
672
- const eventKey = `${pathname}\n${filteredSearch}\n${params === rootRequestEv.params ? "" : loader.__id}`;
802
+ const eventKey = `${pathname}\n${filteredSearch}\n${params === rootRequestEv.params ? "" : loader8.__id}`;
673
803
  let loaderRequestEv = events.get(eventKey);
674
804
  if (!loaderRequestEv) {
675
805
  url.pathname = pathname;
@@ -761,9 +891,9 @@ var detachResponseFromEvent = (requestEv17) => {
761
891
  }
762
892
  });
763
893
  };
764
- var loadRouteLoader = (loader, requestEv18) => {
765
- const loaderEv = getLoaderRequestEvent(loader, requestEv18);
766
- return loadRouteLoaderByQrl(loader.__id, loader.__qrl, loader.__validators, loader.__blockSSR ? loaderEv : detachResponseFromEvent(loaderEv));
894
+ var loadRouteLoader = (loader9, requestEv18) => {
895
+ const loaderEv = getLoaderRequestEvent(loader9, requestEv18);
896
+ return loadRouteLoaderByQrl(loader9.__id, loader9.__qrl, loader9.__validators, loader9.__blockSSR ? loaderEv : detachResponseFromEvent(loaderEv));
767
897
  };
768
898
  /** Run a loader and wrap the result in a LoaderResponse envelope. Catches redirects/errors. */
769
899
  var getRouteLoaderResponse = async (loaderQrl, validators5, requestEv19) => {
@@ -787,24 +917,24 @@ var getRouteLoaderResponse = async (loaderQrl, validators5, requestEv19) => {
787
917
  * @internal
788
918
  */
789
919
  function routeLoaderQrl(loaderQrl, ...rest) {
790
- const { id, validators: validators6, serializationStrategy, cacheControl, eTag, cacheKey, search, blockSSR: blockSSR3 } = getLoaderOptions(rest);
791
- function loader() {
792
- const signal = ensureRouteLoaderSignal(loader, _resolveContextWithoutSequentialScope(RouteStateContext), _resolveContextWithoutSequentialScope(RouteLoaderCtxContext));
920
+ const { id, validators: validators6, serializationStrategy, cacheControl, eTag: eTag3, cacheKey, search, blockSSR: blockSSR3 } = getLoaderOptions(rest);
921
+ function loader10() {
922
+ const signal = ensureRouteLoaderSignal(loader10, _resolveContextWithoutSequentialScope(RouteStateContext), _resolveContextWithoutSequentialScope(RouteLoaderCtxContext));
793
923
  signal.promise();
794
924
  return signal;
795
925
  }
796
- loader.__brand = "server_loader";
797
- loader.__qrl = loaderQrl;
798
- loader.__validators = validators6;
799
- loader.__id = id ?? loaderQrl.getHash();
800
- loader.__serializationStrategy = serializationStrategy;
801
- loader.__cacheControl = cacheControl;
802
- loader.__eTag = eTag;
803
- loader.__cacheKey = cacheKey;
804
- loader.__search = search;
805
- loader.__blockSSR = blockSSR3;
806
- Object.freeze(loader);
807
- return loader;
926
+ loader10.__brand = "server_loader";
927
+ loader10.__qrl = loaderQrl;
928
+ loader10.__validators = validators6;
929
+ loader10.__id = id ?? loaderQrl.getHash();
930
+ loader10.__serializationStrategy = serializationStrategy;
931
+ loader10.__cacheControl = cacheControl;
932
+ loader10.__eTag = eTag3;
933
+ loader10.__cacheKey = cacheKey;
934
+ loader10.__search = search;
935
+ loader10.__blockSSR = blockSSR3;
936
+ Object.freeze(loader10);
937
+ return loader10;
808
938
  }
809
939
  /**
810
940
  * Define a route loader that fetches data before the route renders.
@@ -1037,7 +1167,7 @@ function getStaticChild(node, partLower) {
1037
1167
  * Priority: exact match → _M groups (recursively) → _W wildcard → _A rest wildcard. This ensures
1038
1168
  * exact matches inside nested groups take precedence over wildcards at parent level.
1039
1169
  */
1040
- function findChild(node, part, partLower, parts, partIndex) {
1170
+ function findChild(node, part, partLower) {
1041
1171
  const exact = getStaticChild(node, partLower);
1042
1172
  if (exact) return {
1043
1173
  next: exact,
@@ -1048,21 +1178,21 @@ function findChild(node, part, partLower, parts, partIndex) {
1048
1178
  };
1049
1179
  if (node._M) for (let j = 0; j < node._M.length; j++) {
1050
1180
  const group = node._M[j];
1051
- const groupResult = findChild(group, part, partLower, parts, partIndex);
1181
+ const groupResult = findChild(group, part, partLower);
1052
1182
  if (groupResult) {
1053
1183
  groupResult.groups.unshift(group);
1054
1184
  return groupResult;
1055
1185
  }
1056
1186
  }
1057
- const wildcard = tryWildcardMatch(node, part, partLower, parts, partIndex);
1187
+ const wildcard = tryWildcardMatch(node, part, partLower);
1058
1188
  if (wildcard) return {
1059
1189
  ...wildcard,
1060
1190
  groups: []
1061
1191
  };
1062
1192
  }
1063
1193
  /** Try to match a segment against a node's wildcard children (_W, _A). */
1064
- function tryWildcardMatch(node, part, partLower, parts, partIndex) {
1065
- return matchWildcardNode(node, part, partLower) ?? matchRestNode(node, parts, partIndex);
1194
+ function tryWildcardMatch(node, part, partLower) {
1195
+ return matchWildcardNode(node, part, partLower) ?? matchRestNode(node);
1066
1196
  }
1067
1197
  /** Try to match a segment against a node's `[param]` wildcard child (`_W`). */
1068
1198
  function matchWildcardNode(node, part, partLower) {
@@ -1099,18 +1229,16 @@ function matchWildcardNode(node, part, partLower) {
1099
1229
  }
1100
1230
  }
1101
1231
  /** Try to match the remaining segments against a node's `[...param]` rest child (`_A`). */
1102
- function matchRestNode(node, parts, partIndex) {
1232
+ function matchRestNode(node) {
1103
1233
  const next = node._A;
1104
1234
  if (next) {
1105
1235
  const paramName = next._P;
1106
- const restValue = parts.slice(partIndex).join("/");
1107
1236
  return {
1108
1237
  next,
1109
1238
  routePart: `[...${paramName}]`,
1110
1239
  done: true,
1111
1240
  kind: ChildMatchKind.Rest,
1112
- paramName,
1113
- paramValue: restValue
1241
+ paramName
1114
1242
  };
1115
1243
  }
1116
1244
  }
@@ -1137,7 +1265,6 @@ function matchRestSpans(node, parts, partIndex) {
1137
1265
  done: false,
1138
1266
  kind: ChildMatchKind.Rest,
1139
1267
  paramName,
1140
- paramValue: parts.slice(partIndex, partIndex + span).join("/"),
1141
1268
  span
1142
1269
  });
1143
1270
  return spans;
@@ -1176,7 +1303,7 @@ function findChildAll(node, part, partLower, parts, partIndex) {
1176
1303
  groups: []
1177
1304
  });
1178
1305
  candidates.push(...matchRestSpans(node, parts, partIndex));
1179
- const rest = matchRestNode(node, parts, partIndex);
1306
+ const rest = matchRestNode(node);
1180
1307
  if (rest) candidates.push({
1181
1308
  ...rest,
1182
1309
  groups: []
@@ -1317,7 +1444,7 @@ function matchRouteTree(root = {}, pathname) {
1317
1444
  while (!done && i < len) {
1318
1445
  const part = parts[i];
1319
1446
  const partLower = part.toLowerCase();
1320
- const found = chain ? chain[chainIndex++] : findChild(node, part, partLower, parts, i);
1447
+ const found = chain ? chain[chainIndex++] : findChild(node, part, partLower);
1321
1448
  if (!found) {
1322
1449
  matched = false;
1323
1450
  break;
@@ -1339,11 +1466,11 @@ function matchRouteTree(root = {}, pathname) {
1339
1466
  notFoundLayouts: notFoundLoaderRef.layouts,
1340
1467
  menuLoader: menuLoaderRef.v
1341
1468
  };
1342
- if (found.paramName) params[found.paramName] = found.paramValue;
1469
+ const span = found.span ?? 1;
1470
+ if (found.paramName) params[found.paramName] = found.paramValue ?? parts.slice(i, found.done ? len : i + span).join("/");
1343
1471
  routeParts.push(found.routePart);
1344
1472
  done = found.done;
1345
1473
  node = found.next;
1346
- const span = found.span ?? 1;
1347
1474
  const matchedParts = encodedParts.slice(0, found.done ? len : i + span);
1348
1475
  const matchedPathname = matchedParts.length ? `/${matchedParts.join("/")}/` : "/";
1349
1476
  collectNodeMeta(node, found.groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef, loaderPathsByHash, matchedPathname, loaderParamsByHash, { ...params });
@@ -1500,39 +1627,6 @@ function collectPageLoaders({ node, loaderPaths, loaderParams }, paths, pathPara
1500
1627
  pathParams[hash] = { ...params };
1501
1628
  }
1502
1629
  }
1503
- /** Gets an absolute url path string (url.pathname + url.search + url.hash) */
1504
- var toPath = (url) => url.pathname + url.search + url.hash;
1505
- /** Create a URL from a string and baseUrl */
1506
- var toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
1507
- /** Checks only if the origins are the same. */
1508
- var isSameOrigin = (a, b) => a.origin === b.origin;
1509
- /** Checks only if the pathnames are the same for the URLs (doesn't include search and hash) */
1510
- var isSamePathname = ({ pathname: a }, { pathname: b }) => {
1511
- const lDiff = Math.abs(a.length - b.length);
1512
- return lDiff === 0 ? a === b : lDiff === 1 && ensureSlash(a) === ensureSlash(b);
1513
- };
1514
- /** Checks only if the search query strings are the same for the URLs */
1515
- var isSameSearchQuery = (a, b) => a.search === b.search;
1516
- /** Checks only if the pathname + search are the same for the URLs. */
1517
- var isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
1518
- var getClientNavPath = (props, baseUrl) => {
1519
- const href = props.href;
1520
- if (typeof href === "string" && typeof props.target !== "string" && !props.reload) try {
1521
- const linkUrl = toUrl(href.trim(), baseUrl.url);
1522
- if (isSameOrigin(linkUrl, toUrl("", baseUrl.url))) return toPath(linkUrl);
1523
- } catch (e) {
1524
- console.error(e);
1525
- }
1526
- else if (props.reload) return toPath(toUrl("", baseUrl.url));
1527
- return null;
1528
- };
1529
- var shouldPreload = (clientNavPath, currentLoc) => {
1530
- if (clientNavPath) return !isSamePathname(toUrl(clientNavPath, currentLoc.url), toUrl("", currentLoc.url));
1531
- return false;
1532
- };
1533
- var isPromise = (value) => {
1534
- return value && typeof value.then === "function";
1535
- };
1536
1630
  /**
1537
1631
  * Resolve the full route config (head + eTag + cacheKey) from all content modules. Uses the same
1538
1632
  * resolution rules as DocumentHead: objects are merged immediately, functions are queued and
@@ -1650,4 +1744,4 @@ var createDocumentHead = (defaults, manifestHash) => ({
1650
1744
  frontmatter: { ...defaults?.frontmatter },
1651
1745
  manifestHash: manifestHash || "dev"
1652
1746
  });
1653
- export { ContentInternalContext as $, isImmutableLoader as A, _getServiceWorkerUrl as B, getModuleRouteLoaders as C, getRouteLoaderResponse as D, getRouteLoaderParams as E, restoreRouteLoaders as F, getRoutes as G, findRouterConfig as H, routeLoader$ as I, RUN_PENDING_ACTION as J, getTrailingSlash as K, routeLoaderQrl as L, matchesRouteLoaderId as M, prepareRouteLoaders as N, getRouteLoaderValues as O, resolveRouteLoaderByHash as P, ContentContext as Q, setLoaderSignalValue as R, getLoaderRequestEvent as S, getRouteLoaderCtx as T, getBasePathname as U, _setRouterConfig as V, getRouterConfig as W, preventNav as X, internalState as Y, registerPreventNav as Z, clearRouteLoaderData as _, isPromise as a, RouteLocationContext as at, fetchRouteLoaderData as b, shouldPreload as c, QACTION_KEY as ct, loadRoute as d, Q_ROUTE as dt, DocumentHeadContext as et, matchRouteTree as f, RequestEvRouterConfig as ft, clearNavFetchCache as g, abortRouteLoaderNavigation as h, getClientNavPath as i, RouteLoaderCtxContext as it, loadRouteLoader as j, getRouteLoaders as k, toPath as l, QDATA_KEY as lt, ROUTE_PATH_HEADER as m, resolveHead as n, RouteActionContext as nt, isSameOrigin as o, RouteNavigateContext as ot, FULLPATH_HEADER as p, _asyncRequestStore as pt, REFRESH_HEAD as q, resolveRouteConfig as r, RouteActionRunnerContext as rt, isSamePath as s, RouteStateContext as st, createDocumentHead as t, HttpStatusContext as tt, toUrl as u, QFN_KEY as ut, commitRouteLoaders as v, getRequestEvent as w, getClientRouteLoaders as x, ensureRouteLoaderSignals as y, setRouteLoaders as z };
1747
+ export { ContentContext as $, routeLoaderQrl as A, toUrl as B, isImmutableLoader as C, resolveRouteLoaderByHash as D, prepareRouteLoaders as E, isSameOrigin as F, getRouterConfig as G, _setRouterConfig as H, isSamePath as I, REFRESH_HEAD as J, getRoutes as K, shouldPreload as L, setRouteLoaders as M, getClientNavPath as N, restoreRouteLoaders as O, isPromise as P, registerPreventNav as Q, toPath as R, getRouteLoaders as S, matchesRouteLoaderId as T, findRouterConfig as U, _getServiceWorkerUrl as V, getBasePathname as W, internalState as X, RUN_PENDING_ACTION as Y, preventNav as Z, getRequestEvent as _, setETagHeader as _t, matchRouteTree as a, RouteLoaderCtxContext as at, getRouteLoaderResponse as b, abortRouteLoaderNavigation as c, RouteStateContext as ct, commitRouteLoaders as d, QFN_KEY as dt, ContentInternalContext as et, ensureRouteLoaderSignals as f, Q_ROUTE as ft, getModuleRouteLoaders as g, resolvePreETag as gt, getLoaderRequestEvent as h, performETagMatch as ht, loadRoute as i, RouteActionRunnerContext as it, setLoaderSignalValue as j, routeLoader$ as k, clearNavFetchCache as l, QACTION_KEY as lt, getClientRouteLoaders as m, normalizeETag as mt, resolveHead as n, HttpStatusContext as nt, FULLPATH_HEADER as o, RouteLocationContext as ot, fetchRouteLoaderData as p, hash as pt, getTrailingSlash as q, resolveRouteConfig as r, RouteActionContext as rt, ROUTE_PATH_HEADER as s, RouteNavigateContext as st, createDocumentHead as t, DocumentHeadContext as tt, clearRouteLoaderData as u, QDATA_KEY as ut, getRouteLoaderCtx as v, RequestEvRouterConfig as vt, loadRouteLoader as w, getRouteLoaderValues as x, getRouteLoaderParams as y, _asyncRequestStore as yt, toSafeRedirectUrl as z };
@@ -1,11 +1,14 @@
1
1
  import { t as ensureSlash } from "./pathname.mjs";
2
2
  var IsQLoader = "@isQLoader";
3
3
  var IsQAction = "@isQAction";
4
+ var IsQRoute = "@isQRoute";
4
5
  var QLoaderId = "@loaderId";
5
6
  var QActionId = "@actionId";
6
7
  /** Matches the final `/q-loader-{loaderId}.{manifestHash}.json` path segment. */
7
8
  var LOADER_REGEX = /\/(q-loader-([^/.]+)\.([^/.]+)\.json)$/;
8
9
  var getLoaderName = (loaderId, manifestHash) => `q-loader-${loaderId}.${manifestHash}.json`;
10
+ /** Matches the final `/q-route.json` path segment: the client asks where a URL really routes to. */
11
+ var ROUTE_REGEX = /\/q-route\.json$/;
9
12
  /**
10
13
  * Recognize internal request types from the URL pathname.
11
14
  *
@@ -23,6 +26,11 @@ function recognizeRequest(pathname) {
23
26
  manifestHash: loaderMatch[3]
24
27
  }
25
28
  };
29
+ if (ROUTE_REGEX.test(pathname)) return {
30
+ type: IsQRoute,
31
+ trimLength: 13,
32
+ data: null
33
+ };
26
34
  return null;
27
35
  }
28
36
  /** Trim a recognized internal URL suffix from a pathname, returning the clean route pathname. */
@@ -50,4 +58,4 @@ function resolveValidInternalFullPathname(loaderPathname, fullPath) {
50
58
  return;
51
59
  }
52
60
  }
53
- export { QLoaderId as a, resolveValidInternalFullPathname as c, QActionId as i, trimInternalPathname as l, IsQLoader as n, getLoaderName as o, LOADER_REGEX as r, recognizeRequest as s, IsQAction as t, trimRecognizedInternalPathname as u };
61
+ export { QActionId as a, recognizeRequest as c, trimRecognizedInternalPathname as d, LOADER_REGEX as i, resolveValidInternalFullPathname as l, IsQLoader as n, QLoaderId as o, IsQRoute as r, getLoaderName as s, IsQAction as t, trimInternalPathname as u };