@qwik.dev/router 2.0.0-beta.9 → 2.0.0-rc.2
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.
- package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
- package/lib/adapters/azure-swa/vite/index.mjs +44 -57
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +16 -22
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +15 -19
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +45 -76
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +25 -34
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +49 -89
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/node-server/vite/index.mjs +16 -22
- package/lib/adapters/shared/vite/index.d.ts +9 -16
- package/lib/adapters/shared/vite/index.mjs +280 -293
- package/lib/adapters/ssg/vite/index.d.ts +1 -1
- package/lib/adapters/ssg/vite/index.mjs +13 -299
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +75 -79
- package/lib/chunks/dev-preloaded-route-loader.mjs +2 -0
- package/lib/chunks/format.mjs +24 -0
- package/lib/chunks/fs.mjs +143 -0
- package/lib/chunks/head.qwik.mjs +1570 -0
- package/lib/chunks/http-error.qwik.mjs +28 -0
- package/lib/chunks/pathname.mjs +58 -0
- package/lib/chunks/request-body-limit.mjs +27 -0
- package/lib/chunks/request-path.mjs +53 -0
- package/lib/chunks/route-trie-key.mjs +10 -0
- package/lib/chunks/routes.mjs +26 -0
- package/lib/chunks/server-error.mjs +38 -0
- package/lib/chunks/static-file.mjs +70 -0
- package/lib/chunks/system.mjs +271 -0
- package/lib/chunks/user-response.mjs +1878 -0
- package/lib/chunks/worker-thread.mjs +274 -0
- package/lib/index.d.ts +550 -182
- package/lib/index.qwik.mjs +1746 -2057
- package/lib/middleware/aws-lambda/index.d.ts +15 -17
- package/lib/middleware/aws-lambda/index.mjs +46 -50
- package/lib/middleware/azure-swa/index.mjs +85 -294
- package/lib/middleware/bun/index.d.ts +22 -5
- package/lib/middleware/bun/index.mjs +118 -201
- package/lib/middleware/cloudflare-pages/index.d.ts +2 -0
- package/lib/middleware/cloudflare-pages/index.mjs +103 -101
- package/lib/middleware/deno/index.d.ts +22 -5
- package/lib/middleware/deno/index.mjs +103 -191
- package/lib/middleware/firebase/index.mjs +22 -31
- package/lib/middleware/netlify-edge/index.d.ts +2 -0
- package/lib/middleware/netlify-edge/index.mjs +64 -80
- package/lib/middleware/node/index.d.ts +17 -5
- package/lib/middleware/node/index.mjs +298 -269
- package/lib/middleware/request-handler/index.d.ts +259 -58
- package/lib/middleware/request-handler/index.mjs +108 -1730
- package/lib/middleware/vercel-edge/index.d.ts +2 -0
- package/lib/middleware/vercel-edge/index.mjs +77 -100
- package/lib/modules.d.ts +7 -4
- package/lib/service-worker/index.mjs +14 -0
- package/lib/ssg/index.d.ts +50 -26
- package/lib/ssg/index.mjs +257 -43
- package/lib/vite/index.d.ts +59 -11
- package/lib/vite/index.mjs +2534 -27536
- package/modules.d.ts +7 -4
- package/package.json +53 -70
- package/lib/adapters/azure-swa/vite/index.cjs +0 -96
- package/lib/adapters/bun-server/vite/index.cjs +0 -50
- package/lib/adapters/cloud-run/vite/index.cjs +0 -47
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
- package/lib/adapters/deno-server/vite/index.cjs +0 -62
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -130
- package/lib/adapters/node-server/vite/index.cjs +0 -50
- package/lib/adapters/shared/vite/index.cjs +0 -338
- package/lib/adapters/ssg/vite/index.cjs +0 -339
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
- package/lib/index.qwik.cjs +0 -2112
- package/lib/middleware/node/index.cjs +0 -310
- package/lib/middleware/request-handler/index.cjs +0 -1766
- package/lib/service-worker.cjs +0 -17
- package/lib/service-worker.mjs +0 -15
- package/lib/ssg/deno.mjs +0 -8
- package/lib/ssg/index.cjs +0 -67
- package/lib/ssg/node.cjs +0 -1128
- package/lib/ssg/node.mjs +0 -1090
- package/lib/vite/index.cjs +0 -27607
|
@@ -0,0 +1,1570 @@
|
|
|
1
|
+
import { t as ensureSlash } from "./pathname.mjs";
|
|
2
|
+
import { o as getLoaderName } from "./request-path.mjs";
|
|
3
|
+
import { i as RedirectMessage, n as throwIfControlFlowSignal, t as ServerError } from "./server-error.mjs";
|
|
4
|
+
import { r as unescapeStaticTrieKey, t as escapeStaticTrieKey } from "./route-trie-key.mjs";
|
|
5
|
+
import { _capturesObj, createComputedQrl, createContextId, implicit$FirstArg, inlinedQrl, isBrowser, isDev, isServer, untrack, useServerData, withLocale } from "@qwik.dev/core";
|
|
6
|
+
import { SerializerSymbol, _UNINITIALIZED, _deserialize, _getAsyncLocalStorage, _injectAsyncSignalValue, _markSignalAsExternallyOwned, _qwikSymbol, _registerSingleton, _resolveContextWithoutSequentialScope, _verifySerializable } from "@qwik.dev/core/internal";
|
|
7
|
+
import { isServer as isServer$1 } from "@qwik.dev/core/build";
|
|
8
|
+
var createRequestStore = () => {
|
|
9
|
+
const AsyncLocalStorage = _getAsyncLocalStorage();
|
|
10
|
+
if (AsyncLocalStorage) return new AsyncLocalStorage();
|
|
11
|
+
console.warn("\n=====================\n Qwik Router Warning:\n AsyncLocalStorage is not available, continuing without it.\n This impacts concurrent async server calls, where they lose access to the ServerRequestEv object.\n=====================\n\n");
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Shared with the router copy of a Qwik library kept external on the server, so its
|
|
15
|
+
* `getRequestEvent()` and `server$` see the request the app is serving.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
var _asyncRequestStore = isServer$1 ? _registerSingleton("routerRequestStore", createRequestStore) : void 0;
|
|
20
|
+
/** The request event's key for the config of the app serving it. */
|
|
21
|
+
var RequestEvRouterConfig = /*#__PURE__*/ _qwikSymbol("router.config");
|
|
22
|
+
/** The config of the app serving the current request, for a router copy that holds none. */
|
|
23
|
+
var getServingRouterConfig = () => _asyncRequestStore?.getStore()?.[RequestEvRouterConfig];
|
|
24
|
+
var QACTION_KEY = "qaction";
|
|
25
|
+
var QFN_KEY = "qfunc";
|
|
26
|
+
var QDATA_KEY = "qdata";
|
|
27
|
+
/** @public */
|
|
28
|
+
var Q_ROUTE = "q:route";
|
|
29
|
+
function DEFAULT_LOADERS_SERIALIZATION_STRATEGY() {
|
|
30
|
+
return globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__ || "never";
|
|
31
|
+
}
|
|
32
|
+
var RouteStateContext = /*#__PURE__*/ createContextId("qr-s");
|
|
33
|
+
var RouteLoaderCtxContext = /*#__PURE__*/ createContextId("qr-lc");
|
|
34
|
+
var ContentContext = /*#__PURE__*/ createContextId("qr-c");
|
|
35
|
+
var ContentInternalContext = /*#__PURE__*/ createContextId("qr-ic");
|
|
36
|
+
var DocumentHeadContext = /*#__PURE__*/ createContextId("qr-h");
|
|
37
|
+
var RouteLocationContext = /*#__PURE__*/ createContextId("qr-l");
|
|
38
|
+
var RouteNavigateContext = /*#__PURE__*/ createContextId("qr-n");
|
|
39
|
+
var RouteActionContext = /*#__PURE__*/ createContextId("qr-a");
|
|
40
|
+
var RoutePreventNavigateContext = /*#__PURE__*/ createContextId("qr-p");
|
|
41
|
+
var HttpStatusContext = /*#__PURE__*/ createContextId("qr-hs");
|
|
42
|
+
var holder = {};
|
|
43
|
+
/** The config this router copy holds, else the one of the app serving the current request. */
|
|
44
|
+
var findRouterConfig = () => holder.config ?? getServingRouterConfig();
|
|
45
|
+
/**
|
|
46
|
+
* Registers the app's route config with the router copy bundled into the app. The generated
|
|
47
|
+
* `@qwik-router-config` module calls this on the server; the client loads that module lazily
|
|
48
|
+
* instead, since it is a separate chunk.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
var _setRouterConfig = (config) => {
|
|
53
|
+
holder.config = config;
|
|
54
|
+
holder.ready = void 0;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The app's route config: the route trie, server plugins and build options that the Qwik Router
|
|
58
|
+
* Vite plugin generated. Resolves once the config is loaded and its `server$` modules are
|
|
59
|
+
* registered. On the server, the router copy of a Qwik library kept external reads the config of
|
|
60
|
+
* the app serving the current request.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
var getRouterConfig = () => {
|
|
65
|
+
const servingConfig = !holder.config && getServingRouterConfig();
|
|
66
|
+
if (servingConfig) return Promise.resolve(servingConfig);
|
|
67
|
+
if (!holder.ready) holder.ready = loadRouterConfig().catch((error) => {
|
|
68
|
+
holder.ready = void 0;
|
|
69
|
+
throw error;
|
|
70
|
+
});
|
|
71
|
+
return holder.ready;
|
|
72
|
+
};
|
|
73
|
+
var loadRouterConfig = async () => {
|
|
74
|
+
if (!holder.config) {
|
|
75
|
+
const configModule = await import("@qwik-router-config").catch((error) => {
|
|
76
|
+
throw isBrowser ? error : new Error("Qwik Router config not found. Import \"@qwik-router-config\" in the server entry that the Qwik Router Vite plugin builds.", { cause: error });
|
|
77
|
+
});
|
|
78
|
+
holder.config ??= configModule;
|
|
79
|
+
}
|
|
80
|
+
await holder.config.importEagerModules?.();
|
|
81
|
+
return holder.config;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* The route trie of the app, as generated by the Qwik Router Vite plugin.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
var getRoutes = async () => (await getRouterConfig()).routes;
|
|
89
|
+
/**
|
|
90
|
+
* The base pathname the app is served under, such as `/` or `/docs/`.
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
var getBasePathname = () => findRouterConfig()?.basePathname ?? globalThis.__QWIK_ROUTER_BASE_PATHNAME__ ?? "/";
|
|
95
|
+
/**
|
|
96
|
+
* Whether the app's URLs end with a trailing slash.
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
var getTrailingSlash = () => findRouterConfig()?.trailingSlash ?? !globalThis.__NO_TRAILING_SLASH__;
|
|
101
|
+
/** @internal */
|
|
102
|
+
var _getServiceWorkerUrl = () => findRouterConfig()?.serviceWorkerUrl;
|
|
103
|
+
/**
|
|
104
|
+
* Route loaders read data before the route rendering starts, based on the route being navigated to.
|
|
105
|
+
* They automatically update when the route changes on the client.
|
|
106
|
+
*
|
|
107
|
+
* They are represented by a ComputedSignal.
|
|
108
|
+
*/
|
|
109
|
+
var REQUEST_ROUTE_LOADER_STATE = "@routeLoaderState";
|
|
110
|
+
var REQUEST_LOADER_PATHS_STORE = "@loaderPathsStore";
|
|
111
|
+
var REQUEST_LOADER_PARAMS_STORE = "@loaderParamsStore";
|
|
112
|
+
var REQUEST_ROUTE_LOADERS = "@routeLoaders";
|
|
113
|
+
var REQUEST_ROUTE_LOADER_PROMISES = "@routeLoaderPromises";
|
|
114
|
+
var REQUEST_ROUTE_LOADER_EVENTS = "@routeLoaderEvents";
|
|
115
|
+
var REQUEST_ROUTE_LOADER_ROOT_EVENT = "@routeLoaderRootEvent";
|
|
116
|
+
var ROUTE_LOADER_VALUE_PREFIX = "__qwik_route_loader_value__";
|
|
117
|
+
/** Header name sent by client to tell the server the actual page URL for loader requests. */
|
|
118
|
+
var FULLPATH_HEADER = "X-Qwik-fullpath";
|
|
119
|
+
/** Dev route hint that preserves the loader URL. */
|
|
120
|
+
var ROUTE_PATH_HEADER = "X-Qwik-route-path";
|
|
121
|
+
/**
|
|
122
|
+
* Per-navigation fetch dedupe: shares in-flight and completed fetches (hover prefetch → click nav)
|
|
123
|
+
* and prevents repeat hover fetches. Cleared after each navigation kicks off its loader fetches;
|
|
124
|
+
* across navigations the browser HTTP cache is the freshness authority.
|
|
125
|
+
*/
|
|
126
|
+
var navFetchCache = /* @__PURE__ */ new Map();
|
|
127
|
+
var clearNavFetchCache = () => {
|
|
128
|
+
navFetchCache = /* @__PURE__ */ new Map();
|
|
129
|
+
};
|
|
130
|
+
var isRedirectStatus = (status) => status >= 300 && status < 400;
|
|
131
|
+
/** We don't have aborts when preloading so we just pretend we do */
|
|
132
|
+
var wrapWithAbort = (promise, signal) => {
|
|
133
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
const abort = () => reject(signal.reason);
|
|
136
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
137
|
+
promise.finally(() => signal.removeEventListener("abort", abort)).then(resolve, reject);
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
var clientRouteLoaders = /* @__PURE__ */ new WeakMap();
|
|
141
|
+
function getClientRouteLoaders(ctx, pageUrl) {
|
|
142
|
+
let client = clientRouteLoaders.get(ctx);
|
|
143
|
+
if (!client) {
|
|
144
|
+
const current = {
|
|
145
|
+
requests: /* @__PURE__ */ new Map(),
|
|
146
|
+
paths: { ...ctx.loaderPaths },
|
|
147
|
+
pageUrl: pageUrl || location.href
|
|
148
|
+
};
|
|
149
|
+
client = {
|
|
150
|
+
current,
|
|
151
|
+
committed: current
|
|
152
|
+
};
|
|
153
|
+
clientRouteLoaders.set(ctx, client);
|
|
154
|
+
}
|
|
155
|
+
return client;
|
|
156
|
+
}
|
|
157
|
+
function getLoaderRequest(ctx, state, id, hash1) {
|
|
158
|
+
return untrack(() => {
|
|
159
|
+
const client = getClientRouteLoaders(ctx);
|
|
160
|
+
const { requests, paths, pageUrl } = client.current;
|
|
161
|
+
let request = requests.get(state[id]);
|
|
162
|
+
if (!request) {
|
|
163
|
+
const path = paths[id] || paths[hash1];
|
|
164
|
+
request = {
|
|
165
|
+
routePath: path || new URL(pageUrl).pathname,
|
|
166
|
+
pageUrl,
|
|
167
|
+
active: client.navCount === void 0 || !!path,
|
|
168
|
+
hash: hash1
|
|
169
|
+
};
|
|
170
|
+
requests.set(state[id], request);
|
|
171
|
+
}
|
|
172
|
+
return request;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function assertCurrentLoaderRequest(ctx, signal, request, abortSignal) {
|
|
176
|
+
abortSignal.throwIfAborted();
|
|
177
|
+
if (!request.active || clientRouteLoaders.get(ctx)?.current.requests.get(signal) !== request) throw new DOMException(isDev ? "Route loader navigation was superseded" : "", "AbortError");
|
|
178
|
+
}
|
|
179
|
+
var getRouteLoaderValueStateKey = (loaderId) => `${ROUTE_LOADER_VALUE_PREFIX}${loaderId}`;
|
|
180
|
+
var ServerRouteLoaderCapture = class {
|
|
181
|
+
hash;
|
|
182
|
+
qrl;
|
|
183
|
+
validators;
|
|
184
|
+
blockSSR;
|
|
185
|
+
requestEv;
|
|
186
|
+
constructor(hash2, qrl1, validators1, blockSSR1, requestEv1) {
|
|
187
|
+
this.hash = hash2;
|
|
188
|
+
this.qrl = qrl1;
|
|
189
|
+
this.validators = validators1;
|
|
190
|
+
this.blockSSR = blockSSR1;
|
|
191
|
+
this.requestEv = requestEv1;
|
|
192
|
+
}
|
|
193
|
+
load() {
|
|
194
|
+
const requestEv2 = this.requestEv;
|
|
195
|
+
if (!requestEv2) throw new Error("Unable to determine the current RequestEvent.");
|
|
196
|
+
const values = getRouteLoaderValues(requestEv2);
|
|
197
|
+
if (this.hash in values) return values[this.hash];
|
|
198
|
+
const ev = this.blockSSR ? requestEv2 : detachResponseFromEvent(requestEv2);
|
|
199
|
+
return loadRouteLoaderByQrl(this.hash, this.qrl, this.validators, ev);
|
|
200
|
+
}
|
|
201
|
+
[SerializerSymbol]() {
|
|
202
|
+
return this.hash;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var isRequestEvent = (value) => !!value && typeof value === "object" && Object.prototype.hasOwnProperty.call(value, "sharedMap") && Object.prototype.hasOwnProperty.call(value, "cookie");
|
|
206
|
+
var isLoaderInternal = (value) => typeof value === "function" && value.__brand === "server_loader";
|
|
207
|
+
/**
|
|
208
|
+
* Fetch a single loader's raw JSON response from the server.
|
|
209
|
+
*
|
|
210
|
+
* URL pattern: `{basePath}{routePath}/q-loader-{loaderId}.{manifestHash}.json`
|
|
211
|
+
*/
|
|
212
|
+
var fetchRouteLoaderData = async (loaderId, routePath, manifestHash, opts) => {
|
|
213
|
+
if (!routePath) return;
|
|
214
|
+
let resolvedPath = routePath;
|
|
215
|
+
const basePath = opts?.basePath ?? "/";
|
|
216
|
+
if (basePath !== "/" && !resolvedPath.startsWith(basePath)) resolvedPath = basePath + resolvedPath.slice(1);
|
|
217
|
+
const pathBase = ensureSlash(resolvedPath);
|
|
218
|
+
const pageUrl = opts?.pageUrl;
|
|
219
|
+
const search = pageUrl?.search ?? "";
|
|
220
|
+
const url = `${pathBase}${getLoaderName(loaderId, manifestHash)}${search}`;
|
|
221
|
+
const headers = {};
|
|
222
|
+
if (pageUrl && pageUrl.pathname !== pathBase) {
|
|
223
|
+
if (!globalThis.__STRICT_LOADERS__) headers[FULLPATH_HEADER] = pageUrl.pathname;
|
|
224
|
+
else if (isDev) headers[ROUTE_PATH_HEADER] = pageUrl.pathname;
|
|
225
|
+
}
|
|
226
|
+
const cacheKey = `${url}\n${headers["X-Qwik-fullpath"] ?? ""}`;
|
|
227
|
+
const cache = navFetchCache;
|
|
228
|
+
if (!opts?.ignoreCache) {
|
|
229
|
+
const entry = cache.get(cacheKey);
|
|
230
|
+
if (entry) return opts?.signal ? wrapWithAbort(entry, opts.signal) : entry;
|
|
231
|
+
}
|
|
232
|
+
const request = async () => {
|
|
233
|
+
opts?.signal?.throwIfAborted();
|
|
234
|
+
const response = await fetch(url, {
|
|
235
|
+
signal: opts?.signal,
|
|
236
|
+
cache: opts?.ignoreCache ? "reload" : "default",
|
|
237
|
+
headers
|
|
238
|
+
});
|
|
239
|
+
opts?.signal?.throwIfAborted();
|
|
240
|
+
if (response.redirected) return { r: response.url };
|
|
241
|
+
if (isRedirectStatus(response.status)) {
|
|
242
|
+
const location1 = response.headers.get("Location");
|
|
243
|
+
if (location1) return { r: location1 };
|
|
244
|
+
}
|
|
245
|
+
if (!response.ok) return;
|
|
246
|
+
const raw = await response.text();
|
|
247
|
+
opts?.signal?.throwIfAborted();
|
|
248
|
+
return { raw };
|
|
249
|
+
};
|
|
250
|
+
if (opts?.ignoreCache) return request();
|
|
251
|
+
if (opts?.signal) return request().then((value) => {
|
|
252
|
+
opts.signal.throwIfAborted();
|
|
253
|
+
if (value !== void 0 && !cache.has(cacheKey)) cache.set(cacheKey, Promise.resolve(value));
|
|
254
|
+
return value;
|
|
255
|
+
});
|
|
256
|
+
const promise = request().then((value) => {
|
|
257
|
+
if (value === void 0) cache.delete(cacheKey);
|
|
258
|
+
return value;
|
|
259
|
+
}, (err) => {
|
|
260
|
+
cache.delete(cacheKey);
|
|
261
|
+
throw err;
|
|
262
|
+
});
|
|
263
|
+
cache.set(cacheKey, promise);
|
|
264
|
+
return promise;
|
|
265
|
+
};
|
|
266
|
+
var createRouteLoaderSignal = (loader, routeLoaderCtx, state, requestEv3) => {
|
|
267
|
+
const id = loader.__id;
|
|
268
|
+
const stateValues = state;
|
|
269
|
+
const resumeValueKey = getRouteLoaderValueStateKey(id);
|
|
270
|
+
const capture = isServer ? new ServerRouteLoaderCapture(id, loader.__qrl, loader.__validators, loader.__blockSSR, requestEv3 ?? useServerData("qwikrouter")?.ev) : id;
|
|
271
|
+
const searchFilter = loader.__search;
|
|
272
|
+
const loaderHash = isDev ? loader.__qrl.getHash() : id;
|
|
273
|
+
const signal = createComputedQrl(/*#__PURE__*/ inlinedQrl(async (ctx) => {
|
|
274
|
+
let capture = _capturesObj._[0], id = _capturesObj._[1], lastFetch = _capturesObj._[2], loaderHash = _capturesObj._[3], resumeValueKey = _capturesObj._[4], routeLoaderCtx = _capturesObj._[5], searchFilter = _capturesObj._[6], state = _capturesObj._[7], stateValues = _capturesObj._[8];
|
|
275
|
+
if (!!ctx.info && typeof ctx.info === "object" && "__v" in ctx.info) {
|
|
276
|
+
const value = ctx.info.__v;
|
|
277
|
+
if (!isServer && resumeValueKey in stateValues) stateValues[resumeValueKey] = value;
|
|
278
|
+
lastFetch.raw = void 0;
|
|
279
|
+
return value;
|
|
280
|
+
}
|
|
281
|
+
if (isServer) return capture.load();
|
|
282
|
+
const request = getLoaderRequest(routeLoaderCtx, state, id, loaderHash);
|
|
283
|
+
if (!request.active) {
|
|
284
|
+
if (ctx.previous === void 0) return new Promise((_, reject) => {
|
|
285
|
+
ctx.abortSignal.throwIfAborted();
|
|
286
|
+
ctx.abortSignal.addEventListener("abort", () => reject(ctx.abortSignal.reason), { once: true });
|
|
287
|
+
});
|
|
288
|
+
return ctx.previous;
|
|
289
|
+
}
|
|
290
|
+
const pageUrl = new URL(request.pageUrl);
|
|
291
|
+
const mHash = untrack(() => routeLoaderCtx.manifestHash) || "dev";
|
|
292
|
+
const basePath = getBasePathname();
|
|
293
|
+
const needsResumeFetch = stateValues[resumeValueKey] === _UNINITIALIZED;
|
|
294
|
+
let fetchUrl = pageUrl;
|
|
295
|
+
if (searchFilter) {
|
|
296
|
+
fetchUrl = new URL(pageUrl.href);
|
|
297
|
+
fetchUrl.search = filterSearchParams(pageUrl.searchParams, searchFilter);
|
|
298
|
+
}
|
|
299
|
+
const result = await fetchRouteLoaderData(id, request.routePath, mHash, {
|
|
300
|
+
pageUrl: fetchUrl,
|
|
301
|
+
basePath,
|
|
302
|
+
ignoreCache: ctx.info === true,
|
|
303
|
+
signal: ctx.abortSignal
|
|
304
|
+
});
|
|
305
|
+
assertCurrentLoaderRequest(routeLoaderCtx, state[id], request, ctx.abortSignal);
|
|
306
|
+
if (!result) throw new Error(`Loader ${id} returned empty response`);
|
|
307
|
+
let response;
|
|
308
|
+
if (result.raw === void 0) response = result;
|
|
309
|
+
else {
|
|
310
|
+
if (result.raw === lastFetch.raw && ctx.previous !== void 0) return ctx.previous;
|
|
311
|
+
response = await _deserialize(result.raw);
|
|
312
|
+
if (!response) throw new Error(`Loader ${id} returned empty response`);
|
|
313
|
+
}
|
|
314
|
+
assertCurrentLoaderRequest(routeLoaderCtx, state[id], request, ctx.abortSignal);
|
|
315
|
+
if (response.r) {
|
|
316
|
+
const goto = routeLoaderCtx.goto;
|
|
317
|
+
if (goto) goto(response.r, { replaceState: true });
|
|
318
|
+
else location.href = response.r;
|
|
319
|
+
return ctx.previous;
|
|
320
|
+
}
|
|
321
|
+
if (response.e) throw response.e;
|
|
322
|
+
lastFetch.raw = result.raw;
|
|
323
|
+
if (needsResumeFetch) stateValues[resumeValueKey] = response.d;
|
|
324
|
+
return response.d;
|
|
325
|
+
}, "createRouteLoaderSignal_signal_createComputed_4s4ZDCYhDOA", [
|
|
326
|
+
capture,
|
|
327
|
+
id,
|
|
328
|
+
{},
|
|
329
|
+
loaderHash,
|
|
330
|
+
resumeValueKey,
|
|
331
|
+
routeLoaderCtx,
|
|
332
|
+
searchFilter,
|
|
333
|
+
state,
|
|
334
|
+
stateValues
|
|
335
|
+
]), { serializationStrategy: loader.__serializationStrategy });
|
|
336
|
+
_markSignalAsExternallyOwned(signal);
|
|
337
|
+
return signal;
|
|
338
|
+
};
|
|
339
|
+
/** Build a sorted, stable search string from only the allowed param names. */
|
|
340
|
+
var filterSearchParams = (params, allowed) => {
|
|
341
|
+
const filtered = new URLSearchParams();
|
|
342
|
+
for (let i = 0; i < allowed.length; i++) {
|
|
343
|
+
const name = allowed[i];
|
|
344
|
+
const values = params.getAll(name);
|
|
345
|
+
for (let j = 0; j < values.length; j++) filtered.append(name, values[j]);
|
|
346
|
+
}
|
|
347
|
+
filtered.sort();
|
|
348
|
+
return filtered.toString() ? `?${filtered.toString()}` : "";
|
|
349
|
+
};
|
|
350
|
+
function getLoaderOptions(rest) {
|
|
351
|
+
let id;
|
|
352
|
+
let serializationStrategy = DEFAULT_LOADERS_SERIALIZATION_STRATEGY();
|
|
353
|
+
let cacheControl;
|
|
354
|
+
let eTag;
|
|
355
|
+
let cacheKey;
|
|
356
|
+
let search;
|
|
357
|
+
let blockSSR2 = true;
|
|
358
|
+
const validators2 = [];
|
|
359
|
+
if (rest.length === 1) {
|
|
360
|
+
const options = rest[0];
|
|
361
|
+
if (options && typeof options === "object") {
|
|
362
|
+
if ("validate" in options) validators2.push(options);
|
|
363
|
+
else {
|
|
364
|
+
if (options.id) id = options.id;
|
|
365
|
+
if (options.serializationStrategy) serializationStrategy = options.serializationStrategy;
|
|
366
|
+
if (options.validation) validators2.push(...options.validation);
|
|
367
|
+
if ("cacheControl" in options) cacheControl = options.cacheControl;
|
|
368
|
+
if ("eTag" in options) eTag = options.eTag;
|
|
369
|
+
if ("cacheKey" in options) cacheKey = options.cacheKey;
|
|
370
|
+
if (options.search) search = options.search;
|
|
371
|
+
else if (globalThis.__STRICT_LOADERS__) search = [];
|
|
372
|
+
if (options.blockSSR === false) {
|
|
373
|
+
if (!__EXPERIMENTAL__.blockSSR) throw new Error("`blockSSR: false` is an experimental feature and is not enabled. Please enable the feature flag by adding `experimental: [\"blockSSR\"]` to your qwikVite plugin options.");
|
|
374
|
+
blockSSR2 = false;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
} else if (rest.length > 1) validators2.push(...rest.filter(Boolean));
|
|
379
|
+
return {
|
|
380
|
+
id,
|
|
381
|
+
validators: validators2.reverse(),
|
|
382
|
+
serializationStrategy,
|
|
383
|
+
cacheControl,
|
|
384
|
+
eTag,
|
|
385
|
+
cacheKey,
|
|
386
|
+
search,
|
|
387
|
+
blockSSR: blockSSR2
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Returns the current RequestEvent if possible. Only usable on the server, and only during request
|
|
392
|
+
* processing.
|
|
393
|
+
*
|
|
394
|
+
* @public
|
|
395
|
+
*/
|
|
396
|
+
var getRequestEvent = (thisArg) => {
|
|
397
|
+
if (!isServer) throw new Error("getRequestEvent() can only be used on the server.");
|
|
398
|
+
return _asyncRequestStore?.getStore() ?? (isRequestEvent(thisArg) ? thisArg : void 0);
|
|
399
|
+
};
|
|
400
|
+
var REQUEST_ROUTE_LOADER_VALUES = "@routeLoaderValues";
|
|
401
|
+
/** Get/create the record of pre-loaded loader values (used by middleware before component). */
|
|
402
|
+
function getRouteLoaderValues(requestEv5) {
|
|
403
|
+
let values = requestEv5.sharedMap.get(REQUEST_ROUTE_LOADER_VALUES);
|
|
404
|
+
if (!values) {
|
|
405
|
+
values = {};
|
|
406
|
+
requestEv5.sharedMap.set(REQUEST_ROUTE_LOADER_VALUES, values);
|
|
407
|
+
}
|
|
408
|
+
return values;
|
|
409
|
+
}
|
|
410
|
+
function getRouteLoaderPromises(requestEv6) {
|
|
411
|
+
let promises = requestEv6.sharedMap.get(REQUEST_ROUTE_LOADER_PROMISES);
|
|
412
|
+
if (!promises) {
|
|
413
|
+
promises = {};
|
|
414
|
+
requestEv6.sharedMap.set(REQUEST_ROUTE_LOADER_PROMISES, promises);
|
|
415
|
+
}
|
|
416
|
+
return promises;
|
|
417
|
+
}
|
|
418
|
+
/** Clear loader state before rendering a route-independent error boundary. */
|
|
419
|
+
function clearRouteLoaderData(requestEv7) {
|
|
420
|
+
requestEv7.sharedMap.delete(REQUEST_ROUTE_LOADER_STATE);
|
|
421
|
+
requestEv7.sharedMap.delete(REQUEST_ROUTE_LOADER_VALUES);
|
|
422
|
+
requestEv7.sharedMap.delete(REQUEST_ROUTE_LOADER_PROMISES);
|
|
423
|
+
requestEv7.sharedMap.delete(REQUEST_ROUTE_LOADER_EVENTS);
|
|
424
|
+
requestEv7.sharedMap.delete(REQUEST_ROUTE_LOADER_ROOT_EVENT);
|
|
425
|
+
requestEv7.sharedMap.delete(REQUEST_ROUTE_LOADERS);
|
|
426
|
+
}
|
|
427
|
+
/** Store the route loader internals on the request for SSG to read. */
|
|
428
|
+
function setRouteLoaders(requestEv8, loaders) {
|
|
429
|
+
requestEv8.sharedMap.set(REQUEST_ROUTE_LOADERS, loaders);
|
|
430
|
+
}
|
|
431
|
+
/** Get the route loader internals stored on the request. */
|
|
432
|
+
function getRouteLoaders(requestEv9) {
|
|
433
|
+
return requestEv9.sharedMap.get(REQUEST_ROUTE_LOADERS) ?? [];
|
|
434
|
+
}
|
|
435
|
+
function getRouteLoaderCtx(requestEv10) {
|
|
436
|
+
let ctx = requestEv10.sharedMap.get(REQUEST_LOADER_PATHS_STORE);
|
|
437
|
+
if (!ctx) {
|
|
438
|
+
ctx = { loaderPaths: {} };
|
|
439
|
+
requestEv10.sharedMap.set(REQUEST_LOADER_PATHS_STORE, ctx);
|
|
440
|
+
}
|
|
441
|
+
return ctx;
|
|
442
|
+
}
|
|
443
|
+
/** Server-only loader ID → params matched at its loader path; never serialized to the client. */
|
|
444
|
+
function getRouteLoaderParams(requestEv11) {
|
|
445
|
+
let params = requestEv11.sharedMap.get(REQUEST_LOADER_PARAMS_STORE);
|
|
446
|
+
if (!params) {
|
|
447
|
+
params = {};
|
|
448
|
+
requestEv11.sharedMap.set(REQUEST_LOADER_PARAMS_STORE, params);
|
|
449
|
+
}
|
|
450
|
+
return params;
|
|
451
|
+
}
|
|
452
|
+
var getModuleRouteLoaders = (mods) => {
|
|
453
|
+
const routeLoaders = [];
|
|
454
|
+
const seen = /* @__PURE__ */ new Map();
|
|
455
|
+
for (let i = 0; i < mods.length; i++) {
|
|
456
|
+
const mod = mods[i];
|
|
457
|
+
if (!mod) continue;
|
|
458
|
+
for (const key in mod) {
|
|
459
|
+
const value = mod[key];
|
|
460
|
+
if (isLoaderInternal(value)) {
|
|
461
|
+
const existing = seen.get(value.__id);
|
|
462
|
+
if (existing) {
|
|
463
|
+
if (isDev && existing !== value) console.warn(`Two route loaders share the same id "${value.__id}". Only the first will run; the others are ignored. If they are created by a shared wrapper around routeLoader$, give each loader a distinct \`id\` option.`);
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
seen.set(value.__id, value);
|
|
467
|
+
routeLoaders.push(value);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return routeLoaders;
|
|
472
|
+
};
|
|
473
|
+
/**
|
|
474
|
+
* Loader ids declared `cacheControl: 'immutable'`. Their data cannot change until a rebuild, so
|
|
475
|
+
* navigation skips them unless their request inputs change. Registered on every nav via
|
|
476
|
+
* ensureRouteLoaderSignal, so resumed signals are covered too.
|
|
477
|
+
*/
|
|
478
|
+
var immutableLoaderIds = /* @__PURE__ */ new Set();
|
|
479
|
+
var isImmutableLoader = (loaderId) => immutableLoaderIds.has(loaderId);
|
|
480
|
+
function abortRouteLoaderNavigation(ctx) {
|
|
481
|
+
for (const [signal, request] of clientRouteLoaders.get(ctx)?.current.requests ?? []) {
|
|
482
|
+
if (signal.untrackedPending) request.isAborted = true;
|
|
483
|
+
signal.abort();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
/** Search-filtered loaders ignore changes to unlisted params. */
|
|
487
|
+
function hasSameListedSearch(previous, next, search) {
|
|
488
|
+
return !!search && previous.pathname === next.pathname && filterSearchParams(previous.searchParams, search) === filterSearchParams(next.searchParams, search);
|
|
489
|
+
}
|
|
490
|
+
function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navCount, forceIds, navigationKey) {
|
|
491
|
+
const client = getClientRouteLoaders(ctx, previousUrl.href);
|
|
492
|
+
if (navigationKey && client.navigationKey === navigationKey) return ensureRouteLoaderSignals(mods, state, ctx);
|
|
493
|
+
const previous = client.current;
|
|
494
|
+
if (client.navCount === void 0) {
|
|
495
|
+
for (const id in state) if (!id.startsWith(ROUTE_LOADER_VALUE_PREFIX)) getLoaderRequest(ctx, state, id, id);
|
|
496
|
+
}
|
|
497
|
+
client.navCount = navCount;
|
|
498
|
+
client.navigationKey = navigationKey;
|
|
499
|
+
const current = client.current = {
|
|
500
|
+
requests: /* @__PURE__ */ new Map(),
|
|
501
|
+
paths: { ...paths },
|
|
502
|
+
pageUrl: pageUrl.href
|
|
503
|
+
};
|
|
504
|
+
const loaders = ensureRouteLoaderSignals(mods, state, ctx);
|
|
505
|
+
const routeLoaders = /* @__PURE__ */ new Map();
|
|
506
|
+
for (const loader of loaders) {
|
|
507
|
+
routeLoaders.set(loader.__id, loader);
|
|
508
|
+
current.paths[loader.__id] ||= current.paths[loader.__qrl.getHash()] || pageUrl.pathname;
|
|
509
|
+
}
|
|
510
|
+
for (const id in state) {
|
|
511
|
+
if (id.startsWith(ROUTE_LOADER_VALUE_PREFIX)) continue;
|
|
512
|
+
const signal = state[id];
|
|
513
|
+
const old = previous.requests.get(signal);
|
|
514
|
+
const loader = routeLoaders.get(id);
|
|
515
|
+
const hash3 = loader?.__qrl.getHash() || old?.hash;
|
|
516
|
+
const routePath = current.paths[id] || hash3 && current.paths[hash3];
|
|
517
|
+
if (!routePath) {
|
|
518
|
+
if (old) current.requests.set(signal, {
|
|
519
|
+
...old,
|
|
520
|
+
active: false
|
|
521
|
+
});
|
|
522
|
+
signal.abort();
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
const keepRequest = old?.active && !old.isAborted && old.routePath === routePath && (old.pageUrl === pageUrl.href ? isImmutableLoader(id) : hasSameListedSearch(new URL(old.pageUrl), pageUrl, loader?.__search));
|
|
526
|
+
current.requests.set(signal, keepRequest ? old : {
|
|
527
|
+
routePath,
|
|
528
|
+
pageUrl: pageUrl.href,
|
|
529
|
+
active: true,
|
|
530
|
+
hash: hash3
|
|
531
|
+
});
|
|
532
|
+
ctx.loaderPaths[id] = routePath;
|
|
533
|
+
if (forceIds === null || forceIds?.some((value) => value === id || value === hash3)) signal.invalidate(true);
|
|
534
|
+
else if (old && !keepRequest) signal.invalidate();
|
|
535
|
+
}
|
|
536
|
+
return loaders;
|
|
537
|
+
}
|
|
538
|
+
function pruneRouteLoaders(state, ctx) {
|
|
539
|
+
const { requests } = clientRouteLoaders.get(ctx).current;
|
|
540
|
+
const paths = {};
|
|
541
|
+
for (const id in state) {
|
|
542
|
+
if (id.startsWith(ROUTE_LOADER_VALUE_PREFIX)) continue;
|
|
543
|
+
const signal = state[id];
|
|
544
|
+
const request = requests.get(signal);
|
|
545
|
+
if (request?.active) paths[id] = request.routePath;
|
|
546
|
+
else {
|
|
547
|
+
signal.$dispose();
|
|
548
|
+
requests.delete(signal);
|
|
549
|
+
delete state[id];
|
|
550
|
+
delete state[getRouteLoaderValueStateKey(id)];
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
ctx.loaderPaths = paths;
|
|
554
|
+
}
|
|
555
|
+
function commitRouteLoaders(state, ctx, navCount) {
|
|
556
|
+
const client = clientRouteLoaders.get(ctx);
|
|
557
|
+
if (!client || client.navCount !== navCount) return;
|
|
558
|
+
pruneRouteLoaders(state, ctx);
|
|
559
|
+
client.committed = client.current;
|
|
560
|
+
}
|
|
561
|
+
function restoreRouteLoaders(state, ctx, navCount) {
|
|
562
|
+
const client = clientRouteLoaders.get(ctx);
|
|
563
|
+
if (!client || client.navCount !== navCount) return;
|
|
564
|
+
client.navigationKey = void 0;
|
|
565
|
+
client.current = client.committed;
|
|
566
|
+
pruneRouteLoaders(state, ctx);
|
|
567
|
+
for (const signal of client.current.requests.keys()) signal.invalidate();
|
|
568
|
+
}
|
|
569
|
+
var ensureRouteLoaderSignal = (loader, state, routeLoaderCtx, requestEv12) => {
|
|
570
|
+
if (loader.__cacheControl === "immutable") immutableLoaderIds.add(loader.__id);
|
|
571
|
+
if (isServer && loader.__serializationStrategy === "never") state[getRouteLoaderValueStateKey(loader.__id)] = _UNINITIALIZED;
|
|
572
|
+
return state[loader.__id] ||= createRouteLoaderSignal(loader, routeLoaderCtx, state, requestEv12);
|
|
573
|
+
};
|
|
574
|
+
var ensureRouteLoaderSignals = (mods, state, routeLoaderCtx, requestEv13) => {
|
|
575
|
+
const loaders = getModuleRouteLoaders(mods);
|
|
576
|
+
for (let i = 0; i < loaders.length; i++) ensureRouteLoaderSignal(loaders[i], state, routeLoaderCtx, requestEv13);
|
|
577
|
+
return loaders;
|
|
578
|
+
};
|
|
579
|
+
/**
|
|
580
|
+
* Inject a pre-loaded value into a ComputedSignal while preserving subscriptions. Delegates to the
|
|
581
|
+
* core helper which calls `invalidate({__v})` + `$computeIfNeeded$()` so the compute function runs
|
|
582
|
+
* synchronously and returns the pre-loaded value without fetching. Must go through the core helper
|
|
583
|
+
* because `$computeIfNeeded$` is mangled in core builds and not directly callable from this
|
|
584
|
+
* package.
|
|
585
|
+
*/
|
|
586
|
+
var setLoaderSignalValue = (signal, value) => {
|
|
587
|
+
_injectAsyncSignalValue(signal, value);
|
|
588
|
+
};
|
|
589
|
+
var resolveRouteLoaderByHash = (routeLoaders, loaderId) => {
|
|
590
|
+
return routeLoaders.find((loader) => matchesRouteLoaderId(loader, loaderId));
|
|
591
|
+
};
|
|
592
|
+
var matchesRouteLoaderId = (loader, loaderId) => {
|
|
593
|
+
return typeof loaderId === "string" && (loader.__id === loaderId || isDev && loader.__qrl.getHash() === loaderId);
|
|
594
|
+
};
|
|
595
|
+
/** Run a loader and return its raw value. Errors/redirects propagate as exceptions. */
|
|
596
|
+
var getRouteLoaderData = async (loaderQrl, validators3, requestEv14) => {
|
|
597
|
+
const loaderRequestEv = requestEv14;
|
|
598
|
+
const result = await runValidators(requestEv14, validators3, void 0);
|
|
599
|
+
if (!result.success) return loaderRequestEv.fail(result.status ?? 500, result.error);
|
|
600
|
+
const resolved = await loaderQrl.call(loaderRequestEv, loaderRequestEv);
|
|
601
|
+
const value = typeof resolved === "function" ? resolved() : resolved;
|
|
602
|
+
throwIfControlFlowSignal(value);
|
|
603
|
+
if (isDev) verifySerializable(value, loaderQrl);
|
|
604
|
+
return value;
|
|
605
|
+
};
|
|
606
|
+
var loadRouteLoaderByQrl = (loaderId, loaderQrl, validators4, requestEv15) => {
|
|
607
|
+
const values = getRouteLoaderValues(requestEv15);
|
|
608
|
+
if (loaderId in values) return Promise.resolve(values[loaderId]);
|
|
609
|
+
const promises = getRouteLoaderPromises(requestEv15);
|
|
610
|
+
let promise = promises[loaderId];
|
|
611
|
+
if (!promise) {
|
|
612
|
+
promise = getRouteLoaderData(loaderQrl, validators4, requestEv15).then((value) => {
|
|
613
|
+
values[loaderId] = value;
|
|
614
|
+
return value;
|
|
615
|
+
}, (err) => {
|
|
616
|
+
delete promises[loaderId];
|
|
617
|
+
throw err;
|
|
618
|
+
});
|
|
619
|
+
promises[loaderId] = promise;
|
|
620
|
+
}
|
|
621
|
+
return promise;
|
|
622
|
+
};
|
|
623
|
+
/** @internal */
|
|
624
|
+
var getLoaderRequestEvent = (loader, requestEv16) => {
|
|
625
|
+
let rootRequestEv = requestEv16.sharedMap.get(REQUEST_ROUTE_LOADER_ROOT_EVENT);
|
|
626
|
+
if (!rootRequestEv) {
|
|
627
|
+
rootRequestEv = requestEv16;
|
|
628
|
+
requestEv16.sharedMap.set(REQUEST_ROUTE_LOADER_ROOT_EVENT, rootRequestEv);
|
|
629
|
+
}
|
|
630
|
+
const url = new URL(rootRequestEv.url);
|
|
631
|
+
const pathname = globalThis.__STRICT_LOADERS__ ? getRouteLoaderCtx(rootRequestEv).loaderPaths[loader.__id] || rootRequestEv.url.pathname : rootRequestEv.url.pathname;
|
|
632
|
+
const filteredSearch = loader.__search ? filterSearchParams(url.searchParams, loader.__search) : rootRequestEv.url.search;
|
|
633
|
+
if (pathname === rootRequestEv.url.pathname && filteredSearch === rootRequestEv.url.search) return rootRequestEv;
|
|
634
|
+
const params = pathname === rootRequestEv.url.pathname ? rootRequestEv.params : getRouteLoaderParams(rootRequestEv)[loader.__id] || {};
|
|
635
|
+
let events = rootRequestEv.sharedMap.get(REQUEST_ROUTE_LOADER_EVENTS);
|
|
636
|
+
if (!events) {
|
|
637
|
+
events = /* @__PURE__ */ new Map();
|
|
638
|
+
rootRequestEv.sharedMap.set(REQUEST_ROUTE_LOADER_EVENTS, events);
|
|
639
|
+
}
|
|
640
|
+
const eventKey = `${pathname}\n${filteredSearch}`;
|
|
641
|
+
let loaderRequestEv = events.get(eventKey);
|
|
642
|
+
if (!loaderRequestEv) {
|
|
643
|
+
url.pathname = pathname;
|
|
644
|
+
url.search = filteredSearch;
|
|
645
|
+
const request = new Request(url, rootRequestEv.request);
|
|
646
|
+
loaderRequestEv = Object.create(rootRequestEv, {
|
|
647
|
+
originalUrl: {
|
|
648
|
+
value: new URL(url),
|
|
649
|
+
enumerable: true
|
|
650
|
+
},
|
|
651
|
+
params: {
|
|
652
|
+
value: params,
|
|
653
|
+
enumerable: true
|
|
654
|
+
},
|
|
655
|
+
pathname: {
|
|
656
|
+
get: () => url.pathname,
|
|
657
|
+
enumerable: true
|
|
658
|
+
},
|
|
659
|
+
query: {
|
|
660
|
+
get: () => url.searchParams,
|
|
661
|
+
enumerable: true
|
|
662
|
+
},
|
|
663
|
+
request: {
|
|
664
|
+
value: request,
|
|
665
|
+
enumerable: true
|
|
666
|
+
},
|
|
667
|
+
url: {
|
|
668
|
+
value: url,
|
|
669
|
+
enumerable: true
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
events.set(eventKey, loaderRequestEv);
|
|
673
|
+
}
|
|
674
|
+
return loaderRequestEv;
|
|
675
|
+
};
|
|
676
|
+
/**
|
|
677
|
+
* View of a request event whose response controls (status/headers/redirect/error/fail/cacheControl)
|
|
678
|
+
* are captured locally, so a background (`blockSSR: false`) loader's status/redirect/error surfaces
|
|
679
|
+
* on its own signal instead of mutating the page response. The originals also call `check()`, which
|
|
680
|
+
* throws once SSR streaming has started — a background loader must fail on its signal, not crash.
|
|
681
|
+
*/
|
|
682
|
+
var detachResponseFromEvent = (requestEv17) => {
|
|
683
|
+
let status = 200;
|
|
684
|
+
const headers = new Headers();
|
|
685
|
+
return Object.create(requestEv17, {
|
|
686
|
+
headers: {
|
|
687
|
+
value: headers,
|
|
688
|
+
enumerable: true
|
|
689
|
+
},
|
|
690
|
+
status: {
|
|
691
|
+
value: (statusCode) => {
|
|
692
|
+
if (typeof statusCode === "number") status = statusCode;
|
|
693
|
+
return status;
|
|
694
|
+
},
|
|
695
|
+
enumerable: true
|
|
696
|
+
},
|
|
697
|
+
error: {
|
|
698
|
+
value: (statusCode, message) => {
|
|
699
|
+
status = statusCode;
|
|
700
|
+
return new ServerError(statusCode, message);
|
|
701
|
+
},
|
|
702
|
+
enumerable: true
|
|
703
|
+
},
|
|
704
|
+
redirect: {
|
|
705
|
+
value: (statusCode, url) => {
|
|
706
|
+
status = statusCode;
|
|
707
|
+
if (url) headers.set("Location", url);
|
|
708
|
+
return new RedirectMessage();
|
|
709
|
+
},
|
|
710
|
+
enumerable: true
|
|
711
|
+
},
|
|
712
|
+
fail: {
|
|
713
|
+
value: (statusCode, data) => {
|
|
714
|
+
status = statusCode;
|
|
715
|
+
return {
|
|
716
|
+
failed: true,
|
|
717
|
+
...data
|
|
718
|
+
};
|
|
719
|
+
},
|
|
720
|
+
enumerable: true
|
|
721
|
+
},
|
|
722
|
+
cacheControl: {
|
|
723
|
+
value: () => {},
|
|
724
|
+
enumerable: true
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
};
|
|
728
|
+
var loadRouteLoader = (loader, requestEv18) => {
|
|
729
|
+
const loaderEv = getLoaderRequestEvent(loader, requestEv18);
|
|
730
|
+
return loadRouteLoaderByQrl(loader.__id, loader.__qrl, loader.__validators, loader.__blockSSR ? loaderEv : detachResponseFromEvent(loaderEv));
|
|
731
|
+
};
|
|
732
|
+
/** Run a loader and wrap the result in a LoaderResponse envelope. Catches redirects/errors. */
|
|
733
|
+
var getRouteLoaderResponse = async (loaderQrl, validators5, requestEv19) => {
|
|
734
|
+
try {
|
|
735
|
+
return { d: await getRouteLoaderData(loaderQrl, validators5, requestEv19) };
|
|
736
|
+
} catch (err) {
|
|
737
|
+
if (err instanceof RedirectMessage) {
|
|
738
|
+
const location2 = requestEv19.headers.get("Location") || "/";
|
|
739
|
+
requestEv19.headers.delete("Location");
|
|
740
|
+
return { r: location2 };
|
|
741
|
+
}
|
|
742
|
+
if (err instanceof ServerError) return { e: err };
|
|
743
|
+
throw err;
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
/**
|
|
747
|
+
* A hoisted function declaration on purpose: the app's route modules call `routeLoaderQrl` at their
|
|
748
|
+
* own eval, and a bundle may execute them before this module, where a `const` binding would throw a
|
|
749
|
+
* TDZ ReferenceError.
|
|
750
|
+
*
|
|
751
|
+
* @internal
|
|
752
|
+
*/
|
|
753
|
+
function routeLoaderQrl(loaderQrl, ...rest) {
|
|
754
|
+
const { id, validators: validators6, serializationStrategy, cacheControl, eTag, cacheKey, search, blockSSR: blockSSR3 } = getLoaderOptions(rest);
|
|
755
|
+
function loader() {
|
|
756
|
+
const signal = ensureRouteLoaderSignal(loader, _resolveContextWithoutSequentialScope(RouteStateContext), _resolveContextWithoutSequentialScope(RouteLoaderCtxContext));
|
|
757
|
+
signal.promise();
|
|
758
|
+
return signal;
|
|
759
|
+
}
|
|
760
|
+
loader.__brand = "server_loader";
|
|
761
|
+
loader.__qrl = loaderQrl;
|
|
762
|
+
loader.__validators = validators6;
|
|
763
|
+
loader.__id = id ?? loaderQrl.getHash();
|
|
764
|
+
loader.__serializationStrategy = serializationStrategy;
|
|
765
|
+
loader.__cacheControl = cacheControl;
|
|
766
|
+
loader.__eTag = eTag;
|
|
767
|
+
loader.__cacheKey = cacheKey;
|
|
768
|
+
loader.__search = search;
|
|
769
|
+
loader.__blockSSR = blockSSR3;
|
|
770
|
+
Object.freeze(loader);
|
|
771
|
+
return loader;
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Define a route loader that fetches data before the route renders.
|
|
775
|
+
*
|
|
776
|
+
* Route loaders run on the server during SSR and return data as a `ComputedSignal`. On the client,
|
|
777
|
+
* loaders automatically re-fetch when the route changes (SPA navigation). Each loader gets its own
|
|
778
|
+
* JSON endpoint (`q-loader-{id}.{hash}.json`), so only the loaders present on the target route are
|
|
779
|
+
* fetched.
|
|
780
|
+
*
|
|
781
|
+
* **Important:** Route loader data uses Qwik's custom serialization format, not standard JSON. This
|
|
782
|
+
* means the data supports features like circular references, Dates, and other non-JSON types, but
|
|
783
|
+
* it cannot be consumed by external clients expecting plain JSON.
|
|
784
|
+
*
|
|
785
|
+
* ## Options
|
|
786
|
+
*
|
|
787
|
+
* - `search: string[]`: Allowlist of URL search params the loader depends on. Only listed params are
|
|
788
|
+
* sent in the request and changes to other params are ignored. During SSR and loader JSON
|
|
789
|
+
* requests, the loader's request event is filtered to those params too. `search: []` means no
|
|
790
|
+
* search params are sent and only route path changes trigger a re-fetch.
|
|
791
|
+
* - `eTag`: Enable ETag-based caching. Can be `true` (auto-hash), a string, or a function.
|
|
792
|
+
* - `cacheControl`: Cache-Control for loader JSON responses; the browser HTTP cache controls
|
|
793
|
+
* client-side freshness. `'immutable'` additionally lets SSG write the loader file.
|
|
794
|
+
*
|
|
795
|
+
* The `strictLoaders` Vite plugin option applies `search: []` globally for all loaders that don't
|
|
796
|
+
* specify an explicit `search` option.
|
|
797
|
+
*
|
|
798
|
+
* @public
|
|
799
|
+
*/
|
|
800
|
+
var routeLoader$ = /*#__PURE__*/ implicit$FirstArg(routeLoaderQrl);
|
|
801
|
+
async function runValidators(requestEv20, validators7, data) {
|
|
802
|
+
let lastResult = {
|
|
803
|
+
success: true,
|
|
804
|
+
data
|
|
805
|
+
};
|
|
806
|
+
if (validators7) for (let i = 0; i < validators7.length; i++) {
|
|
807
|
+
lastResult = await validators7[i].validate(requestEv20, data);
|
|
808
|
+
if (!lastResult.success) return lastResult;
|
|
809
|
+
data = lastResult.data;
|
|
810
|
+
}
|
|
811
|
+
return lastResult;
|
|
812
|
+
}
|
|
813
|
+
function verifySerializable(data, qrl2) {
|
|
814
|
+
try {
|
|
815
|
+
_verifySerializable(data, void 0);
|
|
816
|
+
} catch (error) {
|
|
817
|
+
if (error instanceof Error && qrl2.dev) error.loc = qrl2.dev;
|
|
818
|
+
throw error;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
var deepFreeze = (obj) => {
|
|
822
|
+
if (obj == null) return obj;
|
|
823
|
+
Object.getOwnPropertyNames(obj).forEach((prop) => {
|
|
824
|
+
const value = obj[prop];
|
|
825
|
+
if (value && typeof value === "object" && !Object.isFrozen(value)) try {
|
|
826
|
+
deepFreeze(value);
|
|
827
|
+
} catch {
|
|
828
|
+
return obj;
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
return Object.freeze(obj);
|
|
832
|
+
};
|
|
833
|
+
/** LoadRoute() runs in both client and server. */
|
|
834
|
+
var MODULE_CACHE = /*#__PURE__*/ new WeakMap();
|
|
835
|
+
var loadRoute = async (routes, cacheModules, pathname) => {
|
|
836
|
+
const { loaders, params, routeParts, notFound, routeBundleNames, loaderPathsByHash, loaderParamsByHash, menuLoader, errorLoader } = matchRouteTree(routes, pathname);
|
|
837
|
+
const routeName = "/" + routeParts.join("/");
|
|
838
|
+
const modules = new Array(loaders.length);
|
|
839
|
+
const pendingLoads = [];
|
|
840
|
+
for (let i = 0; i < loaders.length; i++) {
|
|
841
|
+
const moduleLoader = loaders[i];
|
|
842
|
+
loadModule(moduleLoader, pendingLoads, (routeModule) => modules[i] = routeModule, cacheModules);
|
|
843
|
+
}
|
|
844
|
+
let menu = void 0;
|
|
845
|
+
loadModule(menuLoader, pendingLoads, (menuModule) => menu = menuModule?.default, cacheModules);
|
|
846
|
+
if (pendingLoads.length > 0) await Promise.all(pendingLoads);
|
|
847
|
+
return {
|
|
848
|
+
$routeName$: routeName,
|
|
849
|
+
$params$: params,
|
|
850
|
+
$mods$: modules,
|
|
851
|
+
$menu$: deepFreeze(menu),
|
|
852
|
+
$routeBundleNames$: routeBundleNames,
|
|
853
|
+
$notFound$: notFound,
|
|
854
|
+
$errorLoader$: errorLoader,
|
|
855
|
+
$loaders$: loaderPathsByHash && Object.keys(loaderPathsByHash),
|
|
856
|
+
$loaderPaths$: loaderPathsByHash,
|
|
857
|
+
$loaderParams$: loaderParamsByHash
|
|
858
|
+
};
|
|
859
|
+
};
|
|
860
|
+
/** Built-in fallback error component loader */
|
|
861
|
+
var httpErrorLoader = (() => import("./http-error.qwik.mjs"));
|
|
862
|
+
/** Collect the rewrite target's layouts, loader endpoint paths, and params at those paths. */
|
|
863
|
+
function walkTrieKeys(root, keys, params) {
|
|
864
|
+
let node = root;
|
|
865
|
+
let pathname = "/";
|
|
866
|
+
let pathParams = {};
|
|
867
|
+
const layouts = [];
|
|
868
|
+
const loaderPaths = {};
|
|
869
|
+
const loaderParams = {};
|
|
870
|
+
const collect = (node) => {
|
|
871
|
+
if (node._L) layouts.push(node._L);
|
|
872
|
+
for (const hash of node._R ?? []) {
|
|
873
|
+
loaderPaths[hash] = pathname;
|
|
874
|
+
loaderParams[hash] = pathParams;
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
collect(root);
|
|
878
|
+
for (const key of keys) {
|
|
879
|
+
const match = descendGroups(node, (candidate) => candidate[key]);
|
|
880
|
+
if (!match) return;
|
|
881
|
+
for (const group of match.groups) collect(group);
|
|
882
|
+
node = match.value;
|
|
883
|
+
const segment = node._P ? `${node._0 ?? ""}${params[node._P] ?? ""}${node._9 ?? ""}` : unescapeStaticTrieKey(key);
|
|
884
|
+
const segments = key === "_A" ? segment.split("/") : [segment];
|
|
885
|
+
pathname = ensureSlash(pathname + segments.map(encodeURIComponent).join("/"));
|
|
886
|
+
if (node._P) pathParams = {
|
|
887
|
+
...pathParams,
|
|
888
|
+
[node._P]: params[node._P] ?? ""
|
|
889
|
+
};
|
|
890
|
+
collect(node);
|
|
891
|
+
}
|
|
892
|
+
if (!node._I && node._G == null) {
|
|
893
|
+
const index = findIndexNode(node);
|
|
894
|
+
if (index) {
|
|
895
|
+
for (const group of index.groups) collect(group);
|
|
896
|
+
node = index.target;
|
|
897
|
+
collect(node);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return {
|
|
901
|
+
node,
|
|
902
|
+
layouts,
|
|
903
|
+
loaderPaths,
|
|
904
|
+
loaderParams
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
/** Resolve the page and its modules, following rewrite targets. */
|
|
908
|
+
function resolveLoaders(root, node, gatheredLayouts, params) {
|
|
909
|
+
if (node._G != null) {
|
|
910
|
+
const target = walkTrieKeys(root, node._G.split("/").filter((p) => p.length > 0), params);
|
|
911
|
+
if (!target) return;
|
|
912
|
+
const resolved = resolveLoaders(root, target.node, target.layouts, params);
|
|
913
|
+
if (resolved && !resolved.loaderPaths) {
|
|
914
|
+
resolved.loaderPaths = target.loaderPaths;
|
|
915
|
+
resolved.loaderParams = target.loaderParams;
|
|
916
|
+
}
|
|
917
|
+
return resolved;
|
|
918
|
+
}
|
|
919
|
+
const index = node._I;
|
|
920
|
+
if (!index) return;
|
|
921
|
+
if (Array.isArray(index)) return {
|
|
922
|
+
loaders: index,
|
|
923
|
+
node
|
|
924
|
+
};
|
|
925
|
+
return {
|
|
926
|
+
loaders: [...gatheredLayouts, index],
|
|
927
|
+
node
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* The full chain to render for a boundary: a bare loader in its snapshot layouts, an override
|
|
932
|
+
* as-is.
|
|
933
|
+
*/
|
|
934
|
+
var boundaryChain = (ref) => ref.v ? Array.isArray(ref.v) ? ref.v : [...ref.layouts, ref.v] : void 0;
|
|
935
|
+
/**
|
|
936
|
+
* Collect layouts, the nearest error (`_E`) and not-found (`_4`) boundaries, and the menu from a
|
|
937
|
+
* node and the group ancestors entered to reach it.
|
|
938
|
+
*/
|
|
939
|
+
function collectNodeMeta(node, groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef, loaderPathsByHash, matchedPathname = "/", loaderParamsByHash, matchedParams = {}) {
|
|
940
|
+
for (let j = 0; j < groups.length; j++) {
|
|
941
|
+
const g = groups[j];
|
|
942
|
+
if (g._L) layouts.push(g._L);
|
|
943
|
+
if (g._R && loaderPathsByHash) for (const hash of g._R) {
|
|
944
|
+
loaderPathsByHash[hash] = matchedPathname;
|
|
945
|
+
if (loaderParamsByHash) loaderParamsByHash[hash] = matchedParams;
|
|
946
|
+
}
|
|
947
|
+
if (g._E) {
|
|
948
|
+
errorLoaderRef.v = g._E;
|
|
949
|
+
errorLoaderRef.layouts = [...layouts];
|
|
950
|
+
}
|
|
951
|
+
if (g._4) {
|
|
952
|
+
notFoundLoaderRef.v = g._4;
|
|
953
|
+
notFoundLoaderRef.layouts = [...layouts];
|
|
954
|
+
}
|
|
955
|
+
if (g._N) menuLoaderRef.v = g._N;
|
|
956
|
+
}
|
|
957
|
+
if (node._L) layouts.push(node._L);
|
|
958
|
+
if (node._R && loaderPathsByHash) for (const hash of node._R) {
|
|
959
|
+
loaderPathsByHash[hash] = matchedPathname;
|
|
960
|
+
if (loaderParamsByHash) loaderParamsByHash[hash] = matchedParams;
|
|
961
|
+
}
|
|
962
|
+
if (node._E) {
|
|
963
|
+
errorLoaderRef.v = node._E;
|
|
964
|
+
errorLoaderRef.layouts = [...layouts];
|
|
965
|
+
}
|
|
966
|
+
if (node._4) {
|
|
967
|
+
notFoundLoaderRef.v = node._4;
|
|
968
|
+
notFoundLoaderRef.layouts = [...layouts];
|
|
969
|
+
}
|
|
970
|
+
if (node._N) menuLoaderRef.v = node._N;
|
|
971
|
+
}
|
|
972
|
+
var ChildMatchKind = /* @__PURE__ */ function(ChildMatchKind) {
|
|
973
|
+
ChildMatchKind[ChildMatchKind["Exact"] = 0] = "Exact";
|
|
974
|
+
ChildMatchKind[ChildMatchKind["Wildcard"] = 1] = "Wildcard";
|
|
975
|
+
ChildMatchKind[ChildMatchKind["Rest"] = 2] = "Rest";
|
|
976
|
+
return ChildMatchKind;
|
|
977
|
+
}(ChildMatchKind || {});
|
|
978
|
+
/** The static child for a segment; inherited object properties (`constructor`, …) are not routes. */
|
|
979
|
+
function getStaticChild(node, partLower) {
|
|
980
|
+
const key = escapeStaticTrieKey(partLower);
|
|
981
|
+
if (!Object.prototype.hasOwnProperty.call(node, key)) return;
|
|
982
|
+
return node[key];
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* Try to find a child matching `partLower` in `node`, including inside group children (_M). Returns
|
|
986
|
+
* the matched child node, the groups entered to reach it, what to push to routeParts, and which
|
|
987
|
+
* kind of edge matched. Returns undefined if no match.
|
|
988
|
+
*
|
|
989
|
+
* Priority: exact match → _M groups (recursively) → _W wildcard → _A rest wildcard. This ensures
|
|
990
|
+
* exact matches inside nested groups take precedence over wildcards at parent level.
|
|
991
|
+
*/
|
|
992
|
+
function findChild(node, part, partLower, parts, partIndex) {
|
|
993
|
+
const exact = getStaticChild(node, partLower);
|
|
994
|
+
if (exact) return {
|
|
995
|
+
next: exact,
|
|
996
|
+
groups: [],
|
|
997
|
+
routePart: part,
|
|
998
|
+
done: false,
|
|
999
|
+
kind: ChildMatchKind.Exact
|
|
1000
|
+
};
|
|
1001
|
+
if (node._M) for (let j = 0; j < node._M.length; j++) {
|
|
1002
|
+
const group = node._M[j];
|
|
1003
|
+
const groupResult = findChild(group, part, partLower, parts, partIndex);
|
|
1004
|
+
if (groupResult) {
|
|
1005
|
+
groupResult.groups.unshift(group);
|
|
1006
|
+
return groupResult;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
const wildcard = tryWildcardMatch(node, part, partLower, parts, partIndex);
|
|
1010
|
+
if (wildcard) return {
|
|
1011
|
+
...wildcard,
|
|
1012
|
+
groups: []
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
/** Try to match a segment against a node's wildcard children (_W, _A). */
|
|
1016
|
+
function tryWildcardMatch(node, part, partLower, parts, partIndex) {
|
|
1017
|
+
return matchWildcardNode(node, part, partLower) ?? matchRestNode(node, parts, partIndex);
|
|
1018
|
+
}
|
|
1019
|
+
/** Try to match a segment against a node's `[param]` wildcard child (`_W`). */
|
|
1020
|
+
function matchWildcardNode(node, part, partLower) {
|
|
1021
|
+
const next = node._W;
|
|
1022
|
+
if (next) {
|
|
1023
|
+
const prefix = next._0;
|
|
1024
|
+
const suffix = next._9;
|
|
1025
|
+
if (prefix || suffix) {
|
|
1026
|
+
const pre = prefix || "";
|
|
1027
|
+
const suf = suffix || "";
|
|
1028
|
+
if (partLower.length > pre.length + suf.length && (!pre || partLower.startsWith(pre.toLowerCase())) && (!suf || partLower.endsWith(suf.toLowerCase()))) {
|
|
1029
|
+
const paramName = next._P;
|
|
1030
|
+
const value = part.slice(pre.length, suf ? part.length - suf.length : void 0);
|
|
1031
|
+
return {
|
|
1032
|
+
next,
|
|
1033
|
+
routePart: `${pre}[${paramName}]${suf}`,
|
|
1034
|
+
done: false,
|
|
1035
|
+
kind: ChildMatchKind.Wildcard,
|
|
1036
|
+
paramName,
|
|
1037
|
+
paramValue: value
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
} else {
|
|
1041
|
+
const paramName = next._P;
|
|
1042
|
+
return {
|
|
1043
|
+
next,
|
|
1044
|
+
routePart: `[${paramName}]`,
|
|
1045
|
+
done: false,
|
|
1046
|
+
kind: ChildMatchKind.Wildcard,
|
|
1047
|
+
paramName,
|
|
1048
|
+
paramValue: part
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
/** Try to match the remaining segments against a node's `[...param]` rest child (`_A`). */
|
|
1054
|
+
function matchRestNode(node, parts, partIndex) {
|
|
1055
|
+
const next = node._A;
|
|
1056
|
+
if (next) {
|
|
1057
|
+
const paramName = next._P;
|
|
1058
|
+
const restValue = parts.slice(partIndex).join("/");
|
|
1059
|
+
return {
|
|
1060
|
+
next,
|
|
1061
|
+
routePart: `[...${paramName}]`,
|
|
1062
|
+
done: true,
|
|
1063
|
+
kind: ChildMatchKind.Rest,
|
|
1064
|
+
paramName,
|
|
1065
|
+
paramValue: restValue
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Every child of `node` that could match `partLower`, in the same priority order `findChild` walks:
|
|
1071
|
+
* exact match → `_M` groups (recursively) → `_W` wildcard → `_A` rest wildcard.
|
|
1072
|
+
*
|
|
1073
|
+
* `findChild` stops at the first of these; this returns them all so the matcher can backtrack when
|
|
1074
|
+
* the highest-priority one dead-ends deeper in the trie.
|
|
1075
|
+
*/
|
|
1076
|
+
function findChildAll(node, part, partLower, parts, partIndex) {
|
|
1077
|
+
const candidates = [];
|
|
1078
|
+
const exact = getStaticChild(node, partLower);
|
|
1079
|
+
if (exact) candidates.push({
|
|
1080
|
+
next: exact,
|
|
1081
|
+
groups: [],
|
|
1082
|
+
routePart: part,
|
|
1083
|
+
done: false,
|
|
1084
|
+
kind: ChildMatchKind.Exact
|
|
1085
|
+
});
|
|
1086
|
+
if (node._M) for (let j = 0; j < node._M.length; j++) {
|
|
1087
|
+
const group = node._M[j];
|
|
1088
|
+
const groupCandidates = findChildAll(group, part, partLower, parts, partIndex);
|
|
1089
|
+
for (let k = 0; k < groupCandidates.length; k++) {
|
|
1090
|
+
const candidate = groupCandidates[k];
|
|
1091
|
+
candidates.push({
|
|
1092
|
+
...candidate,
|
|
1093
|
+
groups: [group, ...candidate.groups]
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
const wildcard = matchWildcardNode(node, part, partLower);
|
|
1098
|
+
if (wildcard) candidates.push({
|
|
1099
|
+
...wildcard,
|
|
1100
|
+
groups: []
|
|
1101
|
+
});
|
|
1102
|
+
const rest = matchRestNode(node, parts, partIndex);
|
|
1103
|
+
if (rest) candidates.push({
|
|
1104
|
+
...rest,
|
|
1105
|
+
groups: []
|
|
1106
|
+
});
|
|
1107
|
+
return candidates;
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Search for the most specific chain of child matches that consumes `parts` from `i` and lands on a
|
|
1111
|
+
* route. Chains rank segment by segment: a static segment beats a `[param]`, which beats a
|
|
1112
|
+
* `[...rest]`; ties go to the first in `findChild` order.
|
|
1113
|
+
*
|
|
1114
|
+
* Only chains strictly more specific than `toBeat` (the best tail found so far) are returned, so
|
|
1115
|
+
* branches that can no longer win are pruned. Returns undefined when nothing matches.
|
|
1116
|
+
*/
|
|
1117
|
+
function findMatchChain(node, parts, i, toBeat) {
|
|
1118
|
+
if (i === parts.length) return !toBeat && (findIndexNode(node) || findRestNode(node)) ? [] : void 0;
|
|
1119
|
+
const part = parts[i];
|
|
1120
|
+
const candidates = findChildAll(node, part, part.toLowerCase(), parts, i).sort((a, b) => a.kind - b.kind);
|
|
1121
|
+
let best;
|
|
1122
|
+
for (let c = 0; c < candidates.length; c++) {
|
|
1123
|
+
const found = candidates[c];
|
|
1124
|
+
const bound = best ?? toBeat;
|
|
1125
|
+
if (bound && found.kind > bound[0].kind) break;
|
|
1126
|
+
const tailToBeat = bound && found.kind === bound[0].kind ? bound.slice(1) : void 0;
|
|
1127
|
+
const tail = found.done ? matchRestTail(found.next, tailToBeat) : findMatchChain(found.next, parts, i + 1, tailToBeat);
|
|
1128
|
+
if (tail) best = [found, ...tail];
|
|
1129
|
+
}
|
|
1130
|
+
return best;
|
|
1131
|
+
}
|
|
1132
|
+
/** A `[...rest]` match ends the chain; it only counts when it has a page and beats the bound. */
|
|
1133
|
+
function matchRestTail(restNode, toBeat) {
|
|
1134
|
+
return !toBeat && isRouteNode(restNode) ? [] : void 0;
|
|
1135
|
+
}
|
|
1136
|
+
/** Whether a node renders something: a page (`_I`) or a rewrite (`_G`). */
|
|
1137
|
+
function isRouteNode(node) {
|
|
1138
|
+
return !!node._I || node._G != null;
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Descend through a node and its pathless `_M` groups (depth-first, in `_M` order), returning the
|
|
1142
|
+
* first node for which `hit` yields a value, plus the chain of groups entered to reach it. The
|
|
1143
|
+
* shared traversal behind the index / rest / boundary lookups inside groups.
|
|
1144
|
+
*/
|
|
1145
|
+
function descendGroups(node, hit) {
|
|
1146
|
+
const value = hit(node);
|
|
1147
|
+
if (value !== void 0) return {
|
|
1148
|
+
value,
|
|
1149
|
+
node,
|
|
1150
|
+
groups: []
|
|
1151
|
+
};
|
|
1152
|
+
if (node._M) for (let j = 0; j < node._M.length; j++) {
|
|
1153
|
+
const group = node._M[j];
|
|
1154
|
+
const result = descendGroups(group, hit);
|
|
1155
|
+
if (result) {
|
|
1156
|
+
result.groups.unshift(group);
|
|
1157
|
+
return result;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Find a node with `_I`/`_G` at the current level, including inside `_M` groups. Returns it and the
|
|
1163
|
+
* groups entered to reach it — excluding the target itself, whose `_L` the caller applies (so it
|
|
1164
|
+
* isn't double-counted).
|
|
1165
|
+
*/
|
|
1166
|
+
function findIndexNode(node) {
|
|
1167
|
+
const r = descendGroups(node, (n) => isRouteNode(n) ? n : void 0);
|
|
1168
|
+
return r ? {
|
|
1169
|
+
target: r.node,
|
|
1170
|
+
groups: r.groups.filter((g) => g !== r.node)
|
|
1171
|
+
} : void 0;
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Find a rest wildcard (`_A`) at the current node or inside its `_M` groups, with the groups
|
|
1175
|
+
* entered to reach it. Used to save fallback checkpoints during matching.
|
|
1176
|
+
*/
|
|
1177
|
+
function findRestNode(node) {
|
|
1178
|
+
const r = descendGroups(node, (n) => n._A);
|
|
1179
|
+
return r ? {
|
|
1180
|
+
next: r.value,
|
|
1181
|
+
groups: r.groups
|
|
1182
|
+
} : void 0;
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Find a `_4`/`_E` boundary inside a node's pathless `_M` groups (first in `_M` order), wrapped in
|
|
1186
|
+
* those groups' layouts.
|
|
1187
|
+
*/
|
|
1188
|
+
function findGroupBoundary(node, layouts, kind) {
|
|
1189
|
+
const r = descendGroups(node, (n) => n[kind]);
|
|
1190
|
+
if (!r) return;
|
|
1191
|
+
const groupLayouts = [...layouts];
|
|
1192
|
+
for (const g of r.groups) if (g._L) groupLayouts.push(g._L);
|
|
1193
|
+
return {
|
|
1194
|
+
v: r.value,
|
|
1195
|
+
layouts: groupLayouts
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Match a URL pathname against the route trie.
|
|
1200
|
+
*
|
|
1201
|
+
* Always returns a result. When no route matches, `notFound` is true and `loaders` contains only
|
|
1202
|
+
* the error component (from the nearest `_E` or `_4` ancestor, or the built-in fallback).
|
|
1203
|
+
*
|
|
1204
|
+
* Group nodes (in `_M` arrays) are pathless — they don't consume a URL segment but contribute their
|
|
1205
|
+
* `_L` layout to the chain. The matcher transparently enters groups when searching for a matching
|
|
1206
|
+
* child.
|
|
1207
|
+
*/
|
|
1208
|
+
function matchRouteTree(root = {}, pathname) {
|
|
1209
|
+
let node = root;
|
|
1210
|
+
const params = {};
|
|
1211
|
+
const routeParts = [];
|
|
1212
|
+
const layouts = [];
|
|
1213
|
+
const loaderPathsByHash = {};
|
|
1214
|
+
const loaderParamsByHash = {};
|
|
1215
|
+
const errorLoaderRef = {
|
|
1216
|
+
v: void 0,
|
|
1217
|
+
layouts: []
|
|
1218
|
+
};
|
|
1219
|
+
const notFoundLoaderRef = {
|
|
1220
|
+
v: void 0,
|
|
1221
|
+
layouts: []
|
|
1222
|
+
};
|
|
1223
|
+
const menuLoaderRef = { v: void 0 };
|
|
1224
|
+
const groupNodes = [];
|
|
1225
|
+
collectNodeMeta(root, [], layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef, loaderPathsByHash, "/", loaderParamsByHash);
|
|
1226
|
+
if (root._M) groupNodes.push({
|
|
1227
|
+
node: root,
|
|
1228
|
+
depth: layouts.length
|
|
1229
|
+
});
|
|
1230
|
+
let done = false;
|
|
1231
|
+
let matched = true;
|
|
1232
|
+
const parts = pathname.split("/").filter((p) => p.length > 0).map(decodeURIComponent);
|
|
1233
|
+
let restFallback;
|
|
1234
|
+
let i = 0;
|
|
1235
|
+
const len = parts.length;
|
|
1236
|
+
const chain = findMatchChain(root, parts, 0);
|
|
1237
|
+
for (; !done && i < len; i++) {
|
|
1238
|
+
const part = parts[i];
|
|
1239
|
+
const partLower = part.toLowerCase();
|
|
1240
|
+
const found = chain ? chain[i] : findChild(node, part, partLower, parts, i);
|
|
1241
|
+
if (!found) {
|
|
1242
|
+
matched = false;
|
|
1243
|
+
break;
|
|
1244
|
+
}
|
|
1245
|
+
const restInfo = found.kind === ChildMatchKind.Wildcard ? findRestNode(node) : void 0;
|
|
1246
|
+
if (restInfo) restFallback = {
|
|
1247
|
+
aNode: restInfo.next,
|
|
1248
|
+
groups: restInfo.groups,
|
|
1249
|
+
paramName: restInfo.next._P,
|
|
1250
|
+
restValue: parts.slice(i).join("/"),
|
|
1251
|
+
routeParts: [...routeParts],
|
|
1252
|
+
params: { ...params },
|
|
1253
|
+
layouts: [...layouts],
|
|
1254
|
+
loaderPathsByHash: { ...loaderPathsByHash },
|
|
1255
|
+
loaderParamsByHash: { ...loaderParamsByHash },
|
|
1256
|
+
errorLoader: errorLoaderRef.v,
|
|
1257
|
+
errorLayouts: errorLoaderRef.layouts,
|
|
1258
|
+
notFoundLoader: notFoundLoaderRef.v,
|
|
1259
|
+
notFoundLayouts: notFoundLoaderRef.layouts,
|
|
1260
|
+
menuLoader: menuLoaderRef.v
|
|
1261
|
+
};
|
|
1262
|
+
if (found.paramName) params[found.paramName] = found.paramValue;
|
|
1263
|
+
routeParts.push(found.routePart);
|
|
1264
|
+
done = found.done;
|
|
1265
|
+
node = found.next;
|
|
1266
|
+
const matchedPathname = `/${parts.slice(0, found.done ? len : i + 1).join("/")}/`;
|
|
1267
|
+
collectNodeMeta(node, found.groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef, loaderPathsByHash, matchedPathname, loaderParamsByHash, { ...params });
|
|
1268
|
+
if (node._M) groupNodes.push({
|
|
1269
|
+
node,
|
|
1270
|
+
depth: layouts.length
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
if (matched && !done && i === len) {
|
|
1274
|
+
if (!node._I && node._G == null) {
|
|
1275
|
+
const indexResult = findIndexNode(node);
|
|
1276
|
+
if (indexResult) {
|
|
1277
|
+
collectNodeMeta(indexResult.target, indexResult.groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef, loaderPathsByHash, pathname, loaderParamsByHash, { ...params });
|
|
1278
|
+
node = indexResult.target;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
if (!node._I && node._G == null) {
|
|
1282
|
+
const restInfo = findRestNode(node);
|
|
1283
|
+
if (restInfo) {
|
|
1284
|
+
const next = restInfo.next;
|
|
1285
|
+
const paramName = next._P;
|
|
1286
|
+
params[paramName] = "";
|
|
1287
|
+
routeParts.push(`[...${paramName}]`);
|
|
1288
|
+
collectNodeMeta(next, restInfo.groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef, loaderPathsByHash, pathname, loaderParamsByHash, { ...params });
|
|
1289
|
+
node = next;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
const resolved = matched && (done || i >= len) ? resolveLoaders(root, node, layouts, params) : void 0;
|
|
1294
|
+
const loaders = resolved?.loaders;
|
|
1295
|
+
if (!loaders && restFallback) {
|
|
1296
|
+
const fb = restFallback;
|
|
1297
|
+
const fbParams = {
|
|
1298
|
+
...fb.params,
|
|
1299
|
+
[fb.paramName]: fb.restValue
|
|
1300
|
+
};
|
|
1301
|
+
const fbRouteParts = [...fb.routeParts, `[...${fb.paramName}]`];
|
|
1302
|
+
const fbLayouts = [...fb.layouts];
|
|
1303
|
+
const fbLoaderPathsByHash = { ...fb.loaderPathsByHash };
|
|
1304
|
+
const fbLoaderParamsByHash = { ...fb.loaderParamsByHash };
|
|
1305
|
+
const fbErrorRef = {
|
|
1306
|
+
v: fb.errorLoader,
|
|
1307
|
+
layouts: fb.errorLayouts
|
|
1308
|
+
};
|
|
1309
|
+
const fbNotFoundRef = {
|
|
1310
|
+
v: fb.notFoundLoader,
|
|
1311
|
+
layouts: fb.notFoundLayouts
|
|
1312
|
+
};
|
|
1313
|
+
const fbMenuRef = { v: fb.menuLoader };
|
|
1314
|
+
collectNodeMeta(fb.aNode, fb.groups, fbLayouts, fbErrorRef, fbNotFoundRef, fbMenuRef, fbLoaderPathsByHash, pathname, fbLoaderParamsByHash, fbParams);
|
|
1315
|
+
const fallback = resolveLoaders(root, fb.aNode, fbLayouts, fbParams);
|
|
1316
|
+
if (fallback) {
|
|
1317
|
+
collectPageLoaders(fallback, fbLoaderPathsByHash, fbLoaderParamsByHash, pathname, fbParams);
|
|
1318
|
+
return {
|
|
1319
|
+
loaders: fallback.loaders,
|
|
1320
|
+
params: fbParams,
|
|
1321
|
+
routeParts: fbRouteParts,
|
|
1322
|
+
notFound: false,
|
|
1323
|
+
routeBundleNames: fb.aNode._B,
|
|
1324
|
+
loaderPathsByHash: Object.keys(fbLoaderPathsByHash).length > 0 ? fbLoaderPathsByHash : void 0,
|
|
1325
|
+
loaderParamsByHash: Object.keys(fbLoaderParamsByHash).length > 0 ? fbLoaderParamsByHash : void 0,
|
|
1326
|
+
menuLoader: fbMenuRef.v,
|
|
1327
|
+
errorLoader: boundaryChain(fbErrorRef)
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
errorLoaderRef.v = fbErrorRef.v;
|
|
1331
|
+
errorLoaderRef.layouts = fbErrorRef.layouts;
|
|
1332
|
+
notFoundLoaderRef.v = fbNotFoundRef.v;
|
|
1333
|
+
notFoundLoaderRef.layouts = fbNotFoundRef.layouts;
|
|
1334
|
+
menuLoaderRef.v = fbMenuRef.v;
|
|
1335
|
+
}
|
|
1336
|
+
if (!loaders) {
|
|
1337
|
+
const recover = (kind) => {
|
|
1338
|
+
for (let k = groupNodes.length - 1; k >= 0; k--) {
|
|
1339
|
+
const found = findGroupBoundary(groupNodes[k].node, layouts.slice(0, groupNodes[k].depth), kind);
|
|
1340
|
+
if (found) return found;
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
if (!notFoundLoaderRef.v) {
|
|
1344
|
+
const g = recover("_4");
|
|
1345
|
+
if (g) {
|
|
1346
|
+
notFoundLoaderRef.v = g.v;
|
|
1347
|
+
notFoundLoaderRef.layouts = g.layouts;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
if (!errorLoaderRef.v) {
|
|
1351
|
+
const g = recover("_E");
|
|
1352
|
+
if (g) {
|
|
1353
|
+
errorLoaderRef.v = g.v;
|
|
1354
|
+
errorLoaderRef.layouts = g.layouts;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
const ref = notFoundLoaderRef.v ? notFoundLoaderRef : errorLoaderRef.v ? errorLoaderRef : null;
|
|
1358
|
+
const boundary = ref?.v ?? httpErrorLoader;
|
|
1359
|
+
const boundaryLayouts = ref ? ref.layouts : layouts;
|
|
1360
|
+
return {
|
|
1361
|
+
loaders: Array.isArray(boundary) ? boundary : [...boundaryLayouts, boundary],
|
|
1362
|
+
params,
|
|
1363
|
+
routeParts,
|
|
1364
|
+
notFound: true,
|
|
1365
|
+
routeBundleNames: void 0,
|
|
1366
|
+
loaderPathsByHash: void 0,
|
|
1367
|
+
loaderParamsByHash: void 0,
|
|
1368
|
+
menuLoader: menuLoaderRef.v,
|
|
1369
|
+
errorLoader: boundaryChain(errorLoaderRef)
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
collectPageLoaders(resolved, loaderPathsByHash, loaderParamsByHash, pathname, params);
|
|
1373
|
+
return {
|
|
1374
|
+
loaders,
|
|
1375
|
+
params,
|
|
1376
|
+
routeParts,
|
|
1377
|
+
notFound: false,
|
|
1378
|
+
routeBundleNames: node._B,
|
|
1379
|
+
loaderPathsByHash: Object.keys(loaderPathsByHash).length > 0 ? loaderPathsByHash : void 0,
|
|
1380
|
+
loaderParamsByHash: Object.keys(loaderParamsByHash).length > 0 ? loaderParamsByHash : void 0,
|
|
1381
|
+
menuLoader: menuLoaderRef.v,
|
|
1382
|
+
errorLoader: boundaryChain(errorLoaderRef)
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
var loadModule = (moduleLoader, pendingLoads, moduleSetter, cacheModules) => {
|
|
1386
|
+
if (typeof moduleLoader === "function") {
|
|
1387
|
+
const loadedModule = MODULE_CACHE.get(moduleLoader);
|
|
1388
|
+
if (loadedModule) moduleSetter(loadedModule);
|
|
1389
|
+
else {
|
|
1390
|
+
const moduleOrPromise = moduleLoader();
|
|
1391
|
+
if (typeof moduleOrPromise.then === "function") pendingLoads.push(moduleOrPromise.then((loadedModule) => {
|
|
1392
|
+
if (cacheModules !== false) MODULE_CACHE.set(moduleLoader, loadedModule);
|
|
1393
|
+
moduleSetter(loadedModule);
|
|
1394
|
+
}));
|
|
1395
|
+
else if (moduleOrPromise) moduleSetter(moduleOrPromise);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
function collectPageLoaders({ node, loaderPaths, loaderParams }, paths, pathParams, pathname, params) {
|
|
1400
|
+
if (loaderPaths) {
|
|
1401
|
+
for (const hash in paths) {
|
|
1402
|
+
delete paths[hash];
|
|
1403
|
+
delete pathParams[hash];
|
|
1404
|
+
}
|
|
1405
|
+
Object.assign(paths, loaderPaths);
|
|
1406
|
+
Object.assign(pathParams, loaderParams);
|
|
1407
|
+
}
|
|
1408
|
+
const pageHashes = node._D ?? [];
|
|
1409
|
+
if (Array.isArray(node._I)) {
|
|
1410
|
+
for (const hash in paths) if (!pageHashes.includes(hash)) {
|
|
1411
|
+
delete paths[hash];
|
|
1412
|
+
delete pathParams[hash];
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
for (const hash of pageHashes) if (!paths[hash]) {
|
|
1416
|
+
paths[hash] = ensureSlash(pathname);
|
|
1417
|
+
pathParams[hash] = { ...params };
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
/** Gets an absolute url path string (url.pathname + url.search + url.hash) */
|
|
1421
|
+
var toPath = (url) => url.pathname + url.search + url.hash;
|
|
1422
|
+
/** Create a URL from a string and baseUrl */
|
|
1423
|
+
var toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
|
|
1424
|
+
/** Checks only if the origins are the same. */
|
|
1425
|
+
var isSameOrigin = (a, b) => a.origin === b.origin;
|
|
1426
|
+
/** Checks only if the pathnames are the same for the URLs (doesn't include search and hash) */
|
|
1427
|
+
var isSamePathname = ({ pathname: a }, { pathname: b }) => {
|
|
1428
|
+
const lDiff = Math.abs(a.length - b.length);
|
|
1429
|
+
return lDiff === 0 ? a === b : lDiff === 1 && ensureSlash(a) === ensureSlash(b);
|
|
1430
|
+
};
|
|
1431
|
+
/** Checks only if the search query strings are the same for the URLs */
|
|
1432
|
+
var isSameSearchQuery = (a, b) => a.search === b.search;
|
|
1433
|
+
/** Checks only if the pathname + search are the same for the URLs. */
|
|
1434
|
+
var isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
|
|
1435
|
+
var getClientNavPath = (props, baseUrl) => {
|
|
1436
|
+
const href = props.href;
|
|
1437
|
+
if (typeof href === "string" && typeof props.target !== "string" && !props.reload) try {
|
|
1438
|
+
const linkUrl = toUrl(href.trim(), baseUrl.url);
|
|
1439
|
+
if (isSameOrigin(linkUrl, toUrl("", baseUrl.url))) return toPath(linkUrl);
|
|
1440
|
+
} catch (e) {
|
|
1441
|
+
console.error(e);
|
|
1442
|
+
}
|
|
1443
|
+
else if (props.reload) return toPath(toUrl("", baseUrl.url));
|
|
1444
|
+
return null;
|
|
1445
|
+
};
|
|
1446
|
+
var shouldPreload = (clientNavPath, currentLoc) => {
|
|
1447
|
+
if (clientNavPath) return !isSamePathname(toUrl(clientNavPath, currentLoc.url), toUrl("", currentLoc.url));
|
|
1448
|
+
return false;
|
|
1449
|
+
};
|
|
1450
|
+
var isPromise = (value) => {
|
|
1451
|
+
return value && typeof value.then === "function";
|
|
1452
|
+
};
|
|
1453
|
+
/**
|
|
1454
|
+
* Resolve the full route config (head + eTag + cacheKey) from all content modules. Uses the same
|
|
1455
|
+
* resolution rules as DocumentHead: objects are merged immediately, functions are queued and
|
|
1456
|
+
* executed inner-before-outer.
|
|
1457
|
+
*/
|
|
1458
|
+
var resolveRouteConfig = (resolveValue, routeLocation, contentModules, locale, status, defaults) => withLocale(locale, () => {
|
|
1459
|
+
const head = createDocumentHead(defaults);
|
|
1460
|
+
let eTag;
|
|
1461
|
+
let cacheKey;
|
|
1462
|
+
const fns = [];
|
|
1463
|
+
for (let i = 0; i < contentModules.length; i++) {
|
|
1464
|
+
const contentModule = contentModules[i];
|
|
1465
|
+
if (!contentModule) continue;
|
|
1466
|
+
const isLast = i === contentModules.length - 1;
|
|
1467
|
+
let config;
|
|
1468
|
+
if (contentModule.routeConfig) config = contentModule.routeConfig;
|
|
1469
|
+
else if (contentModule.head) {
|
|
1470
|
+
const synthetic = { head: void 0 };
|
|
1471
|
+
const headExport = contentModule.head;
|
|
1472
|
+
if (typeof headExport === "function") {
|
|
1473
|
+
const mod = contentModule;
|
|
1474
|
+
config = (props) => ({
|
|
1475
|
+
head: headExport(props),
|
|
1476
|
+
eTag: mod.eTag,
|
|
1477
|
+
cacheKey: mod.cacheKey
|
|
1478
|
+
});
|
|
1479
|
+
} else {
|
|
1480
|
+
synthetic.head = headExport;
|
|
1481
|
+
const mod = contentModule;
|
|
1482
|
+
if (mod.eTag !== void 0) synthetic.eTag = mod.eTag;
|
|
1483
|
+
if (mod.cacheKey !== void 0) synthetic.cacheKey = mod.cacheKey;
|
|
1484
|
+
config = synthetic;
|
|
1485
|
+
}
|
|
1486
|
+
} else {
|
|
1487
|
+
const mod = contentModule;
|
|
1488
|
+
if (mod.eTag !== void 0 || mod.cacheKey !== void 0) config = {
|
|
1489
|
+
eTag: mod.eTag,
|
|
1490
|
+
cacheKey: mod.cacheKey
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
if (!config) continue;
|
|
1494
|
+
if (typeof config === "function") fns.unshift({
|
|
1495
|
+
fn: config,
|
|
1496
|
+
isLast
|
|
1497
|
+
});
|
|
1498
|
+
else {
|
|
1499
|
+
if (config.head) resolveDocumentHead(head, config.head);
|
|
1500
|
+
if (config.eTag !== void 0) eTag = config.eTag;
|
|
1501
|
+
if (config.cacheKey !== void 0) cacheKey = config.cacheKey;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
if (fns.length) {
|
|
1505
|
+
const headProps = {
|
|
1506
|
+
head,
|
|
1507
|
+
status,
|
|
1508
|
+
withLocale: (fn) => fn(),
|
|
1509
|
+
resolveValue,
|
|
1510
|
+
...routeLocation
|
|
1511
|
+
};
|
|
1512
|
+
for (const { fn } of fns) {
|
|
1513
|
+
const result = fn(headProps);
|
|
1514
|
+
if (result.head) resolveDocumentHead(head, result.head);
|
|
1515
|
+
if (result.eTag !== void 0) eTag = result.eTag;
|
|
1516
|
+
if (result.cacheKey !== void 0) cacheKey = result.cacheKey;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return {
|
|
1520
|
+
head,
|
|
1521
|
+
eTag,
|
|
1522
|
+
cacheKey
|
|
1523
|
+
};
|
|
1524
|
+
});
|
|
1525
|
+
/**
|
|
1526
|
+
* Resolve only the document head from all content modules. This is the browser-side entry point
|
|
1527
|
+
* that ignores eTag/cacheKey (server-only concerns).
|
|
1528
|
+
*
|
|
1529
|
+
* Signal values may throw a promise on the client when still loading — callers should wrap this in
|
|
1530
|
+
* `retryOnPromise` to handle that.
|
|
1531
|
+
*/
|
|
1532
|
+
var resolveHead = (actionData, loaderState, routeLocation, contentModules, locale, defaults) => {
|
|
1533
|
+
const getData = ((loaderOrAction) => {
|
|
1534
|
+
const id = loaderOrAction.__id;
|
|
1535
|
+
const signal = loaderState?.[id];
|
|
1536
|
+
if (signal) return signal.value;
|
|
1537
|
+
if (actionData?.action === id) return actionData.actionResult;
|
|
1538
|
+
});
|
|
1539
|
+
return resolveRouteConfig(getData, routeLocation, contentModules, locale, actionData?.status ?? 200, defaults).head;
|
|
1540
|
+
};
|
|
1541
|
+
var resolveDocumentHead = (resolvedHead, updatedHead) => {
|
|
1542
|
+
if (typeof updatedHead.title === "string") resolvedHead.title = updatedHead.title;
|
|
1543
|
+
mergeArray(resolvedHead.meta, updatedHead.meta);
|
|
1544
|
+
mergeArray(resolvedHead.links, updatedHead.links);
|
|
1545
|
+
mergeArray(resolvedHead.styles, updatedHead.styles);
|
|
1546
|
+
mergeArray(resolvedHead.scripts, updatedHead.scripts);
|
|
1547
|
+
Object.assign(resolvedHead.frontmatter, updatedHead.frontmatter);
|
|
1548
|
+
};
|
|
1549
|
+
var mergeArray = (existingArr, newArr) => {
|
|
1550
|
+
if (Array.isArray(newArr)) for (const newItem of newArr) {
|
|
1551
|
+
if (typeof newItem.key === "string") {
|
|
1552
|
+
const existingIndex = existingArr.findIndex((i) => i.key === newItem.key);
|
|
1553
|
+
if (existingIndex > -1) {
|
|
1554
|
+
existingArr[existingIndex] = newItem;
|
|
1555
|
+
continue;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
existingArr.push(newItem);
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
var createDocumentHead = (defaults, manifestHash) => ({
|
|
1562
|
+
title: defaults?.title || "",
|
|
1563
|
+
meta: [...defaults?.meta || []],
|
|
1564
|
+
links: [...defaults?.links || []],
|
|
1565
|
+
styles: [...defaults?.styles || []],
|
|
1566
|
+
scripts: [...defaults?.scripts || []],
|
|
1567
|
+
frontmatter: { ...defaults?.frontmatter },
|
|
1568
|
+
manifestHash: manifestHash || "dev"
|
|
1569
|
+
});
|
|
1570
|
+
export { RoutePreventNavigateContext as $, loadRouteLoader as A, _setRouterConfig as B, getRequestEvent as C, getRouteLoaderValues as D, getRouteLoaderResponse as E, routeLoader$ as F, ContentContext as G, getRouterConfig as H, routeLoaderQrl as I, HttpStatusContext as J, ContentInternalContext as K, setLoaderSignalValue as L, prepareRouteLoaders as M, resolveRouteLoaderByHash as N, getRouteLoaders as O, restoreRouteLoaders as P, RouteNavigateContext as Q, setRouteLoaders as R, getModuleRouteLoaders as S, getRouteLoaderParams as T, getRoutes as U, getBasePathname as V, getTrailingSlash as W, RouteLoaderCtxContext as X, RouteActionContext as Y, RouteLocationContext as Z, commitRouteLoaders as _, isPromise as a, RequestEvRouterConfig as at, getClientRouteLoaders as b, shouldPreload as c, loadRoute as d, RouteStateContext as et, FULLPATH_HEADER as f, clearRouteLoaderData as g, clearNavFetchCache as h, getClientNavPath as i, Q_ROUTE as it, matchesRouteLoaderId as j, isImmutableLoader as k, toPath as l, abortRouteLoaderNavigation as m, resolveHead as n, QDATA_KEY as nt, isSameOrigin as o, _asyncRequestStore as ot, ROUTE_PATH_HEADER as p, DocumentHeadContext as q, resolveRouteConfig as r, QFN_KEY as rt, isSamePath as s, createDocumentHead as t, QACTION_KEY as tt, toUrl as u, ensureRouteLoaderSignals as v, getRouteLoaderCtx as w, getLoaderRequestEvent as x, fetchRouteLoaderData as y, _getServiceWorkerUrl as z };
|