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

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,10 +1,49 @@
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";
6
- import { SerializerSymbol, _deserialize, _getAsyncLocalStorage, _injectAsyncSignalValue, _markSignalAsExternallyOwned, _qwikSymbol, _registerSingleton, _resolveContextWithoutSequentialScope, _verifySerializable } from "@qwik.dev/core/internal";
6
+ import { SerializerSymbol, _deserialize, _getAsyncLocalStorage, _getContextContainer, _injectAsyncSignalValue, _invoke, _qwikSymbol, _registerSingleton, _resolveContextWithoutSequentialScope, _verifySerializable } from "@qwik.dev/core/internal";
7
7
  import { isServer as isServer$1 } from "@qwik.dev/core/build";
8
+ /** Gets an absolute url path string (url.pathname + url.search + url.hash) */
9
+ var toPath = (url) => url.pathname + url.search + url.hash;
10
+ /** Create a URL from a string and baseUrl */
11
+ var toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
12
+ /** Resolves a redirect without allowing executable URL schemes. */
13
+ var toSafeRedirectUrl = (url, baseUrl) => {
14
+ const redirectUrl = toUrl(url, baseUrl);
15
+ if (redirectUrl.protocol !== "http:" && redirectUrl.protocol !== "https:") throw new Error(`Unsupported redirect protocol: ${redirectUrl.protocol}`);
16
+ return redirectUrl;
17
+ };
18
+ /** Checks only if the origins are the same. */
19
+ var isSameOrigin = (a, b) => a.origin === b.origin;
20
+ /** Checks only if the pathnames are the same for the URLs (doesn't include search and hash) */
21
+ var isSamePathname = ({ pathname: a }, { pathname: b }) => {
22
+ const lDiff = Math.abs(a.length - b.length);
23
+ return lDiff === 0 ? a === b : lDiff === 1 && ensureSlash(a) === ensureSlash(b);
24
+ };
25
+ /** Checks only if the search query strings are the same for the URLs */
26
+ var isSameSearchQuery = (a, b) => a.search === b.search;
27
+ /** Checks only if the pathname + search are the same for the URLs. */
28
+ var isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
29
+ var getClientNavPath = (props, baseUrl) => {
30
+ const href = props.href;
31
+ if (typeof href === "string" && typeof props.target !== "string" && !props.reload) try {
32
+ const linkUrl = toUrl(href.trim(), baseUrl.url);
33
+ if (isSameOrigin(linkUrl, toUrl("", baseUrl.url))) return toPath(linkUrl);
34
+ } catch (e) {
35
+ console.error(e);
36
+ }
37
+ else if (props.reload) return toPath(toUrl("", baseUrl.url));
38
+ return null;
39
+ };
40
+ var shouldPreload = (clientNavPath, currentLoc) => {
41
+ if (clientNavPath) return !isSamePathname(toUrl(clientNavPath, currentLoc.url), toUrl("", currentLoc.url));
42
+ return false;
43
+ };
44
+ var isPromise = (value) => {
45
+ return value && typeof value.then === "function";
46
+ };
8
47
  var createRequestStore = () => {
9
48
  const AsyncLocalStorage = _getAsyncLocalStorage();
10
49
  if (AsyncLocalStorage) return new AsyncLocalStorage();
@@ -21,13 +60,73 @@ var _asyncRequestStore = isServer$1 ? _registerSingleton("routerRequestStore", c
21
60
  var RequestEvRouterConfig = /*#__PURE__*/ _qwikSymbol("router.config");
22
61
  /** The config of the app serving the current request, for a router copy that holds none. */
23
62
  var getServingRouterConfig = () => _asyncRequestStore?.getStore()?.[RequestEvRouterConfig];
63
+ /**
64
+ * FNV-1a 32-bit hash for generating eTags from response data. Cheap to compute, sufficient
65
+ * collision resistance for cache validation (not cryptographic).
66
+ */
67
+ function hash(str) {
68
+ let hash = 2166136261;
69
+ for (let i = 0; i < str.length; i++) {
70
+ hash ^= str.charCodeAt(i);
71
+ hash = hash * 16777619 | 0;
72
+ }
73
+ return (hash >>> 0).toString(36);
74
+ }
75
+ /**
76
+ * Normalize an ETag header value (or a single `If-None-Match` entry) into a canonical form so byte
77
+ * equality compares the same logical tag. Strips weak ETag syntax (`W/"..."`), quotes, and any
78
+ * character outside RFC 7232's `etagc` grammar (printable ASCII except DQUOTE — no escape mechanism
79
+ * exists, and non-ASCII bytes are mangled by many HTTP stacks even though `obs-text` technically
80
+ * permits them). Idempotent.
81
+ */
82
+ function normalizeETag(raw) {
83
+ let tag = raw.trim();
84
+ if (tag.endsWith("\"") && tag.startsWith("W/\"")) tag = tag.slice(3);
85
+ tag = tag.replace(/[^!#-~]/g, "");
86
+ return tag;
87
+ }
88
+ function setETagHeader(requestEv, normalizedETag) {
89
+ const headerETag = `"${normalizedETag}"`;
90
+ requestEv.headers.set("ETag", headerETag);
91
+ }
92
+ /**
93
+ * Set the strong ETag header on the response and check the request's `If-None-Match` against it.
94
+ * The eTag argument must already be normalized. Returns true if a 304 was sent (caller should stop
95
+ * processing).
96
+ */
97
+ function performETagMatch(requestEv, normalizedETag, beforeNotModified) {
98
+ setETagHeader(requestEv, normalizedETag);
99
+ const ifNoneMatch = requestEv.request.headers.get("If-None-Match");
100
+ if (ifNoneMatch) {
101
+ let found = ifNoneMatch.trim() === "*";
102
+ if (!found) {
103
+ for (const entry of ifNoneMatch.split(",")) if (normalizeETag(entry) === normalizedETag) {
104
+ found = true;
105
+ break;
106
+ }
107
+ }
108
+ if (found) {
109
+ beforeNotModified?.();
110
+ requestEv.status(304);
111
+ requestEv.send(304, "");
112
+ return true;
113
+ }
114
+ }
115
+ return false;
116
+ }
117
+ /** Resolve eTag from a static string or function (before running the loader). */
118
+ function resolvePreETag(eTagOption, requestEv) {
119
+ if (typeof eTagOption === "string") return normalizeETag(eTagOption);
120
+ const result = eTagOption(requestEv);
121
+ return result ? normalizeETag(result) : "";
122
+ }
24
123
  var QACTION_KEY = "qaction";
25
124
  var QFN_KEY = "qfunc";
26
125
  var QDATA_KEY = "qdata";
27
126
  /** @public */
28
127
  var Q_ROUTE = "q:route";
29
128
  function DEFAULT_LOADERS_SERIALIZATION_STRATEGY() {
30
- return globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__ || "never";
129
+ return globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__ || "auto";
31
130
  }
32
131
  var RouteStateContext = /*#__PURE__*/ createContextId("qr-s");
33
132
  var RouteLoaderCtxContext = /*#__PURE__*/ createContextId("qr-lc");
@@ -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;
319
- const signal = createComputedQrl(/*#__PURE__*/ inlinedQrl(async (ctx) => {
423
+ var createRouteLoaderSignal = (loader2, routeLoaderCtx, state, requestEv3, container) => {
424
+ const id = loader2.__id;
425
+ const capture = isServer ? new ServerRouteLoaderCapture(id, loader2.__qrl, loader2.__validators, loader2.__blockSSR, loader2, requestEv3) : id;
426
+ const searchFilter = loader2.__search;
427
+ const loaderHash = isDev ? loader2.__qrl.getHash() : id;
428
+ return 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,9 +499,10 @@ var createRouteLoaderSignal = (loader, routeLoaderCtx, state, requestEv3) => {
369
499
  routeLoaderCtx,
370
500
  searchFilter,
371
501
  state
372
- ]), { serializationStrategy: loader.__serializationStrategy });
373
- _markSignalAsExternallyOwned(signal);
374
- return signal;
502
+ ]), {
503
+ serializationStrategy: loader2.__serializationStrategy,
504
+ container
505
+ });
375
506
  };
376
507
  /** Build a sorted, stable search string from only the allowed param names. */
377
508
  var filterSearchParams = (params, allowed) => {
@@ -388,7 +519,7 @@ function getLoaderOptions(rest) {
388
519
  let id;
389
520
  let serializationStrategy = DEFAULT_LOADERS_SERIALIZATION_STRATEGY();
390
521
  let cacheControl;
391
- let eTag;
522
+ let eTag2;
392
523
  let cacheKey;
393
524
  let search;
394
525
  let blockSSR2 = true;
@@ -402,7 +533,7 @@ function getLoaderOptions(rest) {
402
533
  if (options.serializationStrategy) serializationStrategy = options.serializationStrategy;
403
534
  if (options.validation) validators2.push(...options.validation);
404
535
  if ("cacheControl" in options) cacheControl = options.cacheControl;
405
- if ("eTag" in options) eTag = options.eTag;
536
+ if ("eTag" in options) eTag2 = options.eTag;
406
537
  if ("cacheKey" in options) cacheKey = options.cacheKey;
407
538
  if (options.search) search = options.search;
408
539
  else if (globalThis.__STRICT_LOADERS__) search = [];
@@ -418,7 +549,7 @@ function getLoaderOptions(rest) {
418
549
  validators: validators2.reverse(),
419
550
  serializationStrategy,
420
551
  cacheControl,
421
- eTag,
552
+ eTag: eTag2,
422
553
  cacheKey,
423
554
  search,
424
555
  blockSSR: blockSSR2
@@ -517,17 +648,19 @@ var isImmutableLoader = (loaderId) => immutableLoaderIds.has(loaderId);
517
648
  function abortRouteLoaderNavigation(ctx) {
518
649
  for (const [signal, request] of clientRouteLoaders.get(ctx)?.current.requests ?? []) {
519
650
  if (signal.untrackedPending) request.isAborted = true;
520
- signal.abort();
651
+ if (!request.redirect) signal.abort();
521
652
  }
522
653
  }
523
654
  /** Search-filtered loaders ignore changes to unlisted params. */
524
655
  function hasSameListedSearch(previous, next, search) {
525
656
  return !!search && previous.pathname === next.pathname && filterSearchParams(previous.searchParams, search) === filterSearchParams(next.searchParams, search);
526
657
  }
527
- function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navCount, forceIds, navigationKey) {
658
+ function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navCount, forceIds, navigationKey, forceReload) {
528
659
  const client = getClientRouteLoaders(ctx, previousUrl.href);
529
660
  if (navigationKey && client.navigationKey === navigationKey) return ensureRouteLoaderSignals(mods, state, ctx);
530
661
  const previous = client.current;
662
+ const previousPageUrl = new URL(previous.pageUrl);
663
+ const reloadsCurrentPage = previousPageUrl.origin === pageUrl.origin && previousPageUrl.pathname === pageUrl.pathname && previousPageUrl.search === pageUrl.search;
531
664
  if (client.navCount === void 0) for (const id in state) getLoaderRequest(ctx, state, id, id);
532
665
  client.navCount = navCount;
533
666
  client.navigationKey = navigationKey;
@@ -538,15 +671,15 @@ function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navC
538
671
  };
539
672
  const loaders = ensureRouteLoaderSignals(mods, state, ctx);
540
673
  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;
674
+ for (const loader3 of loaders) {
675
+ routeLoaders.set(loader3.__id, loader3);
676
+ current.paths[loader3.__id] ||= current.paths[loader3.__qrl.getHash()] || pageUrl.pathname;
544
677
  }
545
678
  for (const id in state) {
546
679
  const signal = state[id];
547
680
  const old = previous.requests.get(signal);
548
- const loader = routeLoaders.get(id);
549
- const hash3 = loader?.__qrl.getHash() || old?.hash;
681
+ const loader4 = routeLoaders.get(id);
682
+ const hash3 = loader4?.__qrl.getHash() || old?.hash;
550
683
  const routePath = current.paths[id] || hash3 && current.paths[hash3];
551
684
  if (!routePath) {
552
685
  if (old) current.requests.set(signal, {
@@ -556,7 +689,7 @@ function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navC
556
689
  signal.abort();
557
690
  continue;
558
691
  }
559
- const keepRequest = old?.active && !old.isAborted && old.routePath === routePath && (old.pageUrl === pageUrl.href ? isImmutableLoader(id) : hasSameListedSearch(new URL(old.pageUrl), pageUrl, loader?.__search));
692
+ const keepRequest = old?.active && !old.isAborted && old.routePath === routePath && (reloadsCurrentPage ? isImmutableLoader(id) : !forceReload && hasSameListedSearch(new URL(old.pageUrl), pageUrl, loader4?.__search));
560
693
  current.requests.set(signal, keepRequest ? old : {
561
694
  routePath,
562
695
  pageUrl: pageUrl.href,
@@ -598,9 +731,14 @@ function restoreRouteLoaders(state, ctx, navCount) {
598
731
  pruneRouteLoaders(state, ctx);
599
732
  for (const signal of client.current.requests.keys()) signal.invalidate();
600
733
  }
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);
734
+ var ensureRouteLoaderSignal = (loader5, state, routeLoaderCtx, requestEv12) => {
735
+ if (loader5.__cacheControl === "immutable") immutableLoaderIds.add(loader5.__id);
736
+ const id = loader5.__id;
737
+ if (!state[id]) {
738
+ const ev = requestEv12 ?? (isServer ? useServerData("qwikrouter")?.ev : void 0);
739
+ state[id] = _invoke(void 0, createRouteLoaderSignal, loader5, routeLoaderCtx, state, ev, _getContextContainer());
740
+ }
741
+ return state[id];
604
742
  };
605
743
  var ensureRouteLoaderSignals = (mods, state, routeLoaderCtx, requestEv13) => {
606
744
  const loaders = getModuleRouteLoaders(mods);
@@ -618,10 +756,10 @@ var setLoaderSignalValue = (signal, value) => {
618
756
  _injectAsyncSignalValue(signal, value);
619
757
  };
620
758
  var resolveRouteLoaderByHash = (routeLoaders, loaderId) => {
621
- return routeLoaders.find((loader) => matchesRouteLoaderId(loader, loaderId));
759
+ return routeLoaders.find((loader6) => matchesRouteLoaderId(loader6, loaderId));
622
760
  };
623
- var matchesRouteLoaderId = (loader, loaderId) => {
624
- return typeof loaderId === "string" && (loader.__id === loaderId || isDev && loader.__qrl.getHash() === loaderId);
761
+ var matchesRouteLoaderId = (loader7, loaderId) => {
762
+ return typeof loaderId === "string" && (loader7.__id === loaderId || isDev && loader7.__qrl.getHash() === loaderId);
625
763
  };
626
764
  /** Run a loader and return its raw value. Errors/redirects propagate as exceptions. */
627
765
  var getRouteLoaderData = async (loaderQrl, validators3, requestEv14) => {
@@ -652,24 +790,24 @@ var loadRouteLoaderByQrl = (loaderId, loaderQrl, validators4, requestEv15) => {
652
790
  return promise;
653
791
  };
654
792
  /** @internal */
655
- var getLoaderRequestEvent = (loader, requestEv16) => {
793
+ var getLoaderRequestEvent = (loader8, requestEv16) => {
656
794
  let rootRequestEv = requestEv16.sharedMap.get(REQUEST_ROUTE_LOADER_ROOT_EVENT);
657
795
  if (!rootRequestEv) {
658
796
  rootRequestEv = requestEv16;
659
797
  requestEv16.sharedMap.set(REQUEST_ROUTE_LOADER_ROOT_EVENT, rootRequestEv);
660
798
  }
661
799
  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;
800
+ const pathname = globalThis.__STRICT_LOADERS__ ? getRouteLoaderCtx(rootRequestEv).loaderPaths[loader8.__id] || rootRequestEv.url.pathname : rootRequestEv.url.pathname;
801
+ const filteredSearch = loader8.__search ? filterSearchParams(url.searchParams, loader8.__search) : rootRequestEv.url.search;
664
802
  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;
803
+ const params = globalThis.__STRICT_LOADERS__ ? getRouteLoaderParams(rootRequestEv)[loader8.__id] ?? (pathname === rootRequestEv.url.pathname ? rootRequestEv.params : {}) : rootRequestEv.params;
666
804
  if (isSameUrl && params === rootRequestEv.params) return rootRequestEv;
667
805
  let events = rootRequestEv.sharedMap.get(REQUEST_ROUTE_LOADER_EVENTS);
668
806
  if (!events) {
669
807
  events = /* @__PURE__ */ new Map();
670
808
  rootRequestEv.sharedMap.set(REQUEST_ROUTE_LOADER_EVENTS, events);
671
809
  }
672
- const eventKey = `${pathname}\n${filteredSearch}\n${params === rootRequestEv.params ? "" : loader.__id}`;
810
+ const eventKey = `${pathname}\n${filteredSearch}\n${params === rootRequestEv.params ? "" : loader8.__id}`;
673
811
  let loaderRequestEv = events.get(eventKey);
674
812
  if (!loaderRequestEv) {
675
813
  url.pathname = pathname;
@@ -761,9 +899,9 @@ var detachResponseFromEvent = (requestEv17) => {
761
899
  }
762
900
  });
763
901
  };
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));
902
+ var loadRouteLoader = (loader9, requestEv18) => {
903
+ const loaderEv = getLoaderRequestEvent(loader9, requestEv18);
904
+ return loadRouteLoaderByQrl(loader9.__id, loader9.__qrl, loader9.__validators, loader9.__blockSSR ? loaderEv : detachResponseFromEvent(loaderEv));
767
905
  };
768
906
  /** Run a loader and wrap the result in a LoaderResponse envelope. Catches redirects/errors. */
769
907
  var getRouteLoaderResponse = async (loaderQrl, validators5, requestEv19) => {
@@ -787,24 +925,24 @@ var getRouteLoaderResponse = async (loaderQrl, validators5, requestEv19) => {
787
925
  * @internal
788
926
  */
789
927
  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));
928
+ const { id, validators: validators6, serializationStrategy, cacheControl, eTag: eTag3, cacheKey, search, blockSSR: blockSSR3 } = getLoaderOptions(rest);
929
+ function loader10() {
930
+ const signal = ensureRouteLoaderSignal(loader10, _resolveContextWithoutSequentialScope(RouteStateContext), _resolveContextWithoutSequentialScope(RouteLoaderCtxContext));
793
931
  signal.promise();
794
932
  return signal;
795
933
  }
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;
934
+ loader10.__brand = "server_loader";
935
+ loader10.__qrl = loaderQrl;
936
+ loader10.__validators = validators6;
937
+ loader10.__id = id ?? loaderQrl.getHash();
938
+ loader10.__serializationStrategy = serializationStrategy;
939
+ loader10.__cacheControl = cacheControl;
940
+ loader10.__eTag = eTag3;
941
+ loader10.__cacheKey = cacheKey;
942
+ loader10.__search = search;
943
+ loader10.__blockSSR = blockSSR3;
944
+ Object.freeze(loader10);
945
+ return loader10;
808
946
  }
809
947
  /**
810
948
  * Define a route loader that fetches data before the route renders.
@@ -1037,7 +1175,7 @@ function getStaticChild(node, partLower) {
1037
1175
  * Priority: exact match → _M groups (recursively) → _W wildcard → _A rest wildcard. This ensures
1038
1176
  * exact matches inside nested groups take precedence over wildcards at parent level.
1039
1177
  */
1040
- function findChild(node, part, partLower, parts, partIndex) {
1178
+ function findChild(node, part, partLower) {
1041
1179
  const exact = getStaticChild(node, partLower);
1042
1180
  if (exact) return {
1043
1181
  next: exact,
@@ -1048,21 +1186,21 @@ function findChild(node, part, partLower, parts, partIndex) {
1048
1186
  };
1049
1187
  if (node._M) for (let j = 0; j < node._M.length; j++) {
1050
1188
  const group = node._M[j];
1051
- const groupResult = findChild(group, part, partLower, parts, partIndex);
1189
+ const groupResult = findChild(group, part, partLower);
1052
1190
  if (groupResult) {
1053
1191
  groupResult.groups.unshift(group);
1054
1192
  return groupResult;
1055
1193
  }
1056
1194
  }
1057
- const wildcard = tryWildcardMatch(node, part, partLower, parts, partIndex);
1195
+ const wildcard = tryWildcardMatch(node, part, partLower);
1058
1196
  if (wildcard) return {
1059
1197
  ...wildcard,
1060
1198
  groups: []
1061
1199
  };
1062
1200
  }
1063
1201
  /** 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);
1202
+ function tryWildcardMatch(node, part, partLower) {
1203
+ return matchWildcardNode(node, part, partLower) ?? matchRestNode(node);
1066
1204
  }
1067
1205
  /** Try to match a segment against a node's `[param]` wildcard child (`_W`). */
1068
1206
  function matchWildcardNode(node, part, partLower) {
@@ -1099,18 +1237,16 @@ function matchWildcardNode(node, part, partLower) {
1099
1237
  }
1100
1238
  }
1101
1239
  /** Try to match the remaining segments against a node's `[...param]` rest child (`_A`). */
1102
- function matchRestNode(node, parts, partIndex) {
1240
+ function matchRestNode(node) {
1103
1241
  const next = node._A;
1104
1242
  if (next) {
1105
1243
  const paramName = next._P;
1106
- const restValue = parts.slice(partIndex).join("/");
1107
1244
  return {
1108
1245
  next,
1109
1246
  routePart: `[...${paramName}]`,
1110
1247
  done: true,
1111
1248
  kind: ChildMatchKind.Rest,
1112
- paramName,
1113
- paramValue: restValue
1249
+ paramName
1114
1250
  };
1115
1251
  }
1116
1252
  }
@@ -1137,7 +1273,6 @@ function matchRestSpans(node, parts, partIndex) {
1137
1273
  done: false,
1138
1274
  kind: ChildMatchKind.Rest,
1139
1275
  paramName,
1140
- paramValue: parts.slice(partIndex, partIndex + span).join("/"),
1141
1276
  span
1142
1277
  });
1143
1278
  return spans;
@@ -1176,7 +1311,7 @@ function findChildAll(node, part, partLower, parts, partIndex) {
1176
1311
  groups: []
1177
1312
  });
1178
1313
  candidates.push(...matchRestSpans(node, parts, partIndex));
1179
- const rest = matchRestNode(node, parts, partIndex);
1314
+ const rest = matchRestNode(node);
1180
1315
  if (rest) candidates.push({
1181
1316
  ...rest,
1182
1317
  groups: []
@@ -1317,7 +1452,7 @@ function matchRouteTree(root = {}, pathname) {
1317
1452
  while (!done && i < len) {
1318
1453
  const part = parts[i];
1319
1454
  const partLower = part.toLowerCase();
1320
- const found = chain ? chain[chainIndex++] : findChild(node, part, partLower, parts, i);
1455
+ const found = chain ? chain[chainIndex++] : findChild(node, part, partLower);
1321
1456
  if (!found) {
1322
1457
  matched = false;
1323
1458
  break;
@@ -1339,11 +1474,11 @@ function matchRouteTree(root = {}, pathname) {
1339
1474
  notFoundLayouts: notFoundLoaderRef.layouts,
1340
1475
  menuLoader: menuLoaderRef.v
1341
1476
  };
1342
- if (found.paramName) params[found.paramName] = found.paramValue;
1477
+ const span = found.span ?? 1;
1478
+ if (found.paramName) params[found.paramName] = found.paramValue ?? parts.slice(i, found.done ? len : i + span).join("/");
1343
1479
  routeParts.push(found.routePart);
1344
1480
  done = found.done;
1345
1481
  node = found.next;
1346
- const span = found.span ?? 1;
1347
1482
  const matchedParts = encodedParts.slice(0, found.done ? len : i + span);
1348
1483
  const matchedPathname = matchedParts.length ? `/${matchedParts.join("/")}/` : "/";
1349
1484
  collectNodeMeta(node, found.groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef, loaderPathsByHash, matchedPathname, loaderParamsByHash, { ...params });
@@ -1500,38 +1635,19 @@ function collectPageLoaders({ node, loaderPaths, loaderParams }, paths, pathPara
1500
1635
  pathParams[hash] = { ...params };
1501
1636
  }
1502
1637
  }
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);
1638
+ var getLayoutKeys = (loaders) => {
1639
+ const layoutKeys = [];
1640
+ for (const loader of loaders) {
1641
+ const layoutKey = loader._K;
1642
+ if (layoutKey) layoutKeys.push(layoutKey);
1525
1643
  }
1526
- else if (props.reload) return toPath(toUrl("", baseUrl.url));
1527
- return null;
1644
+ return layoutKeys;
1528
1645
  };
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";
1646
+ var getNewLayoutKeys = (currentLayoutKeys, destLayoutKeys) => {
1647
+ if (!currentLayoutKeys) return destLayoutKeys;
1648
+ let sharedCount = 0;
1649
+ while (sharedCount < destLayoutKeys.length && destLayoutKeys[sharedCount] === currentLayoutKeys[sharedCount]) sharedCount++;
1650
+ return destLayoutKeys.slice(sharedCount);
1535
1651
  };
1536
1652
  /**
1537
1653
  * Resolve the full route config (head + eTag + cacheKey) from all content modules. Uses the same
@@ -1650,4 +1766,4 @@ var createDocumentHead = (defaults, manifestHash) => ({
1650
1766
  frontmatter: { ...defaults?.frontmatter },
1651
1767
  manifestHash: manifestHash || "dev"
1652
1768
  });
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 };
1769
+ export { RouteLoaderCtxContext as $, restoreRouteLoaders as A, getRoutes as B, getRouteLoaderValues as C, matchesRouteLoaderId as D, loadRouteLoader as E, _getServiceWorkerUrl as F, preventNav as G, REFRESH_HEAD as H, _setRouterConfig as I, ContentInternalContext as J, registerPreventNav as K, findRouterConfig as L, routeLoaderQrl as M, setLoaderSignalValue as N, prepareRouteLoaders as O, setRouteLoaders as P, RouteActionRunnerContext as Q, getBasePathname as R, getRouteLoaderResponse as S, isImmutableLoader as T, RUN_PENDING_ACTION as U, getTrailingSlash as V, internalState as W, HttpStatusContext as X, DocumentHeadContext as Y, RouteActionContext as Z, getLoaderRequestEvent as _, isSamePath as _t, getNewLayoutKeys as a, QFN_KEY as at, getRouteLoaderCtx as b, toSafeRedirectUrl as bt, FULLPATH_HEADER as c, normalizeETag as ct, clearNavFetchCache as d, setETagHeader as dt, RouteLocationContext as et, clearRouteLoaderData as f, RequestEvRouterConfig as ft, getClientRouteLoaders as g, isSameOrigin as gt, fetchRouteLoaderData as h, isPromise as ht, getLayoutKeys as i, QDATA_KEY as it, routeLoader$ as j, resolveRouteLoaderByHash as k, ROUTE_PATH_HEADER as l, performETagMatch as lt, ensureRouteLoaderSignals as m, getClientNavPath as mt, resolveHead as n, RouteStateContext as nt, loadRoute as o, Q_ROUTE as ot, commitRouteLoaders as p, _asyncRequestStore as pt, ContentContext as q, resolveRouteConfig as r, QACTION_KEY as rt, matchRouteTree as s, hash as st, createDocumentHead as t, RouteNavigateContext as tt, abortRouteLoaderNavigation as u, resolvePreETag as ut, getModuleRouteLoaders as v, shouldPreload as vt, getRouteLoaders as w, getRouteLoaderParams as x, toUrl as xt, getRequestEvent as y, toPath as yt, getRouterConfig as z };
@@ -28,6 +28,7 @@ function getPathnameForDynamicRoute(originalPathname, paramNames, params) {
28
28
  const paramKey = `[${paramName}]`;
29
29
  const restParamKey = `[...${paramName}]`;
30
30
  const paramValue = params[paramName];
31
+ if (paramValue === "") pathname = pathname.replace(`/${restParamKey}/`, "/");
31
32
  pathname = pathname.replace(restParamKey, paramValue);
32
33
  pathname = pathname.replace(paramKey, paramValue);
33
34
  }
@@ -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 };