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

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.
@@ -304,6 +304,13 @@ var fetchRouteLoaderData = async (loaderId, routePath, manifestHash, opts) => {
304
304
  cache.set(cacheKey, promise);
305
305
  return promise;
306
306
  };
307
+ var retainLoaderValue = (previous, abortSignal) => {
308
+ if (previous !== void 0) return previous;
309
+ return new Promise((_, reject) => {
310
+ abortSignal.throwIfAborted();
311
+ abortSignal.addEventListener("abort", () => reject(abortSignal.reason), { once: true });
312
+ });
313
+ };
307
314
  var createRouteLoaderSignal = (loader, routeLoaderCtx, state, requestEv3) => {
308
315
  const id = loader.__id;
309
316
  const capture = isServer ? new ServerRouteLoaderCapture(id, loader.__qrl, loader.__validators, loader.__blockSSR, requestEv3 ?? useServerData("qwikrouter")?.ev) : id;
@@ -318,13 +325,7 @@ var createRouteLoaderSignal = (loader, routeLoaderCtx, state, requestEv3) => {
318
325
  }
319
326
  if (isServer) return capture.load();
320
327
  const request = getLoaderRequest(routeLoaderCtx, state, id, loaderHash);
321
- if (!request.active) {
322
- if (ctx.previous === void 0) return new Promise((_, reject) => {
323
- ctx.abortSignal.throwIfAborted();
324
- ctx.abortSignal.addEventListener("abort", () => reject(ctx.abortSignal.reason), { once: true });
325
- });
326
- return ctx.previous;
327
- }
328
+ if (!request.active) return retainLoaderValue(ctx.previous, ctx.abortSignal);
328
329
  const pageUrl = new URL(request.pageUrl);
329
330
  const mHash = untrack(() => routeLoaderCtx.manifestHash) || "dev";
330
331
  const basePath = getBasePathname();
@@ -353,7 +354,7 @@ var createRouteLoaderSignal = (loader, routeLoaderCtx, state, requestEv3) => {
353
354
  const goto = routeLoaderCtx.goto;
354
355
  if (goto) goto(response.r, { replaceState: true });
355
356
  else location.href = response.r;
356
- return ctx.previous;
357
+ return retainLoaderValue(ctx.previous, ctx.abortSignal);
357
358
  }
358
359
  if (response.e) throw response.e;
359
360
  lastFetch.raw = result.raw;
@@ -660,22 +661,27 @@ var getLoaderRequestEvent = (loader, requestEv16) => {
660
661
  const url = new URL(rootRequestEv.url);
661
662
  const pathname = globalThis.__STRICT_LOADERS__ ? getRouteLoaderCtx(rootRequestEv).loaderPaths[loader.__id] || rootRequestEv.url.pathname : rootRequestEv.url.pathname;
662
663
  const filteredSearch = loader.__search ? filterSearchParams(url.searchParams, loader.__search) : rootRequestEv.url.search;
663
- if (pathname === rootRequestEv.url.pathname && filteredSearch === rootRequestEv.url.search) return rootRequestEv;
664
- const params = pathname === rootRequestEv.url.pathname ? rootRequestEv.params : getRouteLoaderParams(rootRequestEv)[loader.__id] || {};
664
+ 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;
666
+ if (isSameUrl && params === rootRequestEv.params) return rootRequestEv;
665
667
  let events = rootRequestEv.sharedMap.get(REQUEST_ROUTE_LOADER_EVENTS);
666
668
  if (!events) {
667
669
  events = /* @__PURE__ */ new Map();
668
670
  rootRequestEv.sharedMap.set(REQUEST_ROUTE_LOADER_EVENTS, events);
669
671
  }
670
- const eventKey = `${pathname}\n${filteredSearch}`;
672
+ const eventKey = `${pathname}\n${filteredSearch}\n${params === rootRequestEv.params ? "" : loader.__id}`;
671
673
  let loaderRequestEv = events.get(eventKey);
672
674
  if (!loaderRequestEv) {
673
675
  url.pathname = pathname;
674
676
  url.search = filteredSearch;
675
- const request = new Request(url, rootRequestEv.request);
677
+ const request = new Request(url, {
678
+ method: rootRequestEv.request.method,
679
+ headers: rootRequestEv.request.headers,
680
+ signal: rootRequestEv.request.signal
681
+ });
676
682
  loaderRequestEv = Object.create(rootRequestEv, {
677
683
  originalUrl: {
678
- value: new URL(url),
684
+ value: isSameUrl ? rootRequestEv.originalUrl : new URL(url),
679
685
  enumerable: true
680
686
  },
681
687
  params: {
@@ -864,6 +870,18 @@ var deepFreeze = (obj) => {
864
870
  var MODULE_CACHE = /*#__PURE__*/ new WeakMap();
865
871
  var loadRoute = async (routes, cacheModules, pathname) => {
866
872
  const { loaders, params, routeParts, notFound, routeBundleNames, loaderPathsByHash, loaderParamsByHash, menuLoader, errorLoader } = matchRouteTree(routes, pathname);
873
+ const loaderEndpoints = /* @__PURE__ */ new Map();
874
+ const pagePath = ensureSlash(pathname);
875
+ for (const hash in loaderPathsByHash) {
876
+ const loaderPath = loaderPathsByHash[hash];
877
+ if (loaderPath === pagePath) continue;
878
+ let endpoint = loaderEndpoints.get(loaderPath);
879
+ if (!endpoint) {
880
+ endpoint = matchRouteTree(routes, loaderPath);
881
+ loaderEndpoints.set(loaderPath, endpoint);
882
+ }
883
+ if (!endpoint.notFound && !endpoint.loaderPathsByHash?.[hash]) loaderPathsByHash[hash] = pagePath;
884
+ }
867
885
  const routeName = "/" + routeParts.join("/");
868
886
  const modules = new Array(loaders.length);
869
887
  const pendingLoads = [];
@@ -1289,7 +1307,8 @@ function matchRouteTree(root = {}, pathname) {
1289
1307
  });
1290
1308
  let done = false;
1291
1309
  let matched = true;
1292
- const parts = pathname.split("/").filter((p) => p.length > 0).map(decodeURIComponent);
1310
+ const encodedParts = pathname.split("/").filter((p) => p.length > 0);
1311
+ const parts = encodedParts.map(decodeURIComponent);
1293
1312
  let restFallback;
1294
1313
  let i = 0;
1295
1314
  const len = parts.length;
@@ -1325,7 +1344,7 @@ function matchRouteTree(root = {}, pathname) {
1325
1344
  done = found.done;
1326
1345
  node = found.next;
1327
1346
  const span = found.span ?? 1;
1328
- const matchedParts = parts.slice(0, found.done ? len : i + span);
1347
+ const matchedParts = encodedParts.slice(0, found.done ? len : i + span);
1329
1348
  const matchedPathname = matchedParts.length ? `/${matchedParts.join("/")}/` : "/";
1330
1349
  collectNodeMeta(node, found.groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef, loaderPathsByHash, matchedPathname, loaderParamsByHash, { ...params });
1331
1350
  if (node._M) groupNodes.push({
@@ -1631,4 +1650,4 @@ var createDocumentHead = (defaults, manifestHash) => ({
1631
1650
  frontmatter: { ...defaults?.frontmatter },
1632
1651
  manifestHash: manifestHash || "dev"
1633
1652
  });
1634
- export { HttpStatusContext as $, loadRouteLoader as A, _setRouterConfig as B, getRequestEvent as C, getRouteLoaderValues as D, getRouteLoaderResponse as E, routeLoader$ as F, REFRESH_HEAD as G, getRouterConfig as H, routeLoaderQrl as I, preventNav as J, RUN_PENDING_ACTION as K, setLoaderSignalValue as L, prepareRouteLoaders as M, resolveRouteLoaderByHash as N, getRouteLoaders as O, restoreRouteLoaders as P, DocumentHeadContext as Q, setRouteLoaders as R, getModuleRouteLoaders as S, getRouteLoaderParams as T, getRoutes as U, getBasePathname as V, getTrailingSlash as W, ContentContext as X, registerPreventNav as Y, ContentInternalContext as Z, commitRouteLoaders as _, isPromise as a, RouteStateContext as at, getClientRouteLoaders as b, shouldPreload as c, QFN_KEY as ct, loadRoute as d, _asyncRequestStore as dt, RouteActionContext as et, FULLPATH_HEADER as f, clearRouteLoaderData as g, clearNavFetchCache as h, getClientNavPath as i, RouteNavigateContext as it, matchesRouteLoaderId as j, isImmutableLoader as k, toPath as l, Q_ROUTE as lt, abortRouteLoaderNavigation as m, resolveHead as n, RouteLoaderCtxContext as nt, isSameOrigin as o, QACTION_KEY as ot, ROUTE_PATH_HEADER as p, internalState as q, resolveRouteConfig as r, RouteLocationContext as rt, isSamePath as s, QDATA_KEY as st, createDocumentHead as t, RouteActionRunnerContext as tt, toUrl as u, RequestEvRouterConfig as ut, ensureRouteLoaderSignals as v, getRouteLoaderCtx as w, getLoaderRequestEvent as x, fetchRouteLoaderData as y, _getServiceWorkerUrl as z };
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 };
@@ -1,5 +1,5 @@
1
1
  import { t as ensureSlash } from "./pathname.mjs";
2
- import { A as loadRouteLoader, D as getRouteLoaderValues, E as getRouteLoaderResponse, N as resolveRouteLoaderByHash, R as setRouteLoaders, T as getRouteLoaderParams, a as isPromise, ct as QFN_KEY, dt as _asyncRequestStore, f as FULLPATH_HEADER, g as clearRouteLoaderData, j as matchesRouteLoaderId, lt as Q_ROUTE, ot as QACTION_KEY, r as resolveRouteConfig, st as QDATA_KEY, ut as RequestEvRouterConfig, w as getRouteLoaderCtx, x as getLoaderRequestEvent } from "./head.qwik.mjs";
2
+ import { D as getRouteLoaderResponse, E as getRouteLoaderParams, M as matchesRouteLoaderId, O as getRouteLoaderValues, P as resolveRouteLoaderByHash, S as getLoaderRequestEvent, T as getRouteLoaderCtx, _ as clearRouteLoaderData, a as isPromise, ct as QACTION_KEY, dt as Q_ROUTE, ft as RequestEvRouterConfig, j as loadRouteLoader, lt as QDATA_KEY, p as FULLPATH_HEADER, pt as _asyncRequestStore, r as resolveRouteConfig, ut as QFN_KEY, z as setRouteLoaders } from "./head.qwik.mjs";
3
3
  import { a as QLoaderId, c as resolveValidInternalFullPathname, i as QActionId, s as recognizeRequest, t as IsQAction, u as trimRecognizedInternalPathname } from "./request-path.mjs";
4
4
  import { a as shareClassIdentity, i as RedirectMessage, n as throwIfControlFlowSignal, r as AbortMessage, t as ServerError } from "./server-error.mjs";
5
5
  import { inlinedQrl, isDev } from "@qwik.dev/core";
@@ -538,6 +538,7 @@ var formToObj = (formData) => {
538
538
  const childNode = pathNode.children.get(key);
539
539
  const nextValue = object[key];
540
540
  if (nextValue !== void 0) {
541
+ if (!Array.isArray(nextValue) && Object.getPrototypeOf(nextValue) !== null) break;
541
542
  object = nextValue;
542
543
  pathNode = childNode;
543
544
  continue;
@@ -598,13 +599,15 @@ function resolveCacheKey(cacheKeyExport, defaultKey, requestEv, eTag) {
598
599
  /** Build the default SSR cache key. eTag slot is dropped when no eTag was resolved. */
599
600
  function defaultSsrCacheKey(requestEv, eTag) {
600
601
  const status = requestEv.status();
601
- const pathname = requestEv.originalUrl.pathname;
602
- return eTag ? `${status}|${eTag}|${pathname}` : `${status}|${pathname}`;
602
+ const { origin, pathname } = requestEv.originalUrl;
603
+ const url = origin + pathname;
604
+ return eTag ? `${status}|${eTag}|${url}` : `${status}|${url}`;
603
605
  }
604
606
  /** Build the default loader cache key. eTag slot is dropped when no eTag was resolved. */
605
607
  function defaultLoaderCacheKey(requestEv, eTag) {
606
608
  const loaderId = requestEv.sharedMap.get(QLoaderId);
607
- const base = `${requestEv.url.pathname}|${requestEv.url.search}|${loaderId}`;
609
+ const { origin, pathname, search } = requestEv.url;
610
+ const base = `${origin}${pathname}|${search}|${loaderId}`;
608
611
  return eTag ? `${base}|${eTag}` : base;
609
612
  }
610
613
  /** Get a cached SSR entry by key (LRU touch). */
@@ -671,7 +674,7 @@ function loaderHandler(routeLoaders, route) {
671
674
  return;
672
675
  }
673
676
  setRouteLoaderData(requestEv, routeLoaders, route);
674
- await runBlockingLoadersBeforeTarget(routeLoaders, loader, requestEv);
677
+ await runRouteGuards(routeLoaders, loader, requestEv);
675
678
  const loaderRequestEv = createLoaderRequestEventFactory(requestEv)(loader);
676
679
  const cacheControl = resolveLoaderCacheControl(loader.__cacheControl, loaderRequestEv);
677
680
  const applyCacheControl = () => {
@@ -701,6 +704,7 @@ function loaderHandler(routeLoaders, route) {
701
704
  body: data
702
705
  });
703
706
  if (!normalizedETag && finalETag && performETagMatch(loaderRequestEv, finalETag, applyCacheControl)) return;
707
+ if (responseData.e || failed) requestEv.headers.set("Cache-Control", "no-store");
704
708
  await sendLoaderResponse(requestEv, data, cacheControl);
705
709
  };
706
710
  }
@@ -712,11 +716,9 @@ function resolveLoaderCacheControl(option, requestEv) {
712
716
  const value = typeof option === "function" ? option(requestEv) : option;
713
717
  return value === void 0 ? "private" : value;
714
718
  }
715
- async function runBlockingLoadersBeforeTarget(routeLoaders, targetLoader, requestEv) {
716
- for (const loader of routeLoaders) {
717
- if (loader === targetLoader) return;
718
- if (loader.__blockSSR) await loadRouteLoader(loader, requestEv);
719
- }
719
+ /** Blocking loaders guard the route, so they all run whatever the export order. */
720
+ async function runRouteGuards(routeLoaders, targetLoader, requestEv) {
721
+ for (const loader of routeLoaders) if (loader !== targetLoader && loader.__blockSSR) await loadRouteLoader(loader, requestEv);
720
722
  }
721
723
  function setRouteLoaderData(requestEv, routeLoaders, route) {
722
724
  if (route?.$loaderPaths$) Object.assign(getRouteLoaderCtx(requestEv).loaderPaths, route.$loaderPaths$);
@@ -787,6 +789,7 @@ function jsonRequestWrapper() {
787
789
  if (isLoader) await sendJsonResponse(requestEv, { r: location });
788
790
  else await sendActionResponse(requestEv, { redirect: location });
789
791
  } else if (err instanceof ServerError) {
792
+ requestEv.headers.set("Cache-Control", "no-store");
790
793
  if (isLoader) await sendJsonResponse(requestEv, { e: err });
791
794
  else await sendActionResponse(requestEv, {
792
795
  e: err,
@@ -794,6 +797,7 @@ function jsonRequestWrapper() {
794
797
  });
795
798
  } else if (err instanceof Error) {
796
799
  console.error("JSON request error:", err);
800
+ requestEv.headers.set("Cache-Control", "no-store");
797
801
  const message = isDev ? `${err.message}\n(this is only visible in dev mode)` : "Internal Server Error";
798
802
  const se = new ServerError(500, message);
799
803
  if (isLoader) await sendJsonResponse(requestEv, { e: se });
@@ -1846,6 +1850,7 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
1846
1850
  } else if (e instanceof AbortMessage) return;
1847
1851
  else if (e instanceof ServerError && !requestEv.headersSent) {
1848
1852
  const status = e.status;
1853
+ requestEv.headers.set("Cache-Control", "no-store");
1849
1854
  const accept = requestEv.request.headers.get("Accept");
1850
1855
  if (accept && !accept.includes("text/html")) {
1851
1856
  requestEv.headers.set("Content-Type", "application/qwik-json");
@@ -1,4 +1,4 @@
1
- import { D as getRouteLoaderValues, O as getRouteLoaders, d as loadRoute } from "./head.qwik.mjs";
1
+ import { O as getRouteLoaderValues, d as loadRoute, k as getRouteLoaders } from "./head.qwik.mjs";
2
2
  import { l as trimInternalPathname } from "./request-path.mjs";
3
3
  import { i as resolveRequestHandlers, r as renderQwikMiddleware, t as runQwikRouter } from "./user-response.mjs";
4
4
  import { _serialize } from "@qwik.dev/core/internal";
package/lib/index.d.ts CHANGED
@@ -157,10 +157,10 @@ declare type AnchorAttributes = QwikIntrinsicElements['a'];
157
157
  *
158
158
  * - `true`: use the surface's default key.
159
159
  *
160
- * - SSR default: `${status}|${eTag}|${pathname}` when an eTag is set, otherwise
161
- * `${status}|${pathname}`.
162
- * - Loader default: `${pathname}|${filteredSearch}|${loaderId}|${eTag}` when an eTag is set,
163
- * otherwise `${pathname}|${filteredSearch}|${loaderId}`.
160
+ * - SSR default: `${status}|${eTag}|${origin}${pathname}` when an eTag is set, otherwise
161
+ * `${status}|${origin}${pathname}`.
162
+ * - Loader default: `${origin}${pathname}|${filteredSearch}|${loaderId}|${eTag}` when an eTag is set,
163
+ * otherwise `${origin}${pathname}|${filteredSearch}|${loaderId}`.
164
164
  * - Function: receives the request event and the normalized, unquoted eTag (or an empty string when
165
165
  * none was provided). Return the cache key string, or `null` or `''` to skip caching for this
166
166
  * request. Loader callbacks receive the loader-scoped request event, with `url`, `query`, and
@@ -659,8 +659,8 @@ declare type LoaderOptions = {
659
659
  /**
660
660
  * Enable in-memory server-side caching of this loader's serialized JSON response.
661
661
  *
662
- * - `true` — use the default key `${pathname}|${filteredSearch}|${loaderId}` (suffixed with
663
- * `|${eTag}` when an eTag is set).
662
+ * - `true` — use the default key `${origin}${pathname}|${filteredSearch}|${loaderId}` (suffixed
663
+ * with `|${eTag}` when an eTag is set).
664
664
  * - Function `(requestEv, eTag) => string | null` — return a custom key, or `null` to skip caching
665
665
  * this request. For user-specific data, include user identity and relevant permissions in the
666
666
  * key or disable this cache.
@@ -1,6 +1,6 @@
1
1
  import { t as ensureSlash } from "./chunks/pathname.mjs";
2
- import { $ as HttpStatusContext, B as _setRouterConfig, C as getRequestEvent, F as routeLoader$, G as REFRESH_HEAD, H as getRouterConfig, I as routeLoaderQrl, J as preventNav, K as RUN_PENDING_ACTION, L as setLoaderSignalValue, M as prepareRouteLoaders, P as restoreRouteLoaders, Q as DocumentHeadContext, S as getModuleRouteLoaders, U as getRoutes, V as getBasePathname, W as getTrailingSlash, X as ContentContext, Y as registerPreventNav, Z as ContentInternalContext, _ as commitRouteLoaders, a as isPromise, at as RouteStateContext, b as getClientRouteLoaders, c as shouldPreload, ct as QFN_KEY, d as loadRoute, et as RouteActionContext, h as clearNavFetchCache, i as getClientNavPath, it as RouteNavigateContext, k as isImmutableLoader, l as toPath, lt as Q_ROUTE, m as abortRouteLoaderNavigation, n as resolveHead, nt as RouteLoaderCtxContext, o as isSameOrigin, ot as QACTION_KEY, q as internalState, rt as RouteLocationContext, s as isSamePath, st as QDATA_KEY, t as createDocumentHead, tt as RouteActionRunnerContext, u as toUrl, v as ensureRouteLoaderSignals, y as fetchRouteLoaderData, z as _getServiceWorkerUrl } from "./chunks/head.qwik.mjs";
3
- import { SkipRender, Slot, _capturesObj, _fnSignal, _getConstProps, _getVarProps, _jsxSorted, _jsxSplit, _qrlSync, _restProps, _wrapProp, componentQrl, createComputedQrl, createElement, eventQrl, getLocale, implicit$FirstArg, inlinedQrl, isBrowser, isDev, isServer, noSerialize, untrack, useContext, useContextProvider, useServerData, useSignal, useStore, useTaskQrl, useVisibleTaskQrl, withLocale } from "@qwik.dev/core";
2
+ import { $ as ContentInternalContext, A as isImmutableLoader, B as _getServiceWorkerUrl, C as getModuleRouteLoaders, F as restoreRouteLoaders, G as getRoutes, H as findRouterConfig, I as routeLoader$, J as RUN_PENDING_ACTION, K as getTrailingSlash, L as routeLoaderQrl, N as prepareRouteLoaders, Q as ContentContext, R as setLoaderSignalValue, U as getBasePathname, V as _setRouterConfig, W as getRouterConfig, X as preventNav, Y as internalState, Z as registerPreventNav, a as isPromise, at as RouteLocationContext, b as fetchRouteLoaderData, c as shouldPreload, ct as QACTION_KEY, d as loadRoute, dt as Q_ROUTE, et as DocumentHeadContext, f as matchRouteTree, g as clearNavFetchCache, h as abortRouteLoaderNavigation, i as getClientNavPath, it as RouteLoaderCtxContext, l as toPath, lt as QDATA_KEY, n as resolveHead, nt as RouteActionContext, o as isSameOrigin, ot as RouteNavigateContext, q as REFRESH_HEAD, rt as RouteActionRunnerContext, s as isSamePath, st as RouteStateContext, t as createDocumentHead, tt as HttpStatusContext, u as toUrl, ut as QFN_KEY, v as commitRouteLoaders, w as getRequestEvent, x as getClientRouteLoaders, y as ensureRouteLoaderSignals } from "./chunks/head.qwik.mjs";
3
+ import { SkipRender, Slot, _capturesObj, _fnSignal, _getConstProps, _getVarProps, _jsxSorted, _jsxSplit, _qrlSync, _restProps, _wrapProp, componentQrl, createComputedQrl, eventQrl, getLocale, implicit$FirstArg, inlinedQrl, isBrowser, isDev, isServer, noSerialize, untrack, useContext, useContextProvider, useServerData, useSignal, useStore, useTaskQrl, useVisibleTaskQrl, withLocale } from "@qwik.dev/core";
4
4
  import { _deserialize, _getContextContainer, _getContextHostElement, _getDomContainer, _hasStoreEffects, _regInlinedQrl, _requestPreload, _serialize, _waitOn, _waitUntilRendered, forceStoreEffects } from "@qwik.dev/core/internal";
5
5
  import { Fragment } from "@qwik.dev/core/jsx-runtime";
6
6
  import * as v from "valibot";
@@ -134,6 +134,8 @@ var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
134
134
  const shouldPrefetch = untrack(shouldPreload, clientNavPath, loc);
135
135
  const shouldVisiblePrefetchBundles = !!clientNavPath && shouldPrefetch && !isDepratedPrefetchDisabled && (prefetchBundlesProp === "visible" || prefetchProp === "js" || prefetchProp === true);
136
136
  const shouldVisiblePrefetchData = !!clientNavPath && shouldPrefetch && !isDepratedPrefetchDisabled && (prefetchDataProp === "visible" || prefetchProp === true);
137
+ const routes = shouldVisiblePrefetchBundles && findRouterConfig()?.routes;
138
+ const route = routes && untrack(() => matchRouteTree(routes, new URL(clientNavPath, loc.url).pathname));
137
139
  const shouldPrefetchBundles = !!clientNavPath && prefetchBundlesProp !== "off" && shouldPrefetch && !isDepratedPrefetchDisabled;
138
140
  const shouldPrefetchData = !!clientNavPath && prefetchDataProp !== "off" && shouldPrefetch && !isDepratedPrefetchDisabled;
139
141
  const handleBundlePrefetch = shouldPrefetchBundles ? /*#__PURE__*/ inlinedQrl((_, elm) => {
@@ -167,13 +169,13 @@ var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
167
169
  let nav = _capturesObj._[0], reload = _capturesObj._[1], replaceState = _capturesObj._[2], scroll = _capturesObj._[3];
168
170
  if (event.defaultPrevented) {
169
171
  if (elm.href) {
170
- elm.setAttribute("aria-pressed", "true");
172
+ elm.setAttribute("data-navigating", "");
171
173
  nav(elm.href, {
172
174
  forceReload: reload,
173
175
  replaceState,
174
176
  scroll
175
- }).then(() => {
176
- elm.removeAttribute("aria-pressed");
177
+ }).finally(() => {
178
+ elm.removeAttribute("data-navigating");
177
179
  });
178
180
  }
179
181
  }
@@ -184,10 +186,10 @@ var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
184
186
  scroll
185
187
  ]) : null;
186
188
  return /*#__PURE__*/ _jsxSplit("a", {
187
- ..._getVarProps({ "q:link": !!clientNavPath }),
188
- ..._getConstProps({ "q:link": !!clientNavPath }),
189
+ "q:link": !!clientNavPath,
189
190
  ...linkProps,
190
191
  "data-q-prefetch": shouldVisiblePrefetchBundles && shouldVisiblePrefetchData ? "bd" : shouldVisiblePrefetchBundles ? "b" : shouldVisiblePrefetchData ? "d" : null,
192
+ "data-q-route": route && !route.notFound ? "/" + route.routeParts.join("/") : void 0,
191
193
  "q-e:click": [
192
194
  preventDefault,
193
195
  /*#__PURE__*/ inlinedQrl((_, elm) => {
@@ -233,11 +235,11 @@ var newScrollState = () => {
233
235
  h: 0
234
236
  };
235
237
  };
236
- var preloadRouteBundles = (path, probability = .8) => {
238
+ var preloadRouteBundles = (routeName, probability = .8) => {
237
239
  if (isBrowser) {
238
- path = ensureSlash(path);
239
- path = path.length > 1 && path.startsWith("/") ? path.slice(1) : path;
240
- _requestPreload(path, probability);
240
+ routeName = ensureSlash(routeName);
241
+ routeName = routeName.length > 1 && routeName.startsWith("/") ? routeName.slice(1) : routeName;
242
+ _requestPreload(routeName, probability);
241
243
  }
242
244
  };
243
245
  var prefetchedLinks = /* @__PURE__ */ new WeakSet();
@@ -269,7 +271,8 @@ var createLinkPrefetchObserver = (manifestHash) => {
269
271
  const currentUrl = new URL(location.href);
270
272
  if (!isSameOrigin(url, currentUrl) || !shouldPreload(toPath(url), { url: currentUrl })) return;
271
273
  const mode = anchor.getAttribute("data-q-prefetch") || "";
272
- if (mode.includes("b")) preloadRouteBundles(url.pathname);
274
+ const routeName = anchor.getAttribute("data-q-route");
275
+ if (mode.includes("b") && routeName) preloadRouteBundles(routeName);
273
276
  if (mode.includes("d")) prefetchRoute(url, true, .8, manifestHash, false);
274
277
  };
275
278
  if (typeof IntersectionObserver === "undefined") {
@@ -335,6 +338,7 @@ var createCurrentPathTracker = (initialPath) => {
335
338
  var dispatchRouterPopstate = (document1, href) => {
336
339
  document1.dispatchEvent(new CustomEvent(Q_ROUTER_POPSTATE_EVENT, { detail: { href } }));
337
340
  };
341
+ var isPlainPrimaryClick = (event) => event.button === 0 && !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey);
338
342
  var spa_init_default = eventQrl(/*#__PURE__*/ inlinedQrl((_, el) => {
339
343
  if (!window._qRouterSPA && !window._qRouterInitPopstate) {
340
344
  const currentPath = location.pathname + location.search;
@@ -392,7 +396,7 @@ var spa_init_default = eventQrl(/*#__PURE__*/ inlinedQrl((_, el) => {
392
396
  };
393
397
  }
394
398
  window._qRouterInitAnchors = (event) => {
395
- if (window._qRouterSPA || event.defaultPrevented) return;
399
+ if (window._qRouterSPA || event.defaultPrevented || !isPlainPrimaryClick(event)) return;
396
400
  const target = event.target.closest("a[href]");
397
401
  if (target && !target.hasAttribute("preventdefault:click")) {
398
402
  const href = target.getAttribute("href");
@@ -1024,7 +1028,7 @@ function initializeSPA(goto, scroller) {
1024
1028
  };
1025
1029
  }
1026
1030
  document.addEventListener("click", (event) => {
1027
- if (event.defaultPrevented) return;
1031
+ if (event.defaultPrevented || !isPlainPrimaryClick(event)) return;
1028
1032
  const target = event.target.closest("a[href]");
1029
1033
  if (target && !target.hasAttribute("preventdefault:click")) {
1030
1034
  const href = target.getAttribute("href");
@@ -1555,8 +1559,8 @@ var ServiceWorkerRegister = (props) => /*#__PURE__*/ _jsxSorted("script", {
1555
1559
  dangerouslySetInnerHTML: _getServiceWorkerScript(_getServiceWorkerUrl()),
1556
1560
  nonce: _wrapProp(props, "nonce")
1557
1561
  }, { type: "module" }, null, 3, "UM_0");
1558
- var _hf0 = (p0) => p0.spaReset ? "true" : void 0;
1559
- var _hf0_str = "p0.spaReset?\"true\":undefined";
1562
+ var _hf0$1 = (p0) => p0.spaReset ? "true" : void 0;
1563
+ var _hf0_str$1 = "p0.spaReset?\"true\":undefined";
1560
1564
  /** @public */
1561
1565
  var Form = ({ action, spaReset, reloadDocument, onSubmit$, ...rest }, key) => {
1562
1566
  if (action) {
@@ -1579,13 +1583,11 @@ var Form = ({ action, spaReset, reloadDocument, onSubmit$, ...rest }, key) => {
1579
1583
  "q-e:submit": [onSubmit$, !reloadDocument ? action.submit : void 0],
1580
1584
  ["data-spa-reset"]: spaReset ? "true" : void 0
1581
1585
  }, { method: "post" }, null, 0, key);
1582
- } else return /*#__PURE__*/ createElement(GetForm, {
1583
- ...rest,
1586
+ } else return /*#__PURE__*/ _jsxSplit(GetForm, {
1584
1587
  spaReset,
1585
1588
  reloadDocument,
1586
- onSubmit$,
1587
- key
1588
- });
1589
+ ...rest
1590
+ }, { onSubmit$ }, null, 0, key);
1589
1591
  };
1590
1592
  var GetForm = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((_rawProps) => {
1591
1593
  const rest = _restProps(_rawProps, [
@@ -1597,7 +1599,7 @@ var GetForm = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((_rawProps) =>
1597
1599
  const nav = useNavigate();
1598
1600
  return /*#__PURE__*/ _jsxSplit("form", {
1599
1601
  action: "get",
1600
- "data-spa-reset": _fnSignal(_hf0, [_rawProps], _hf0_str),
1602
+ "data-spa-reset": _fnSignal(_hf0$1, [_rawProps], _hf0_str$1),
1601
1603
  ..._getVarProps(rest),
1602
1604
  "q-e:submit": [
1603
1605
  ...Array.isArray(_rawProps.onSubmit$) ? _rawProps.onSubmit$ : [_rawProps.onSubmit$],
@@ -1704,6 +1706,8 @@ var createRenderer = (getOptions) => {
1704
1706
  return renderToStream(jsx, renderOptions);
1705
1707
  });
1706
1708
  };
1709
+ var _hf0 = (p0, p1) => p1 || p0.dangerouslySetInnerHTML;
1710
+ var _hf0_str = "p1||p0.dangerouslySetInnerHTML";
1707
1711
  var trackWholeStore = (store) => {
1708
1712
  Object.keys(store);
1709
1713
  return untrack(() => ({ ...store }));
@@ -1744,20 +1748,22 @@ var DocumentHeadTags = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((prop
1744
1748
  head.meta.map((m) => /*#__PURE__*/ _jsxSplit("meta", { ..._getVarProps(m) }, _getConstProps(m), null, 0, "eL_1")),
1745
1749
  head.links.map((l) => /*#__PURE__*/ _jsxSplit("link", { ..._getVarProps(l) }, _getConstProps(l), null, 0, "eL_2")),
1746
1750
  head.styles.map((s) => {
1747
- const props = s.props || s;
1748
- return /*#__PURE__*/ createElement("style", {
1749
- ...props,
1750
- dangerouslySetInnerHTML: s.style || props.dangerouslySetInnerHTML,
1751
- key: s.key
1752
- });
1751
+ const { style, key, props: oldProps, ...rest } = trackWholeStore(s);
1752
+ const props = oldProps || rest;
1753
+ return /*#__PURE__*/ _jsxSplit("style", {
1754
+ ..._getVarProps(props),
1755
+ ..._getConstProps(props),
1756
+ dangerouslySetInnerHTML: _fnSignal(_hf0, [props, style], _hf0_str)
1757
+ }, null, null, 0, key);
1753
1758
  }),
1754
1759
  head.scripts.map((s) => {
1755
- const props = s.props || s;
1756
- return /*#__PURE__*/ createElement("script", {
1757
- ...props,
1758
- dangerouslySetInnerHTML: s.script || props.dangerouslySetInnerHTML,
1759
- key: s.key
1760
- });
1760
+ const { script, key, props: oldProps, ...rest } = trackWholeStore(s);
1761
+ const props = oldProps || rest;
1762
+ return /*#__PURE__*/ _jsxSplit("script", {
1763
+ ..._getVarProps(props),
1764
+ ..._getConstProps(props),
1765
+ dangerouslySetInnerHTML: _fnSignal(_hf0, [props, script], _hf0_str)
1766
+ }, null, null, 0, key);
1761
1767
  })
1762
1768
  ], 1, "eL_3");
1763
1769
  }, "DocumentHeadTags_component_9CrWYOoCpgY"));
@@ -103,10 +103,10 @@ declare type CacheControlTarget = 'Cache-Control' | 'CDN-Cache-Control' | 'Cloud
103
103
  *
104
104
  * - `true`: use the surface's default key.
105
105
  *
106
- * - SSR default: `${status}|${eTag}|${pathname}` when an eTag is set, otherwise
107
- * `${status}|${pathname}`.
108
- * - Loader default: `${pathname}|${filteredSearch}|${loaderId}|${eTag}` when an eTag is set,
109
- * otherwise `${pathname}|${filteredSearch}|${loaderId}`.
106
+ * - SSR default: `${status}|${eTag}|${origin}${pathname}` when an eTag is set, otherwise
107
+ * `${status}|${origin}${pathname}`.
108
+ * - Loader default: `${origin}${pathname}|${filteredSearch}|${loaderId}|${eTag}` when an eTag is set,
109
+ * otherwise `${origin}${pathname}|${filteredSearch}|${loaderId}`.
110
110
  * - Function: receives the request event and the normalized, unquoted eTag (or an empty string when
111
111
  * none was provided). Return the cache key string, or `null` or `''` to skip caching for this
112
112
  * request. Loader callbacks receive the loader-scoped request event, with `url`, `query`, and
@@ -1,4 +1,4 @@
1
- import { H as getRouterConfig, d as loadRoute, dt as _asyncRequestStore } from "../../chunks/head.qwik.mjs";
1
+ import { W as getRouterConfig, d as loadRoute, pt as _asyncRequestStore } from "../../chunks/head.qwik.mjs";
2
2
  import { c as resolveValidInternalFullPathname, l as trimInternalPathname, s as recognizeRequest, u as trimRecognizedInternalPathname } from "../../chunks/request-path.mjs";
3
3
  import { i as RedirectMessage, r as AbortMessage, t as ServerError } from "../../chunks/server-error.mjs";
4
4
  import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qwik.dev/router",
3
3
  "description": "The router for Qwik.",
4
- "version": "2.0.0-rc.3",
4
+ "version": "2.0.0-rc.4",
5
5
  "bugs": "https://github.com/QwikDev/qwik/issues",
6
6
  "dependencies": {
7
7
  "@azure/functions": "3.5.1",
@@ -40,8 +40,8 @@
40
40
  "tsm": "2.3.0",
41
41
  "typescript": "5.9.3",
42
42
  "uvu": "0.5.6",
43
- "vite": "8.2.1",
44
- "@qwik.dev/core": "2.0.0-rc.3"
43
+ "vite": "8.2.4",
44
+ "@qwik.dev/core": "2.0.0-rc.4"
45
45
  },
46
46
  "engines": {
47
47
  "node": "^18.17.0 || ^20.3.0 || >=21.0.0"
@@ -166,7 +166,7 @@
166
166
  "main": "./lib/index.qwik.mjs",
167
167
  "peerDependencies": {
168
168
  "vite": ">=8 <9",
169
- "@qwik.dev/core": "2.0.0-rc.3"
169
+ "@qwik.dev/core": "2.0.0-rc.4"
170
170
  },
171
171
  "publishConfig": {
172
172
  "access": "public"