@qwik.dev/router 2.0.0-rc.5 → 2.0.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters/cloudflare-pages/vite/index.mjs +1 -1
- package/lib/adapters/shared/vite/index.mjs +78 -61
- package/lib/chunks/fs.mjs +1 -1
- package/lib/chunks/head.qwik.mjs +73 -51
- package/lib/chunks/pathname.mjs +1 -0
- package/lib/chunks/system.mjs +2 -2
- package/lib/chunks/user-response.mjs +37 -11
- package/lib/chunks/worker-thread.mjs +3 -3
- package/lib/index.d.ts +3 -1
- package/lib/index.qwik.mjs +104 -48
- package/lib/middleware/bun/index.mjs +1 -1
- package/lib/middleware/deno/index.mjs +1 -1
- package/lib/middleware/node/index.mjs +1 -1
- package/lib/middleware/request-handler/index.mjs +3 -3
- package/lib/ssg/index.mjs +1 -1
- package/lib/vite/index.d.ts +1 -1
- package/lib/vite/index.mjs +61 -16
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { y as normalizePathSlash } from "../../../chunks/fs.mjs";
|
|
1
2
|
import { t as ensureSlash } from "../../../chunks/pathname.mjs";
|
|
2
3
|
import { viteAdapter } from "../../shared/vite/index.mjs";
|
|
3
|
-
import { y as normalizePathSlash } from "../../../chunks/fs.mjs";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import { join, relative } from "node:path";
|
|
6
6
|
/** @public */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as ensureSlash } from "../../../chunks/pathname.mjs";
|
|
2
1
|
import { i as LOADER_REGEX } from "../../../chunks/request-path.mjs";
|
|
2
|
+
import { t as ensureSlash } from "../../../chunks/pathname.mjs";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import { basename, dirname, join, resolve } from "node:path";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
@@ -78,13 +78,16 @@ var QWIK_SSG_ENTRY_ID = "@qwik-ssg-entry";
|
|
|
78
78
|
var QWIK_SSG_ENTRY_RESOLVED = "\0@qwik-ssg-entry";
|
|
79
79
|
var QWIK_SSG_WORKER_ENTRY_ID = "@qwik-ssg-worker-entry";
|
|
80
80
|
var QWIK_SSG_WORKER_ENTRY_RESOLVED = "\0@qwik-ssg-worker-entry";
|
|
81
|
+
var appBuilds = /* @__PURE__ */ new Map();
|
|
82
|
+
var appWatchEnvironments = /* @__PURE__ */ new WeakSet();
|
|
83
|
+
function getAppBuildKey(root, outDir) {
|
|
84
|
+
return JSON.stringify([resolve(root), resolve(root, outDir)]);
|
|
85
|
+
}
|
|
81
86
|
/** @public */
|
|
82
87
|
function viteAdapter(opts) {
|
|
83
88
|
let qwikRouterPlugin = null;
|
|
84
89
|
let qwikVitePlugin = null;
|
|
85
90
|
let viteCommand;
|
|
86
|
-
let buildAppRan = false;
|
|
87
|
-
const outputEntries = [];
|
|
88
91
|
const ssgOutDirFor = (root) => join(resolve(root), "node_modules", ".cache", `qwik-router-ssg-${process.pid}`);
|
|
89
92
|
return [{
|
|
90
93
|
name: `vite-plugin-qwik-router-ssg-${opts.name}`,
|
|
@@ -206,72 +209,86 @@ function viteAdapter(opts) {
|
|
|
206
209
|
},
|
|
207
210
|
generateBundle(_, bundles) {
|
|
208
211
|
if (this.environment.name === "ssr") {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
212
|
+
const { root, build } = this.environment.config;
|
|
213
|
+
const appBuild = appBuilds.get(getAppBuildKey(root, build.outDir));
|
|
214
|
+
if (appBuild) {
|
|
215
|
+
appBuild.outputEntries.length = 0;
|
|
216
|
+
for (const fileName in bundles) {
|
|
217
|
+
const chunk = bundles[fileName];
|
|
218
|
+
if (chunk.type === "chunk" && chunk.isEntry) appBuild.outputEntries.push(fileName);
|
|
219
|
+
}
|
|
213
220
|
}
|
|
214
|
-
|
|
221
|
+
const isAppWatch = !!build.watch && appWatchEnvironments.has(this.environment);
|
|
222
|
+
if (opts.ssg !== null && viteCommand === "build" && !appBuild && !isAppWatch) this.warn("Qwik Router SSG was skipped: the `ssr` environment was built directly instead of through the Vite app builder, so no pages were prerendered. Build with the Qwik CLI or `createBuilder(config).buildApp()` (a plain `vite build` does this automatically).");
|
|
215
223
|
}
|
|
216
224
|
},
|
|
217
225
|
async buildApp(builder) {
|
|
218
|
-
buildAppRan = true;
|
|
219
226
|
const ssr = builder.environments.ssr;
|
|
220
|
-
if (ssr)
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
227
|
+
if (!ssr) return;
|
|
228
|
+
const buildKey = getAppBuildKey(ssr.config.root, ssr.config.build.outDir);
|
|
229
|
+
if (appBuilds.has(buildKey)) throw new Error(`An app build is already running for ${buildKey}`);
|
|
230
|
+
const appBuild = { outputEntries: [] };
|
|
231
|
+
appBuilds.set(buildKey, appBuild);
|
|
232
|
+
try {
|
|
233
|
+
await builder.build(ssr);
|
|
234
|
+
if (ssr.config.build.watch) appWatchEnvironments.add(ssr);
|
|
235
|
+
const serverOutDir = ssr.config.build.outDir;
|
|
236
|
+
if (!serverOutDir || !qwikRouterPlugin?.api || !qwikVitePlugin?.api) return;
|
|
237
|
+
const log = builder.config.logger;
|
|
238
|
+
const staticPaths = opts.staticPaths || [];
|
|
239
|
+
const routes = qwikRouterPlugin.api.getRoutes();
|
|
240
|
+
const basePathname = qwikRouterPlugin.api.getBasePathname();
|
|
241
|
+
const clientOutDir = qwikVitePlugin.api.getClientOutDir();
|
|
242
|
+
const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
|
|
243
|
+
const noTrailingSlash = builder.config.define?.["globalThis.__NO_TRAILING_SLASH__"] === "true";
|
|
244
|
+
const ssgEnv = builder.environments.ssg;
|
|
245
|
+
const ssgOutDir = ssgOutDirFor(builder.config.root);
|
|
246
|
+
if (ssgEnv && clientOutDir && clientPublicOutDir) {
|
|
247
|
+
await builder.build(ssgEnv);
|
|
248
|
+
const runSsgPath = join(ssgOutDir, "run-ssg.js");
|
|
249
|
+
if (await new Promise((res, reject) => {
|
|
250
|
+
const child = spawn(process.execPath, [runSsgPath], {
|
|
251
|
+
stdio: [
|
|
252
|
+
"ignore",
|
|
253
|
+
"inherit",
|
|
254
|
+
"inherit"
|
|
255
|
+
],
|
|
256
|
+
env: {
|
|
257
|
+
...process.env,
|
|
258
|
+
NODE_ENV: process.env.NODE_ENV || "production"
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
child.on("close", res);
|
|
262
|
+
child.on("error", reject);
|
|
263
|
+
}) !== 0) throw new Error(`Error while running SSG from "${opts.name}" adapter. At least one path failed to render.`);
|
|
264
|
+
const staticPathsFile = join(clientPublicOutDir, "_static-paths.json");
|
|
265
|
+
try {
|
|
266
|
+
staticPaths.push(...JSON.parse(await readFile(staticPathsFile, "utf-8")));
|
|
267
|
+
await unlink(staticPathsFile);
|
|
268
|
+
} catch {}
|
|
269
|
+
if (process.env.QWIK_ROUTER_KEEP_SSG_BUILD) log.warn(`SSG build kept at ${ssgOutDir}`);
|
|
270
|
+
else await rm(ssgOutDir, {
|
|
271
|
+
recursive: true,
|
|
272
|
+
force: true
|
|
246
273
|
});
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
274
|
+
}
|
|
275
|
+
await postBuild(clientPublicOutDir, serverOutDir, basePathname, staticPaths, !!opts.cleanStaticGenerated, noTrailingSlash);
|
|
276
|
+
if (typeof opts.generate === "function") await opts.generate({
|
|
277
|
+
outputEntries: appBuild.outputEntries,
|
|
278
|
+
serverOutDir,
|
|
279
|
+
clientOutDir,
|
|
280
|
+
clientPublicOutDir,
|
|
281
|
+
basePathname,
|
|
282
|
+
routes,
|
|
283
|
+
warn: (message) => log.warn(message),
|
|
284
|
+
error: (message) => {
|
|
285
|
+
throw new Error(message);
|
|
286
|
+
}
|
|
259
287
|
});
|
|
288
|
+
log.warn("\n==============================================\nNote: Make sure that you are serving the built files with proper cache headers.\nSee https://qwik.dev/docs/deployments/#cache-headers for more information.\n==============================================");
|
|
289
|
+
} finally {
|
|
290
|
+
appBuilds.delete(buildKey);
|
|
260
291
|
}
|
|
261
|
-
await postBuild(clientPublicOutDir, serverOutDir, basePathname, staticPaths, !!opts.cleanStaticGenerated, noTrailingSlash);
|
|
262
|
-
if (typeof opts.generate === "function") await opts.generate({
|
|
263
|
-
outputEntries,
|
|
264
|
-
serverOutDir,
|
|
265
|
-
clientOutDir,
|
|
266
|
-
clientPublicOutDir,
|
|
267
|
-
basePathname,
|
|
268
|
-
routes,
|
|
269
|
-
warn: (message) => log.warn(message),
|
|
270
|
-
error: (message) => {
|
|
271
|
-
throw new Error(message);
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
log.warn("\n==============================================\nNote: Make sure that you are serving the built files with proper cache headers.\nSee https://qwik.dev/docs/deployments/#cache-headers for more information.\n==============================================");
|
|
275
292
|
}
|
|
276
293
|
}];
|
|
277
294
|
}
|
package/lib/chunks/fs.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as normalizePathname, t as ensureSlash } from "./pathname.mjs";
|
|
2
1
|
import { i as toTitleCase } from "./format.mjs";
|
|
2
|
+
import { i as normalizePathname, t as ensureSlash } from "./pathname.mjs";
|
|
3
3
|
import { basename, dirname, normalize, relative } from "node:path";
|
|
4
4
|
function parseRouteIndexName(extlessName) {
|
|
5
5
|
let layoutName = "";
|
package/lib/chunks/head.qwik.mjs
CHANGED
|
@@ -3,8 +3,47 @@ import { s as getLoaderName } from "./request-path.mjs";
|
|
|
3
3
|
import { i as RedirectMessage, n as throwIfControlFlowSignal, t as ServerError } from "./server-error.mjs";
|
|
4
4
|
import { n as isStaticTrieKey, r as unescapeStaticTrieKey, t as escapeStaticTrieKey } from "./route-trie-key.mjs";
|
|
5
5
|
import { _capturesObj, createComputedQrl, createContextId, implicit$FirstArg, inlinedQrl, isBrowser, isDev, isServer, untrack, useServerData, withLocale } from "@qwik.dev/core";
|
|
6
|
-
import { SerializerSymbol, _deserialize, _getAsyncLocalStorage, _injectAsyncSignalValue,
|
|
6
|
+
import { SerializerSymbol, _deserialize, _getAsyncLocalStorage, _getContextContainer, _injectAsyncSignalValue, _invoke, _qwikSymbol, _registerSingleton, _resolveContextWithoutSequentialScope, _verifySerializable } from "@qwik.dev/core/internal";
|
|
7
7
|
import { isServer as isServer$1 } from "@qwik.dev/core/build";
|
|
8
|
+
/** Gets an absolute url path string (url.pathname + url.search + url.hash) */
|
|
9
|
+
var toPath = (url) => url.pathname + url.search + url.hash;
|
|
10
|
+
/** Create a URL from a string and baseUrl */
|
|
11
|
+
var toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
|
|
12
|
+
/** Resolves a redirect without allowing executable URL schemes. */
|
|
13
|
+
var toSafeRedirectUrl = (url, baseUrl) => {
|
|
14
|
+
const redirectUrl = toUrl(url, baseUrl);
|
|
15
|
+
if (redirectUrl.protocol !== "http:" && redirectUrl.protocol !== "https:") throw new Error(`Unsupported redirect protocol: ${redirectUrl.protocol}`);
|
|
16
|
+
return redirectUrl;
|
|
17
|
+
};
|
|
18
|
+
/** Checks only if the origins are the same. */
|
|
19
|
+
var isSameOrigin = (a, b) => a.origin === b.origin;
|
|
20
|
+
/** Checks only if the pathnames are the same for the URLs (doesn't include search and hash) */
|
|
21
|
+
var isSamePathname = ({ pathname: a }, { pathname: b }) => {
|
|
22
|
+
const lDiff = Math.abs(a.length - b.length);
|
|
23
|
+
return lDiff === 0 ? a === b : lDiff === 1 && ensureSlash(a) === ensureSlash(b);
|
|
24
|
+
};
|
|
25
|
+
/** Checks only if the search query strings are the same for the URLs */
|
|
26
|
+
var isSameSearchQuery = (a, b) => a.search === b.search;
|
|
27
|
+
/** Checks only if the pathname + search are the same for the URLs. */
|
|
28
|
+
var isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
|
|
29
|
+
var getClientNavPath = (props, baseUrl) => {
|
|
30
|
+
const href = props.href;
|
|
31
|
+
if (typeof href === "string" && typeof props.target !== "string" && !props.reload) try {
|
|
32
|
+
const linkUrl = toUrl(href.trim(), baseUrl.url);
|
|
33
|
+
if (isSameOrigin(linkUrl, toUrl("", baseUrl.url))) return toPath(linkUrl);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error(e);
|
|
36
|
+
}
|
|
37
|
+
else if (props.reload) return toPath(toUrl("", baseUrl.url));
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
40
|
+
var shouldPreload = (clientNavPath, currentLoc) => {
|
|
41
|
+
if (clientNavPath) return !isSamePathname(toUrl(clientNavPath, currentLoc.url), toUrl("", currentLoc.url));
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
44
|
+
var isPromise = (value) => {
|
|
45
|
+
return value && typeof value.then === "function";
|
|
46
|
+
};
|
|
8
47
|
var createRequestStore = () => {
|
|
9
48
|
const AsyncLocalStorage = _getAsyncLocalStorage();
|
|
10
49
|
if (AsyncLocalStorage) return new AsyncLocalStorage();
|
|
@@ -87,7 +126,7 @@ var QDATA_KEY = "qdata";
|
|
|
87
126
|
/** @public */
|
|
88
127
|
var Q_ROUTE = "q:route";
|
|
89
128
|
function DEFAULT_LOADERS_SERIALIZATION_STRATEGY() {
|
|
90
|
-
return globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__ || "
|
|
129
|
+
return globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__ || "auto";
|
|
91
130
|
}
|
|
92
131
|
var RouteStateContext = /*#__PURE__*/ createContextId("qr-s");
|
|
93
132
|
var RouteLoaderCtxContext = /*#__PURE__*/ createContextId("qr-lc");
|
|
@@ -192,45 +231,6 @@ var getBasePathname = () => findRouterConfig()?.basePathname ?? globalThis.__QWI
|
|
|
192
231
|
var getTrailingSlash = () => findRouterConfig()?.trailingSlash ?? !globalThis.__NO_TRAILING_SLASH__;
|
|
193
232
|
/** @internal */
|
|
194
233
|
var _getServiceWorkerUrl = () => findRouterConfig()?.serviceWorkerUrl;
|
|
195
|
-
/** Gets an absolute url path string (url.pathname + url.search + url.hash) */
|
|
196
|
-
var toPath = (url) => url.pathname + url.search + url.hash;
|
|
197
|
-
/** Create a URL from a string and baseUrl */
|
|
198
|
-
var toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
|
|
199
|
-
/** Resolves a redirect without allowing executable URL schemes. */
|
|
200
|
-
var toSafeRedirectUrl = (url, baseUrl) => {
|
|
201
|
-
const redirectUrl = toUrl(url, baseUrl);
|
|
202
|
-
if (redirectUrl.protocol !== "http:" && redirectUrl.protocol !== "https:") throw new Error(`Unsupported redirect protocol: ${redirectUrl.protocol}`);
|
|
203
|
-
return redirectUrl;
|
|
204
|
-
};
|
|
205
|
-
/** Checks only if the origins are the same. */
|
|
206
|
-
var isSameOrigin = (a, b) => a.origin === b.origin;
|
|
207
|
-
/** Checks only if the pathnames are the same for the URLs (doesn't include search and hash) */
|
|
208
|
-
var isSamePathname = ({ pathname: a }, { pathname: b }) => {
|
|
209
|
-
const lDiff = Math.abs(a.length - b.length);
|
|
210
|
-
return lDiff === 0 ? a === b : lDiff === 1 && ensureSlash(a) === ensureSlash(b);
|
|
211
|
-
};
|
|
212
|
-
/** Checks only if the search query strings are the same for the URLs */
|
|
213
|
-
var isSameSearchQuery = (a, b) => a.search === b.search;
|
|
214
|
-
/** Checks only if the pathname + search are the same for the URLs. */
|
|
215
|
-
var isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
|
|
216
|
-
var getClientNavPath = (props, baseUrl) => {
|
|
217
|
-
const href = props.href;
|
|
218
|
-
if (typeof href === "string" && typeof props.target !== "string" && !props.reload) try {
|
|
219
|
-
const linkUrl = toUrl(href.trim(), baseUrl.url);
|
|
220
|
-
if (isSameOrigin(linkUrl, toUrl("", baseUrl.url))) return toPath(linkUrl);
|
|
221
|
-
} catch (e) {
|
|
222
|
-
console.error(e);
|
|
223
|
-
}
|
|
224
|
-
else if (props.reload) return toPath(toUrl("", baseUrl.url));
|
|
225
|
-
return null;
|
|
226
|
-
};
|
|
227
|
-
var shouldPreload = (clientNavPath, currentLoc) => {
|
|
228
|
-
if (clientNavPath) return !isSamePathname(toUrl(clientNavPath, currentLoc.url), toUrl("", currentLoc.url));
|
|
229
|
-
return false;
|
|
230
|
-
};
|
|
231
|
-
var isPromise = (value) => {
|
|
232
|
-
return value && typeof value.then === "function";
|
|
233
|
-
};
|
|
234
234
|
/**
|
|
235
235
|
* Route loaders read data before the route rendering starts, based on the route being navigated to.
|
|
236
236
|
* They automatically update when the route changes on the client.
|
|
@@ -420,12 +420,12 @@ var retainLoaderValue = (previous, abortSignal) => {
|
|
|
420
420
|
abortSignal.addEventListener("abort", () => reject(abortSignal.reason), { once: true });
|
|
421
421
|
});
|
|
422
422
|
};
|
|
423
|
-
var createRouteLoaderSignal = (loader2, routeLoaderCtx, state, requestEv3) => {
|
|
423
|
+
var createRouteLoaderSignal = (loader2, routeLoaderCtx, state, requestEv3, container) => {
|
|
424
424
|
const id = loader2.__id;
|
|
425
|
-
const capture = isServer ? new ServerRouteLoaderCapture(id, loader2.__qrl, loader2.__validators, loader2.__blockSSR, loader2, requestEv3
|
|
425
|
+
const capture = isServer ? new ServerRouteLoaderCapture(id, loader2.__qrl, loader2.__validators, loader2.__blockSSR, loader2, requestEv3) : id;
|
|
426
426
|
const searchFilter = loader2.__search;
|
|
427
427
|
const loaderHash = isDev ? loader2.__qrl.getHash() : id;
|
|
428
|
-
|
|
428
|
+
return createComputedQrl(/*#__PURE__*/ inlinedQrl(async (ctx) => {
|
|
429
429
|
let capture = _capturesObj._[0], id = _capturesObj._[1], lastFetch = _capturesObj._[2], loaderHash = _capturesObj._[3], routeLoaderCtx = _capturesObj._[4], searchFilter = _capturesObj._[5], state = _capturesObj._[6];
|
|
430
430
|
const hasInjectedValue = !!ctx.info && typeof ctx.info === "object" && "__v" in ctx.info;
|
|
431
431
|
const eTag1 = isServer && capture.eTag();
|
|
@@ -499,9 +499,10 @@ var createRouteLoaderSignal = (loader2, routeLoaderCtx, state, requestEv3) => {
|
|
|
499
499
|
routeLoaderCtx,
|
|
500
500
|
searchFilter,
|
|
501
501
|
state
|
|
502
|
-
]), {
|
|
503
|
-
|
|
504
|
-
|
|
502
|
+
]), {
|
|
503
|
+
serializationStrategy: loader2.__serializationStrategy,
|
|
504
|
+
container
|
|
505
|
+
});
|
|
505
506
|
};
|
|
506
507
|
/** Build a sorted, stable search string from only the allowed param names. */
|
|
507
508
|
var filterSearchParams = (params, allowed) => {
|
|
@@ -654,10 +655,12 @@ function abortRouteLoaderNavigation(ctx) {
|
|
|
654
655
|
function hasSameListedSearch(previous, next, search) {
|
|
655
656
|
return !!search && previous.pathname === next.pathname && filterSearchParams(previous.searchParams, search) === filterSearchParams(next.searchParams, search);
|
|
656
657
|
}
|
|
657
|
-
function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navCount, forceIds, navigationKey) {
|
|
658
|
+
function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navCount, forceIds, navigationKey, forceReload) {
|
|
658
659
|
const client = getClientRouteLoaders(ctx, previousUrl.href);
|
|
659
660
|
if (navigationKey && client.navigationKey === navigationKey) return ensureRouteLoaderSignals(mods, state, ctx);
|
|
660
661
|
const previous = client.current;
|
|
662
|
+
const previousPageUrl = new URL(previous.pageUrl);
|
|
663
|
+
const reloadsCurrentPage = previousPageUrl.origin === pageUrl.origin && previousPageUrl.pathname === pageUrl.pathname && previousPageUrl.search === pageUrl.search;
|
|
661
664
|
if (client.navCount === void 0) for (const id in state) getLoaderRequest(ctx, state, id, id);
|
|
662
665
|
client.navCount = navCount;
|
|
663
666
|
client.navigationKey = navigationKey;
|
|
@@ -686,7 +689,7 @@ function prepareRouteLoaders(mods, state, ctx, paths, pageUrl, previousUrl, navC
|
|
|
686
689
|
signal.abort();
|
|
687
690
|
continue;
|
|
688
691
|
}
|
|
689
|
-
const keepRequest = old?.active && !old.isAborted && old.routePath === routePath && (
|
|
692
|
+
const keepRequest = old?.active && !old.isAborted && old.routePath === routePath && (reloadsCurrentPage ? isImmutableLoader(id) : !forceReload && hasSameListedSearch(new URL(old.pageUrl), pageUrl, loader4?.__search));
|
|
690
693
|
current.requests.set(signal, keepRequest ? old : {
|
|
691
694
|
routePath,
|
|
692
695
|
pageUrl: pageUrl.href,
|
|
@@ -730,7 +733,12 @@ function restoreRouteLoaders(state, ctx, navCount) {
|
|
|
730
733
|
}
|
|
731
734
|
var ensureRouteLoaderSignal = (loader5, state, routeLoaderCtx, requestEv12) => {
|
|
732
735
|
if (loader5.__cacheControl === "immutable") immutableLoaderIds.add(loader5.__id);
|
|
733
|
-
|
|
736
|
+
const id = loader5.__id;
|
|
737
|
+
if (!state[id]) {
|
|
738
|
+
const ev = requestEv12 ?? (isServer ? useServerData("qwikrouter")?.ev : void 0);
|
|
739
|
+
state[id] = _invoke(void 0, createRouteLoaderSignal, loader5, routeLoaderCtx, state, ev, _getContextContainer());
|
|
740
|
+
}
|
|
741
|
+
return state[id];
|
|
734
742
|
};
|
|
735
743
|
var ensureRouteLoaderSignals = (mods, state, routeLoaderCtx, requestEv13) => {
|
|
736
744
|
const loaders = getModuleRouteLoaders(mods);
|
|
@@ -1627,6 +1635,20 @@ function collectPageLoaders({ node, loaderPaths, loaderParams }, paths, pathPara
|
|
|
1627
1635
|
pathParams[hash] = { ...params };
|
|
1628
1636
|
}
|
|
1629
1637
|
}
|
|
1638
|
+
var getLayoutKeys = (loaders) => {
|
|
1639
|
+
const layoutKeys = [];
|
|
1640
|
+
for (const loader of loaders) {
|
|
1641
|
+
const layoutKey = loader._K;
|
|
1642
|
+
if (layoutKey) layoutKeys.push(layoutKey);
|
|
1643
|
+
}
|
|
1644
|
+
return layoutKeys;
|
|
1645
|
+
};
|
|
1646
|
+
var getNewLayoutKeys = (currentLayoutKeys, destLayoutKeys) => {
|
|
1647
|
+
if (!currentLayoutKeys) return destLayoutKeys;
|
|
1648
|
+
let sharedCount = 0;
|
|
1649
|
+
while (sharedCount < destLayoutKeys.length && destLayoutKeys[sharedCount] === currentLayoutKeys[sharedCount]) sharedCount++;
|
|
1650
|
+
return destLayoutKeys.slice(sharedCount);
|
|
1651
|
+
};
|
|
1630
1652
|
/**
|
|
1631
1653
|
* Resolve the full route config (head + eTag + cacheKey) from all content modules. Uses the same
|
|
1632
1654
|
* resolution rules as DocumentHead: objects are merged immediately, functions are queued and
|
|
@@ -1744,4 +1766,4 @@ var createDocumentHead = (defaults, manifestHash) => ({
|
|
|
1744
1766
|
frontmatter: { ...defaults?.frontmatter },
|
|
1745
1767
|
manifestHash: manifestHash || "dev"
|
|
1746
1768
|
});
|
|
1747
|
-
export {
|
|
1769
|
+
export { RouteLoaderCtxContext as $, restoreRouteLoaders as A, getRoutes as B, getRouteLoaderValues as C, matchesRouteLoaderId as D, loadRouteLoader as E, _getServiceWorkerUrl as F, preventNav as G, REFRESH_HEAD as H, _setRouterConfig as I, ContentInternalContext as J, registerPreventNav as K, findRouterConfig as L, routeLoaderQrl as M, setLoaderSignalValue as N, prepareRouteLoaders as O, setRouteLoaders as P, RouteActionRunnerContext as Q, getBasePathname as R, getRouteLoaderResponse as S, isImmutableLoader as T, RUN_PENDING_ACTION as U, getTrailingSlash as V, internalState as W, HttpStatusContext as X, DocumentHeadContext as Y, RouteActionContext as Z, getLoaderRequestEvent as _, isSamePath as _t, getNewLayoutKeys as a, QFN_KEY as at, getRouteLoaderCtx as b, toSafeRedirectUrl as bt, FULLPATH_HEADER as c, normalizeETag as ct, clearNavFetchCache as d, setETagHeader as dt, RouteLocationContext as et, clearRouteLoaderData as f, RequestEvRouterConfig as ft, getClientRouteLoaders as g, isSameOrigin as gt, fetchRouteLoaderData as h, isPromise as ht, getLayoutKeys as i, QDATA_KEY as it, routeLoader$ as j, resolveRouteLoaderByHash as k, ROUTE_PATH_HEADER as l, performETagMatch as lt, ensureRouteLoaderSignals as m, getClientNavPath as mt, resolveHead as n, RouteStateContext as nt, loadRoute as o, Q_ROUTE as ot, commitRouteLoaders as p, _asyncRequestStore as pt, ContentContext as q, resolveRouteConfig as r, QACTION_KEY as rt, matchRouteTree as s, hash as st, createDocumentHead as t, RouteNavigateContext as tt, abortRouteLoaderNavigation as u, resolvePreETag as ut, getModuleRouteLoaders as v, shouldPreload as vt, getRouteLoaders as w, getRouteLoaderParams as x, toUrl as xt, getRequestEvent as y, toPath as yt, getRouterConfig as z };
|
package/lib/chunks/pathname.mjs
CHANGED
|
@@ -28,6 +28,7 @@ function getPathnameForDynamicRoute(originalPathname, paramNames, params) {
|
|
|
28
28
|
const paramKey = `[${paramName}]`;
|
|
29
29
|
const restParamKey = `[...${paramName}]`;
|
|
30
30
|
const paramValue = params[paramName];
|
|
31
|
+
if (paramValue === "") pathname = pathname.replace(`/${restParamKey}/`, "/");
|
|
31
32
|
pathname = pathname.replace(restParamKey, paramValue);
|
|
32
33
|
pathname = pathname.replace(paramKey, paramValue);
|
|
33
34
|
}
|
package/lib/chunks/system.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as ensureSlash } from "./pathname.mjs";
|
|
2
|
-
import { s as getLoaderName } from "./request-path.mjs";
|
|
3
1
|
import { _ as normalizePath } from "./fs.mjs";
|
|
2
|
+
import { s as getLoaderName } from "./request-path.mjs";
|
|
3
|
+
import { t as ensureSlash } from "./pathname.mjs";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
6
6
|
import { cpus } from "node:os";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as ensureSlash } from "./pathname.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { C as getRouteLoaderValues, D as matchesRouteLoaderId, E as loadRouteLoader, P as setRouteLoaders, S as getRouteLoaderResponse, _ as getLoaderRequestEvent, at as QFN_KEY, b as getRouteLoaderCtx, c as FULLPATH_HEADER, ct as normalizeETag, dt as setETagHeader, f as clearRouteLoaderData, ft as RequestEvRouterConfig, ht as isPromise, it as QDATA_KEY, k as resolveRouteLoaderByHash, l as ROUTE_PATH_HEADER, lt as performETagMatch, ot as Q_ROUTE, pt as _asyncRequestStore, r as resolveRouteConfig, rt as QACTION_KEY, st as hash, ut as resolvePreETag, x as getRouteLoaderParams } from "./head.qwik.mjs";
|
|
3
3
|
import { a as QActionId, c as recognizeRequest, d as trimRecognizedInternalPathname, l as resolveValidInternalFullPathname, o as QLoaderId, t as IsQAction } 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";
|
|
@@ -437,6 +437,8 @@ var RequestEvETagCacheKey = "@eTagCacheKey";
|
|
|
437
437
|
var RequestEvCaughtError = "@caughtError";
|
|
438
438
|
var RequestEvSentServerError = "@sentServerError";
|
|
439
439
|
var RequestEvHttpStatusMessage = "@httpStatusMessage";
|
|
440
|
+
var RequestEvManifestHash = "@manifestHash";
|
|
441
|
+
/** Builds shared request state and controls route handler execution. */
|
|
440
442
|
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, basePathname, resolved, routerConfig) {
|
|
441
443
|
const { request, platform, env } = serverRequestEv;
|
|
442
444
|
const sharedMap = /* @__PURE__ */ new Map();
|
|
@@ -482,13 +484,14 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, baseP
|
|
|
482
484
|
const check = () => {
|
|
483
485
|
if (writableStream !== null) throw new Error("Response already sent");
|
|
484
486
|
};
|
|
487
|
+
/** Exits the route synchronously while handling stream failures asynchronously. */
|
|
485
488
|
const send = (statusOrResponse, body) => {
|
|
486
489
|
check();
|
|
490
|
+
let responseWrite;
|
|
487
491
|
if (typeof statusOrResponse === "number") {
|
|
488
492
|
status = statusOrResponse;
|
|
489
493
|
const writer = requestEv.getWritableStream().getWriter();
|
|
490
|
-
writer.write(typeof body === "string" ? encoder.encode(body) : body);
|
|
491
|
-
writer.close();
|
|
494
|
+
responseWrite = Promise.all([writer.write(typeof body === "string" ? encoder.encode(body) : body), writer.close()]);
|
|
492
495
|
} else {
|
|
493
496
|
status = statusOrResponse.status;
|
|
494
497
|
statusOrResponse.headers.forEach((value, key) => {
|
|
@@ -504,9 +507,14 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, baseP
|
|
|
504
507
|
});
|
|
505
508
|
if (statusOrResponse.body) {
|
|
506
509
|
const writableStream = requestEv.getWritableStream();
|
|
507
|
-
statusOrResponse.body.pipeTo(writableStream);
|
|
508
|
-
} else requestEv.getWritableStream().getWriter().close();
|
|
510
|
+
responseWrite = statusOrResponse.body.pipeTo(writableStream);
|
|
511
|
+
} else responseWrite = requestEv.getWritableStream().getWriter().close();
|
|
509
512
|
}
|
|
513
|
+
responseWrite.catch((error) => {
|
|
514
|
+
const signal = request.signal;
|
|
515
|
+
if (signal.aborted && (error instanceof Error && error.name === "AbortError" || error === signal.reason)) return;
|
|
516
|
+
console.error("Response stream failed:", error);
|
|
517
|
+
});
|
|
510
518
|
return exit();
|
|
511
519
|
};
|
|
512
520
|
const exit = (message = new AbortMessage()) => {
|
|
@@ -1607,8 +1615,11 @@ The request origin "${inputOrigin}" does not match the server origin "${origin}"
|
|
|
1607
1615
|
const { readable, writable } = new TextEncoderStream();
|
|
1608
1616
|
let responseWriter;
|
|
1609
1617
|
const lazyResponseSink = new WritableStream({ write(chunk) {
|
|
1618
|
+
if (requestEv.signal.aborted) return;
|
|
1610
1619
|
responseWriter ||= requestEv.getWritableStream().getWriter();
|
|
1611
|
-
return responseWriter.write(chunk)
|
|
1620
|
+
return responseWriter.write(chunk).catch((error) => {
|
|
1621
|
+
if (!requestEv.signal.aborted) throw error;
|
|
1622
|
+
});
|
|
1612
1623
|
} });
|
|
1613
1624
|
let cacheChunks;
|
|
1614
1625
|
let pipeSource = readable;
|
|
@@ -1621,11 +1632,15 @@ The request origin "${inputOrigin}" does not match the server origin "${origin}"
|
|
|
1621
1632
|
pipeSource = readable.pipeThrough(capture);
|
|
1622
1633
|
}
|
|
1623
1634
|
let pipeError;
|
|
1635
|
+
let hasPipeError = false;
|
|
1624
1636
|
let boundaryErrored = false;
|
|
1625
1637
|
let noStoreSent = false;
|
|
1626
1638
|
let overrodeCacheControl = false;
|
|
1627
1639
|
const pipe = pipeSource.pipeTo(lazyResponseSink, { preventClose: true }).catch((error) => {
|
|
1628
|
-
|
|
1640
|
+
if (!requestEv.signal.aborted) {
|
|
1641
|
+
hasPipeError = true;
|
|
1642
|
+
pipeError = error;
|
|
1643
|
+
}
|
|
1629
1644
|
});
|
|
1630
1645
|
const stream = writable.getWriter();
|
|
1631
1646
|
try {
|
|
@@ -1649,6 +1664,10 @@ The request origin "${inputOrigin}" does not match the server origin "${origin}"
|
|
|
1649
1664
|
}
|
|
1650
1665
|
}
|
|
1651
1666
|
});
|
|
1667
|
+
if (isStatic) {
|
|
1668
|
+
const renderedAttributes = serverData.containerAttributes;
|
|
1669
|
+
requestEv.sharedMap.set(RequestEvManifestHash, renderedAttributes["q:manifest-hash"] ?? result.manifest?.manifestHash);
|
|
1670
|
+
}
|
|
1652
1671
|
if (typeof result.html === "string") await stream.write(result.html);
|
|
1653
1672
|
boundaryErrored ||= result.hasCaughtError === true;
|
|
1654
1673
|
if (boundaryErrored) requestEv.sharedMap.set(RequestEvCaughtError, true);
|
|
@@ -1656,12 +1675,15 @@ The request origin "${inputOrigin}" does not match the server origin "${origin}"
|
|
|
1656
1675
|
try {
|
|
1657
1676
|
await stream.ready;
|
|
1658
1677
|
await stream.close();
|
|
1678
|
+
} catch (error) {
|
|
1679
|
+
if (!requestEv.signal.aborted) throw error;
|
|
1659
1680
|
} finally {
|
|
1660
1681
|
await pipe;
|
|
1661
1682
|
responseWriter?.releaseLock();
|
|
1662
1683
|
}
|
|
1663
1684
|
}
|
|
1664
|
-
if (
|
|
1685
|
+
if (hasPipeError) throw pipeError;
|
|
1686
|
+
if (requestEv.signal.aborted) return;
|
|
1665
1687
|
if (boundaryErrored && (noStoreSent ? cachePlan || overrodeCacheControl : !!cachePlan)) console.warn(`A <Catch> caught during SSR of ${requestEv.url.pathname} — configured caching disabled: ` + (noStoreSent ? "the response was sent with Cache-Control: no-store." : "the SSR cache was skipped (response headers were already sent)."));
|
|
1666
1688
|
if (cachePlan && cacheChunks && cacheChunks.length > 0 && !boundaryErrored) {
|
|
1667
1689
|
const totalLength = cacheChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
@@ -1678,7 +1700,11 @@ The request origin "${inputOrigin}" does not match the server origin "${origin}"
|
|
|
1678
1700
|
body: html
|
|
1679
1701
|
});
|
|
1680
1702
|
}
|
|
1681
|
-
if (responseWriter)
|
|
1703
|
+
if (responseWriter) try {
|
|
1704
|
+
await requestEv.getWritableStream().close();
|
|
1705
|
+
} catch (error) {
|
|
1706
|
+
if (!requestEv.signal.aborted) throw error;
|
|
1707
|
+
}
|
|
1682
1708
|
};
|
|
1683
1709
|
}
|
|
1684
1710
|
function now() {
|
|
@@ -1817,7 +1843,7 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
|
1817
1843
|
requestEv.sharedMap.set(RequestEvSentServerError, e);
|
|
1818
1844
|
return;
|
|
1819
1845
|
}
|
|
1820
|
-
if (!isDev$1 || requestEv.headersSent) try {
|
|
1846
|
+
if ((!isDev$1 || requestEv.headersSent) && !requestEv.signal.aborted) try {
|
|
1821
1847
|
if (!requestEv.headersSent) {
|
|
1822
1848
|
requestEv.headers.set("content-type", "text/html; charset=utf-8");
|
|
1823
1849
|
requestEv.cacheControl({ noCache: true });
|
|
@@ -1841,4 +1867,4 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
|
1841
1867
|
if (!requestEv.isDirty()) resolve(null);
|
|
1842
1868
|
}
|
|
1843
1869
|
}
|
|
1844
|
-
export { getStaticPathRedirect as a, RequestEvHttpStatusMessage as c,
|
|
1870
|
+
export { getStaticPathRedirect as a, RequestEvHttpStatusMessage as c, RewriteMessage as d, mergeHeadersCookies as f, clearSsrCache as h, resolveRequestHandlers as i, RequestEvManifestHash as l, clearLoaderCache as m, getErrorHtml as n, isStaticPath as o, resolveLoaderPagePathname as p, renderQwikMiddleware as r, RequestEvCaughtError as s, runQwikRouter as t, RequestEvSentServerError as u };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as getRouteLoaders, i as loadRoute, x as getRouteLoaderValues } from "./head.qwik.mjs";
|
|
2
|
-
import { u as trimInternalPathname } from "./request-path.mjs";
|
|
3
1
|
import { c as RequestEvHttpStatusMessage, i as resolveRequestHandlers, r as renderQwikMiddleware, t as runQwikRouter } from "./user-response.mjs";
|
|
2
|
+
import { u as trimInternalPathname } from "./request-path.mjs";
|
|
3
|
+
import { C as getRouteLoaderValues, o as loadRoute, w as getRouteLoaders } from "./head.qwik.mjs";
|
|
4
4
|
import { _serialize } from "@qwik.dev/core/internal/serializer";
|
|
5
5
|
import { parentPort } from "node:worker_threads";
|
|
6
6
|
var staticWorkerThreadDeps = {
|
|
@@ -172,7 +172,7 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
|
|
|
172
172
|
if (writeLoaderDataEnabled && !isNotFoundPage) {
|
|
173
173
|
const routeLoaders = getRouteLoaders(requestEv);
|
|
174
174
|
const loaderValues = getRouteLoaderValues(requestEv);
|
|
175
|
-
const manifestHash = opts.manifest?.manifestHash || "dev";
|
|
175
|
+
const manifestHash = requestEv.sharedMap.get("@manifestHash") || opts.manifest?.manifestHash || "dev";
|
|
176
176
|
for (const loader of routeLoaders) {
|
|
177
177
|
if (loader.__cacheControl !== "immutable") continue;
|
|
178
178
|
const data = loaderValues[loader.__id];
|
package/lib/index.d.ts
CHANGED
|
@@ -533,7 +533,8 @@ export declare interface LinkProps extends AnchorAttributes {
|
|
|
533
533
|
* Controls when Qwik should prefetch the javascript bundles required to render this **`Link`**
|
|
534
534
|
* target during client-side navigation.
|
|
535
535
|
*
|
|
536
|
-
* Defaults to **`"visible"`**.
|
|
536
|
+
* Defaults to **`"visible"`**. A link that prefetches when visible is hinted again, ahead of the
|
|
537
|
+
* others, when the user hovers or focuses it.
|
|
537
538
|
*
|
|
538
539
|
* Prefetching will not occur if the user has the **data saver** setting enabled.
|
|
539
540
|
*/
|
|
@@ -618,6 +619,7 @@ declare type LoaderOptions = {
|
|
|
618
619
|
*/
|
|
619
620
|
readonly id?: string;
|
|
620
621
|
readonly validation?: DataValidator[];
|
|
622
|
+
/** Controls value serialization during SSR; defaults to `auto`. */
|
|
621
623
|
readonly serializationStrategy?: SerializationStrategy;
|
|
622
624
|
/**
|
|
623
625
|
* Cache-Control for this loader's JSON responses. The browser HTTP cache is the single source of
|
package/lib/index.qwik.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as ensureSlash } from "./chunks/pathname.mjs";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as RouteLoaderCtxContext, A as restoreRouteLoaders, B as getRoutes, F as _getServiceWorkerUrl, G as preventNav, H as REFRESH_HEAD, I as _setRouterConfig, J as ContentInternalContext, K as registerPreventNav, L as findRouterConfig, M as routeLoaderQrl, N as setLoaderSignalValue, O as prepareRouteLoaders, Q as RouteActionRunnerContext, R as getBasePathname, T as isImmutableLoader, U as RUN_PENDING_ACTION, V as getTrailingSlash, W as internalState, X as HttpStatusContext, Y as DocumentHeadContext, Z as RouteActionContext, _t as isSamePath, a as getNewLayoutKeys, at as QFN_KEY, bt as toSafeRedirectUrl, d as clearNavFetchCache, et as RouteLocationContext, g as getClientRouteLoaders, gt as isSameOrigin, h as fetchRouteLoaderData, ht as isPromise, i as getLayoutKeys, it as QDATA_KEY, j as routeLoader$, m as ensureRouteLoaderSignals, mt as getClientNavPath, n as resolveHead, nt as RouteStateContext, o as loadRoute, ot as Q_ROUTE, p as commitRouteLoaders, q as ContentContext, rt as QACTION_KEY, s as matchRouteTree, t as createDocumentHead, tt as RouteNavigateContext, u as abortRouteLoaderNavigation, v as getModuleRouteLoaders, vt as shouldPreload, xt as toUrl, y as getRequestEvent, yt as toPath, z as getRouterConfig } from "./chunks/head.qwik.mjs";
|
|
3
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, _isSyncQrl, _regInlinedQrl, _requestPreload, _waitOn, _waitUntilRendered, forceStoreEffects } from "@qwik.dev/core/internal";
|
|
5
5
|
import { Fragment } from "@qwik.dev/core/jsx-runtime";
|
|
@@ -8,6 +8,32 @@ import * as v from "valibot";
|
|
|
8
8
|
import * as z$1 from "zod";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { renderToStream } from "@qwik.dev/core/server";
|
|
11
|
+
var clientNavigate = (win, navType, fromURL, toURL, replaceState = false) => {
|
|
12
|
+
if (navType !== "popstate") {
|
|
13
|
+
const samePath = isSamePath(fromURL, toURL);
|
|
14
|
+
const sameHash = fromURL.hash === toURL.hash;
|
|
15
|
+
if (!samePath || !sameHash) {
|
|
16
|
+
const newState = { _qRouterScroll: newScrollState() };
|
|
17
|
+
if (replaceState) win.history.replaceState(newState, "", toPath(toURL));
|
|
18
|
+
else win.history.pushState(newState, "", toPath(toURL));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var newScrollState = () => {
|
|
23
|
+
return {
|
|
24
|
+
x: 0,
|
|
25
|
+
y: 0,
|
|
26
|
+
w: 0,
|
|
27
|
+
h: 0
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var preloadRouteBundles = (routeName, priority = .8, newLayoutKeys = []) => {
|
|
31
|
+
if (isBrowser) {
|
|
32
|
+
routeName = ensureSlash(routeName);
|
|
33
|
+
routeName = routeName.length > 1 && routeName.startsWith("/") ? routeName.slice(1) : routeName;
|
|
34
|
+
_requestPreload([...newLayoutKeys, routeName], priority, true);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
11
37
|
/**
|
|
12
38
|
* Prefetch a route's JS bundles and optionally its loader data.
|
|
13
39
|
*
|
|
@@ -17,23 +43,26 @@ import { renderToStream } from "@qwik.dev/core/server";
|
|
|
17
43
|
*
|
|
18
44
|
* @param url - The URL pathname to prefetch
|
|
19
45
|
* @param prefetchData - Whether to prefetch loader data
|
|
20
|
-
* @param
|
|
46
|
+
* @param priority - Preload priority of the route's bundles (0-1, default 0.8)
|
|
21
47
|
* @param manifestHash - Build manifest hash for loader URLs (from `useDocumentHead().manifestHash`)
|
|
22
48
|
* @param prefetchBundle - Whether to prefetch route JS bundles
|
|
49
|
+
* @param currentUrl - The page the navigation leaves, when `location` already shows the new one
|
|
23
50
|
*/
|
|
24
|
-
async function prefetchRoute(url, prefetchData,
|
|
51
|
+
async function prefetchRoute(url, prefetchData, priority = .8, manifestHash, prefetchBundle = true, currentUrl) {
|
|
25
52
|
if (!isBrowser || isDev) return;
|
|
26
53
|
try {
|
|
27
54
|
const { routes, cacheModules } = await getRouterConfig();
|
|
28
|
-
const loadedRoute = await loadRoute(routes, cacheModules, url.pathname);
|
|
29
|
-
if (!loadedRoute) return;
|
|
30
55
|
if (prefetchBundle) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
56
|
+
const destRoute = matchRouteTree(routes, url.pathname);
|
|
57
|
+
const currentRoute = matchRouteTree(routes, (currentUrl ?? location).pathname);
|
|
58
|
+
const newLayoutKeys = getNewLayoutKeys(getLayoutKeys(currentRoute.loaders), getLayoutKeys(destRoute.loaders));
|
|
59
|
+
preloadRouteBundles("/" + destRoute.routeParts.join("/"), priority, newLayoutKeys);
|
|
35
60
|
}
|
|
36
|
-
|
|
61
|
+
const isNavigating = priority === 1;
|
|
62
|
+
const shouldPrefetchData = !!prefetchData && !!manifestHash;
|
|
63
|
+
if (!isNavigating && !shouldPrefetchData) return;
|
|
64
|
+
const loadedRoute = await loadRoute(routes, cacheModules, url.pathname);
|
|
65
|
+
if (!loadedRoute || !shouldPrefetchData) return;
|
|
37
66
|
prefetchLoaderData(loadedRoute, url, manifestHash);
|
|
38
67
|
} catch {}
|
|
39
68
|
}
|
|
@@ -120,28 +149,37 @@ var usePreventNavigateQrl = (fn) => {
|
|
|
120
149
|
var usePreventNavigate$ = implicit$FirstArg(usePreventNavigateQrl);
|
|
121
150
|
var useAction = () => useContext(RouteActionContext);
|
|
122
151
|
var useQwikRouterEnv = () => noSerialize(useServerData("qwikrouter"));
|
|
152
|
+
var INTENT_PRIORITY = .9;
|
|
123
153
|
/** @public */
|
|
124
154
|
var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
|
|
125
155
|
const nav = useNavigate();
|
|
126
156
|
const loc = useLocation();
|
|
127
157
|
const head = useDocumentHead();
|
|
158
|
+
const originalHref = props.href;
|
|
128
159
|
const { onClick$, prefetch: prefetchProp, reload, replaceState, scroll, prefetchBundles: prefetchBundlesProp = "visible", prefetchData: prefetchDataProp = prefetchProp === "js" ? "off" : "intent", ...linkProps } = props;
|
|
129
160
|
const clientNavPath = untrack(getClientNavPath, {
|
|
130
161
|
...linkProps,
|
|
131
162
|
reload
|
|
132
163
|
}, loc);
|
|
133
|
-
linkProps.href = clientNavPath ||
|
|
164
|
+
linkProps.href = clientNavPath || originalHref;
|
|
134
165
|
const isDepratedPrefetchDisabled = prefetchProp === false;
|
|
135
166
|
const shouldPrefetch = untrack(shouldPreload, clientNavPath, loc);
|
|
136
167
|
const shouldVisiblePrefetchBundles = !!clientNavPath && shouldPrefetch && !isDepratedPrefetchDisabled && (prefetchBundlesProp === "visible" || prefetchProp === "js" || prefetchProp === true);
|
|
137
168
|
const shouldVisiblePrefetchData = !!clientNavPath && shouldPrefetch && !isDepratedPrefetchDisabled && (prefetchDataProp === "visible" || prefetchProp === true);
|
|
138
|
-
const routes =
|
|
139
|
-
const route = routes && untrack(() =>
|
|
169
|
+
const routes = !!clientNavPath && findRouterConfig()?.routes;
|
|
170
|
+
const route = routes && untrack(() => {
|
|
171
|
+
try {
|
|
172
|
+
return matchRouteTree(routes, new URL(clientNavPath, loc.url).pathname);
|
|
173
|
+
} catch {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
const newLayoutKeys = shouldVisiblePrefetchBundles && routes && route && !route.notFound ? untrack(() => getNewLayoutKeys(getLayoutKeys(matchRouteTree(routes, loc.url.pathname).loaders), getLayoutKeys(route.loaders))) : void 0;
|
|
140
178
|
const shouldPrefetchBundles = !!clientNavPath && prefetchBundlesProp !== "off" && shouldPrefetch && !isDepratedPrefetchDisabled;
|
|
141
179
|
const shouldPrefetchData = !!clientNavPath && prefetchDataProp !== "off" && shouldPrefetch && !isDepratedPrefetchDisabled;
|
|
142
180
|
const handleBundlePrefetch = shouldPrefetchBundles ? /*#__PURE__*/ inlinedQrl((_, elm) => {
|
|
143
181
|
if (navigator.connection?.saveData) return;
|
|
144
|
-
if (elm && elm.href) prefetchRoute(new URL(elm.href), false,
|
|
182
|
+
if (elm && elm.href) prefetchRoute(new URL(elm.href), false, INTENT_PRIORITY);
|
|
145
183
|
}, "Link_component_handleBundlePrefetch_ZttUP0kLKj0") : null;
|
|
146
184
|
const handleDataPrefetch = shouldPrefetchData ? /*#__PURE__*/ inlinedQrl((_, elm) => {
|
|
147
185
|
let head = _capturesObj._[0];
|
|
@@ -191,9 +229,12 @@ var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
|
|
|
191
229
|
...linkProps,
|
|
192
230
|
"data-q-prefetch": shouldVisiblePrefetchBundles && shouldVisiblePrefetchData ? "bd" : shouldVisiblePrefetchBundles ? "b" : shouldVisiblePrefetchData ? "d" : null,
|
|
193
231
|
"data-q-route": route && !route.notFound ? "/" + route.routeParts.join("/") : void 0,
|
|
232
|
+
"data-q-layouts": newLayoutKeys?.length ? newLayoutKeys.join(" ") : void 0,
|
|
194
233
|
"q-e:click": [
|
|
195
234
|
preventDefault,
|
|
196
235
|
/*#__PURE__*/ inlinedQrl((_, elm) => {
|
|
236
|
+
const routeName = elm.getAttribute("data-q-route");
|
|
237
|
+
if (routeName) preloadRouteBundles(routeName, 1);
|
|
197
238
|
prefetchRoute(new URL(elm.href), false, 1);
|
|
198
239
|
}, "Link_component_handlePreload_AAemwtuBjsE"),
|
|
199
240
|
onClick$,
|
|
@@ -202,12 +243,12 @@ var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
|
|
|
202
243
|
"q-e:pointerenter": [
|
|
203
244
|
linkProps.onPointerEnter$,
|
|
204
245
|
prefetchDataProp === "intent" ? prefetchData : null,
|
|
205
|
-
prefetchBundlesProp === "
|
|
246
|
+
prefetchBundlesProp === "commit" ? null : handleBundlePrefetch
|
|
206
247
|
],
|
|
207
248
|
"q-e:focus": [
|
|
208
249
|
linkProps.onFocus$,
|
|
209
250
|
prefetchDataProp === "intent" ? prefetchData : null,
|
|
210
|
-
prefetchBundlesProp === "
|
|
251
|
+
prefetchBundlesProp === "commit" ? null : handleBundlePrefetch
|
|
211
252
|
],
|
|
212
253
|
"q-e:pointerdown": [
|
|
213
254
|
linkProps.onPointerDown$,
|
|
@@ -217,32 +258,7 @@ var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
|
|
|
217
258
|
"q-e:keydown": [linkProps.onKeyDown$, prefetchDataProp === "commit" || prefetchBundlesProp === "commit" ? onEnterKeyDown : null]
|
|
218
259
|
}, null, /*#__PURE__*/ _jsxSorted(Slot, null, null, null, 3, "xa_0"), 0, "xa_1");
|
|
219
260
|
}, "Link_component_VPmar9tb3t4"));
|
|
220
|
-
var
|
|
221
|
-
if (navType !== "popstate") {
|
|
222
|
-
const samePath = isSamePath(fromURL, toURL);
|
|
223
|
-
const sameHash = fromURL.hash === toURL.hash;
|
|
224
|
-
if (!samePath || !sameHash) {
|
|
225
|
-
const newState = { _qRouterScroll: newScrollState() };
|
|
226
|
-
if (replaceState) win.history.replaceState(newState, "", toPath(toURL));
|
|
227
|
-
else win.history.pushState(newState, "", toPath(toURL));
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
var newScrollState = () => {
|
|
232
|
-
return {
|
|
233
|
-
x: 0,
|
|
234
|
-
y: 0,
|
|
235
|
-
w: 0,
|
|
236
|
-
h: 0
|
|
237
|
-
};
|
|
238
|
-
};
|
|
239
|
-
var preloadRouteBundles = (routeName, probability = .8) => {
|
|
240
|
-
if (isBrowser) {
|
|
241
|
-
routeName = ensureSlash(routeName);
|
|
242
|
-
routeName = routeName.length > 1 && routeName.startsWith("/") ? routeName.slice(1) : routeName;
|
|
243
|
-
_requestPreload(routeName, probability);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
261
|
+
var VISIBLE_LINK_PRIORITY = .5;
|
|
246
262
|
var prefetchedLinks = /* @__PURE__ */ new WeakSet();
|
|
247
263
|
var cleanupPrefetchObserver;
|
|
248
264
|
var resetLinkPrefetchState = () => {
|
|
@@ -273,7 +289,10 @@ var createLinkPrefetchObserver = (manifestHash) => {
|
|
|
273
289
|
if (!isSameOrigin(url, currentUrl) || !shouldPreload(toPath(url), { url: currentUrl })) return;
|
|
274
290
|
const mode = anchor.getAttribute("data-q-prefetch") || "";
|
|
275
291
|
const routeName = anchor.getAttribute("data-q-route");
|
|
276
|
-
if (mode.includes("b") && routeName)
|
|
292
|
+
if (mode.includes("b") && routeName) {
|
|
293
|
+
const newLayoutKeys = anchor.getAttribute("data-q-layouts")?.split(" ");
|
|
294
|
+
preloadRouteBundles(routeName, VISIBLE_LINK_PRIORITY, newLayoutKeys);
|
|
295
|
+
}
|
|
277
296
|
if (mode.includes("d")) prefetchRoute(url, true, .8, manifestHash, false);
|
|
278
297
|
};
|
|
279
298
|
if (typeof IntersectionObserver === "undefined") {
|
|
@@ -529,6 +548,39 @@ var startViewTransition = (params) => {
|
|
|
529
548
|
} else return { ready: params.update() };
|
|
530
549
|
};
|
|
531
550
|
/**
|
|
551
|
+
* Qwik Router Component
|
|
552
|
+
*
|
|
553
|
+
* This file contains the main Qwik Router component, which initializes the router and provides the
|
|
554
|
+
* necessary context for it to work. It also contains the logic for handling navigation, including
|
|
555
|
+
* updating the URL, managing scroll restoration, and resolving document head changes.
|
|
556
|
+
*
|
|
557
|
+
* Note: This component is designed to work both on the server and the client. During server-side
|
|
558
|
+
* rendering (SSR), it initializes the router state based on the URL and route data provided by the
|
|
559
|
+
* server environment. On the client, it handles navigation events and updates the router state
|
|
560
|
+
* accordingly.
|
|
561
|
+
*
|
|
562
|
+
* SSR is _required_ for the initial load.
|
|
563
|
+
*
|
|
564
|
+
* The flow of navigation is as follows:
|
|
565
|
+
*
|
|
566
|
+
* 1. During SSR, the server environment parses the initial URL and collects the route data.
|
|
567
|
+
* 2. It runs the middleware hooks (`onRequest`, `onGet`, `onPost`, etc.), and responds to q-loader,
|
|
568
|
+
* action$ and server$ requests.
|
|
569
|
+
* 3. If SSR is deemed appropriate, the route data is provided via `useServerData` and this component
|
|
570
|
+
* uses it to initialize the router contexts, register Tasks, and render the Slot. This component
|
|
571
|
+
* will never render again.
|
|
572
|
+
* 4. Then, slotted components like `<DocumentHeadTags />` and `<RouterOutlet />` can consume the route
|
|
573
|
+
* data to render the page.
|
|
574
|
+
* 5. On the client, when a navigation event occurs, this calls `goto()`, which updates the URL in the
|
|
575
|
+
* same tick, loads the route data and adjusts the router context.
|
|
576
|
+
* 6. The changed contexts trigger the slotted components to re-render with the new route data.
|
|
577
|
+
*
|
|
578
|
+
* Since the head data can depend on route loaders and they get their data asynchronously and can
|
|
579
|
+
* update without navigation, the head is resolved in a separate Task that tracks the relevant
|
|
580
|
+
* signals.
|
|
581
|
+
*/
|
|
582
|
+
var LEFT_PAGE_PRIORITY = .6;
|
|
583
|
+
/**
|
|
532
584
|
* @deprecated Use `QWIK_ROUTER_SCROLLER` instead (will be removed in V3)
|
|
533
585
|
* @public
|
|
534
586
|
*/
|
|
@@ -814,7 +866,10 @@ var useQwikRouter = (props) => {
|
|
|
814
866
|
routeInternal.value = navigation;
|
|
815
867
|
navResolver.dest = void 0;
|
|
816
868
|
if (wasNavigating) abortRouteLoaderNavigation(routeLoaderCtx);
|
|
817
|
-
if (isBrowser)
|
|
869
|
+
if (isBrowser) {
|
|
870
|
+
prefetchRoute(dest, false, 1, manifestHash, true, routeLocation.url);
|
|
871
|
+
if (!isSamePath(dest, routeLocation.url)) prefetchRoute(routeLocation.url, false, LEFT_PAGE_PRIORITY, manifestHash, true, dest);
|
|
872
|
+
}
|
|
818
873
|
navResolver.p = new Promise((resolve) => {
|
|
819
874
|
navResolver.r = () => {
|
|
820
875
|
navResolver.r = void 0;
|
|
@@ -954,7 +1009,7 @@ var useQwikRouter = (props) => {
|
|
|
954
1009
|
const { $routeName$, $params$, $mods$, $menu$, $notFound$ } = loadedRoute;
|
|
955
1010
|
const contentModules = $mods$;
|
|
956
1011
|
routeLoaderCtx.goto = noSerialize((path, opt) => prepareNavigation(path, opt).prepared);
|
|
957
|
-
const routeLoaders = prepareRouteLoaders(contentModules, loaderState, routeLoaderCtx, rewrittenTo ? void 0 : loadedRoute.$loaderPaths$, trackUrl, prevUrl, navCountBefore, action ? actionLoaderHashes ?? null : void 0, action ?? navigation);
|
|
1012
|
+
const routeLoaders = prepareRouteLoaders(contentModules, loaderState, routeLoaderCtx, rewrittenTo ? void 0 : loadedRoute.$loaderPaths$, trackUrl, prevUrl, navCountBefore, action ? actionLoaderHashes ?? null : void 0, action ?? navigation, navigation.forceReload);
|
|
958
1013
|
await whenReady(() => {
|
|
959
1014
|
for (let i = 0; i < routeLoaders.length; i++) {
|
|
960
1015
|
const loader = routeLoaders[i];
|
|
@@ -1303,8 +1358,9 @@ var RouterOutlet = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl(() => {
|
|
|
1303
1358
|
const nav = useNavigate();
|
|
1304
1359
|
const contents = internalContext.value;
|
|
1305
1360
|
if (contents && contents.length > 0) {
|
|
1361
|
+
const contentsLen = contents.length;
|
|
1306
1362
|
let cmp = null;
|
|
1307
|
-
for (let i =
|
|
1363
|
+
for (let i = contentsLen - 1; i >= 0; i--) if (contents[i].default) cmp = /*#__PURE__*/ _jsxSorted(contents[i].default, null, null, cmp, 1, "yd_0");
|
|
1308
1364
|
return /*#__PURE__*/ _jsxSorted(Fragment, null, null, [cmp, !__EXPERIMENTAL__.noSPA && /*#__PURE__*/ _jsxSorted("script", {
|
|
1309
1365
|
"q-d:qcinit": [spa_init_default, linkPrefetchInit],
|
|
1310
1366
|
"q-d:qinit": _qrlSync(() => {
|
|
@@ -1759,9 +1815,9 @@ var GetForm = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((_rawProps) =>
|
|
|
1759
1815
|
..._getVarProps(rest),
|
|
1760
1816
|
"q-e:submit": [
|
|
1761
1817
|
...Array.isArray(_rawProps.onSubmit$) ? _rawProps.onSubmit$ : [_rawProps.onSubmit$],
|
|
1762
|
-
/*#__PURE__*/ inlinedQrl(async (
|
|
1818
|
+
/*#__PURE__*/ inlinedQrl(async (evt, form) => {
|
|
1763
1819
|
let nav = _capturesObj._[0];
|
|
1764
|
-
const formData = new FormData(form);
|
|
1820
|
+
const formData = new FormData(form, evt.submitter);
|
|
1765
1821
|
const params = new URLSearchParams();
|
|
1766
1822
|
formData.forEach((value, key) => {
|
|
1767
1823
|
if (typeof value === "string") params.append(key, value);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
2
1
|
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
2
|
+
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
3
3
|
import { isDev } from "@qwik.dev/core/build";
|
|
4
4
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
5
5
|
import { extname, join } from "node:path";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
2
1
|
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
2
|
+
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
3
3
|
import { isDev } from "@qwik.dev/core/build";
|
|
4
4
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
5
5
|
import { isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as validateRequestBodyLimit, n as RequestBodyLimitError, t as DEFAULT_REQUEST_BODY_LIMIT } from "../../chunks/request-body-limit.mjs";
|
|
2
1
|
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
3
2
|
import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
|
|
3
|
+
import { i as validateRequestBodyLimit, n as RequestBodyLimitError, t as DEFAULT_REQUEST_BODY_LIMIT } from "../../chunks/request-body-limit.mjs";
|
|
4
4
|
import { isDev } from "@qwik.dev/core";
|
|
5
5
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
6
6
|
import { createReadStream } from "node:fs";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as loadRoute, pt as _asyncRequestStore, z as getRouterConfig } from "../../chunks/head.qwik.mjs";
|
|
2
|
+
import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
|
|
3
|
+
import { a as getStaticPathRedirect, d as RewriteMessage, f as mergeHeadersCookies, h as clearSsrCache, i as resolveRequestHandlers, m as clearLoaderCache, n as getErrorHtml, o as isStaticPath, p as resolveLoaderPagePathname, r as renderQwikMiddleware, t as runQwikRouter } from "../../chunks/user-response.mjs";
|
|
2
4
|
import { c as recognizeRequest, d as trimRecognizedInternalPathname, u as trimInternalPathname } from "../../chunks/request-path.mjs";
|
|
3
5
|
import { i as RedirectMessage, r as AbortMessage, t as ServerError } from "../../chunks/server-error.mjs";
|
|
4
|
-
import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
|
|
5
|
-
import { a as getStaticPathRedirect, d as mergeHeadersCookies, f as resolveLoaderPagePathname, i as resolveRequestHandlers, m as clearSsrCache, n as getErrorHtml, o as isStaticPath, p as clearLoaderCache, r as renderQwikMiddleware, t as runQwikRouter, u as RewriteMessage } from "../../chunks/user-response.mjs";
|
|
6
6
|
import { isDev } from "@qwik.dev/core";
|
|
7
7
|
/**
|
|
8
8
|
* The request handler for QwikRouter. Called by every adapter.
|
package/lib/ssg/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { r as msToString } from "../chunks/format.mjs";
|
|
1
2
|
import { n as getPathnameForDynamicRoute, t as ensureSlash } from "../chunks/pathname.mjs";
|
|
2
3
|
import { n as isStaticTrieKey, r as unescapeStaticTrieKey } from "../chunks/route-trie-key.mjs";
|
|
3
|
-
import { r as msToString } from "../chunks/format.mjs";
|
|
4
4
|
import { t as createRouteTester } from "../chunks/routes.mjs";
|
|
5
5
|
import { relative } from "node:path";
|
|
6
6
|
import { bold, dim, green, magenta, red } from "kleur/colors";
|
package/lib/vite/index.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ declare interface PluginOptions {
|
|
|
109
109
|
platform?: Record<string, unknown>;
|
|
110
110
|
/** Configuration to rewrite url paths */
|
|
111
111
|
rewriteRoutes?: RewriteRouteOption[];
|
|
112
|
-
/** The serialization strategy for route loaders. Defaults to `
|
|
112
|
+
/** The serialization strategy for route loaders. Defaults to `auto`. */
|
|
113
113
|
defaultLoadersSerializationStrategy?: SerializationStrategy;
|
|
114
114
|
/**
|
|
115
115
|
* Enable strict mode for route loaders and actions by default.
|
package/lib/vite/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { _ as normalizePath$1, a as getPathnameFromDirPath, b as parseRouteIndexName, c as isIndexModule, d as isMenuFileName, f as isModuleExt, g as isServiceWorkerName, h as isPluginModule, i as getMenuPathname, l as isLayoutModule, m as isPageModuleExt, n as createFileId, o as isEntryName, p as isPageExt, r as getExtension, s as isErrorName, t as caughtErrorName, u as isMarkdownExt, v as normalizePathKey, x as removeExtension } from "../chunks/fs.mjs";
|
|
2
|
+
import { n as addWarning, t as addError } from "../chunks/format.mjs";
|
|
1
3
|
import { r as isSameOriginUrl, t as ensureSlash } from "../chunks/pathname.mjs";
|
|
2
|
-
import {
|
|
4
|
+
import { t as createRouteTester } from "../chunks/routes.mjs";
|
|
3
5
|
import { t as escapeStaticTrieKey } from "../chunks/route-trie-key.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { _ as normalizePath$1, a as getPathnameFromDirPath, b as parseRouteIndexName, c as isIndexModule, d as isMenuFileName, f as isModuleExt, g as isServiceWorkerName, h as isPluginModule, i as getMenuPathname, l as isLayoutModule, m as isPageModuleExt, n as createFileId, o as isEntryName, p as isPageExt, r as getExtension, s as isErrorName, t as caughtErrorName, u as isMarkdownExt, v as normalizePathKey, x as removeExtension } from "../chunks/fs.mjs";
|
|
6
|
+
import { c as recognizeRequest, d as trimRecognizedInternalPathname, l as resolveValidInternalFullPathname } from "../chunks/request-path.mjs";
|
|
6
7
|
import { t as devPreloadedRouteLoaders } from "../chunks/dev-preloaded-route-loader.mjs";
|
|
7
|
-
import { t as createRouteTester } from "../chunks/routes.mjs";
|
|
8
8
|
import fs, { existsSync } from "node:fs";
|
|
9
9
|
import path, { basename, dirname, extname, isAbsolute, join, posix, resolve } from "node:path";
|
|
10
10
|
import { readFile } from "node:fs/promises";
|
|
@@ -1029,6 +1029,7 @@ function createRoutes(ctx, qwikPlugin, c, esmImports, isSSR, loadersByFile, serv
|
|
|
1029
1029
|
esmImports.push(`import * as ${id}_ from ${importPath};`);
|
|
1030
1030
|
c.push(`const ${id} = ()=>${id}_;`);
|
|
1031
1031
|
}
|
|
1032
|
+
c.push(`${id}._K = ${JSON.stringify(id)};`);
|
|
1032
1033
|
}
|
|
1033
1034
|
}
|
|
1034
1035
|
if (menuCount > 0) {
|
|
@@ -1364,31 +1365,70 @@ function builtChunksPlugin(bundle) {
|
|
|
1364
1365
|
}
|
|
1365
1366
|
function getRouteImports(routes, manifest) {
|
|
1366
1367
|
const result = {};
|
|
1368
|
+
const layouts = /* @__PURE__ */ new Map();
|
|
1367
1369
|
routes.forEach((route) => {
|
|
1368
|
-
const
|
|
1369
|
-
const bundles = [];
|
|
1370
|
-
for (const [bundleName, bundle] of Object.entries(manifest.bundles)) if (isBundlePartOfRoute(bundle, routeAndLayoutPaths)) bundles.push(bundleName);
|
|
1370
|
+
const bundles = getBundlesOfFile(manifest, route.filePath);
|
|
1371
1371
|
if (bundles.length > 0) result[ensureSlash(route.routeName)] = { dynamicImports: bundles };
|
|
1372
|
+
route.layouts?.forEach((layout) => layouts.set(layout.id, layout));
|
|
1373
|
+
});
|
|
1374
|
+
layouts.forEach((layout) => {
|
|
1375
|
+
const bundles = getBundlesOfFile(manifest, layout.filePath);
|
|
1376
|
+
if (bundles.length > 0) result[layout.id] = { dynamicImports: bundles };
|
|
1372
1377
|
});
|
|
1373
1378
|
for (const bundleName of Object.keys(manifest.bundles)) {
|
|
1374
1379
|
const bundle = manifest.bundles[bundleName];
|
|
1375
1380
|
if (bundle.origins?.some((s) => s.endsWith("@qwik-router-config"))) {
|
|
1376
1381
|
result[bundleName] = {
|
|
1377
1382
|
...bundle,
|
|
1378
|
-
dynamicImports: bundle.dynamicImports?.filter((d) => manifest.bundles[d].origins?.some((s) => s.endsWith("menu.md")))
|
|
1383
|
+
dynamicImports: bundle.dynamicImports?.filter((d) => bundle.qrlImports?.includes(d) || manifest.bundles[d].origins?.some((s) => s.endsWith("menu.md")))
|
|
1379
1384
|
};
|
|
1385
|
+
addRouterConfigToItsImporters(manifest, bundleName, result);
|
|
1380
1386
|
break;
|
|
1381
1387
|
}
|
|
1382
1388
|
}
|
|
1383
1389
|
return result;
|
|
1384
1390
|
}
|
|
1385
|
-
function
|
|
1386
|
-
if (
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
+
function addRouterConfigToItsImporters(manifest, routerConfigBundleName, result) {
|
|
1392
|
+
for (const [bundleName, bundle] of Object.entries(manifest.bundles)) if (bundle.dynamicImports?.includes(routerConfigBundleName)) result[bundleName] = {
|
|
1393
|
+
...bundle,
|
|
1394
|
+
dynamicImports: [...bundle.qrlImports ?? [], routerConfigBundleName]
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
function getBundlesOfFile(manifest, filePath) {
|
|
1398
|
+
const extlessFilePath = removeExtension(filePath);
|
|
1399
|
+
const bundles = [];
|
|
1400
|
+
for (const [bundleName, bundle] of Object.entries(manifest.bundles)) if (isBundleOfFile(bundle, extlessFilePath)) bundles.push(bundleName);
|
|
1401
|
+
return bundles;
|
|
1391
1402
|
}
|
|
1403
|
+
function isBundleOfFile(bundle, extlessFilePath) {
|
|
1404
|
+
if (!bundle.origins) return false;
|
|
1405
|
+
return bundle.origins.some((bundleOrigin) => extlessFilePath.endsWith(removeExtension(bundleOrigin)));
|
|
1406
|
+
}
|
|
1407
|
+
var ROUTER_CHUNK_NAME = "qwik-router";
|
|
1408
|
+
var ROUTER_RUNTIME_MODULE = /[/\\](?:qwik-router|@qwik\.dev[/\\]router)[/\\]lib[/\\](?:index\.qwik|chunks[/\\][^/\\]+?)\.mjs(?:_\w+\.\w+)?$/;
|
|
1409
|
+
var LOADED_ON_DEMAND = /_(?:serverQrl|QwikRouterMockProvider|useQwikMockRouter)_/;
|
|
1410
|
+
var getRouterChunkName = (moduleId) => (moduleId === "@qwik-router-config" || ROUTER_RUNTIME_MODULE.test(moduleId)) && !LOADED_ON_DEMAND.test(moduleId) ? ROUTER_CHUNK_NAME : null;
|
|
1411
|
+
var addRouterChunkGroup = (output) => {
|
|
1412
|
+
const codeSplitting = typeof output.codeSplitting === "object" ? output.codeSplitting : {};
|
|
1413
|
+
return {
|
|
1414
|
+
...output,
|
|
1415
|
+
codeSplitting: {
|
|
1416
|
+
...codeSplitting,
|
|
1417
|
+
groups: [...codeSplitting.groups ?? [], {
|
|
1418
|
+
name: getRouterChunkName,
|
|
1419
|
+
priority: Number.MAX_SAFE_INTEGER,
|
|
1420
|
+
minSize: 0,
|
|
1421
|
+
minModuleSize: 0,
|
|
1422
|
+
minShareCount: 1,
|
|
1423
|
+
maxSize: Infinity,
|
|
1424
|
+
maxModuleSize: Infinity
|
|
1425
|
+
}]
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
};
|
|
1429
|
+
var registerRouterChunkAsEager = (api) => {
|
|
1430
|
+
if (!api.getOptions().experimental?.noSPA) api.registerEagerModules?.((id) => getRouterChunkName(id) !== null);
|
|
1431
|
+
};
|
|
1392
1432
|
var findLocation = (e) => {
|
|
1393
1433
|
const stack = e.stack;
|
|
1394
1434
|
if (typeof stack === "string") {
|
|
@@ -2326,7 +2366,7 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2326
2366
|
viteCommand = viteEnv.command;
|
|
2327
2367
|
return {
|
|
2328
2368
|
define: {
|
|
2329
|
-
"globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__": JSON.stringify(userOpts?.defaultLoadersSerializationStrategy || "
|
|
2369
|
+
"globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__": JSON.stringify(userOpts?.defaultLoadersSerializationStrategy || "auto"),
|
|
2330
2370
|
"globalThis.__NO_TRAILING_SLASH__": JSON.stringify(userOpts?.trailingSlash === false),
|
|
2331
2371
|
"globalThis.__QWIK_ROUTER_BASE_PATHNAME__": JSON.stringify(resolveBasePathname(userOpts, _viteConfig.base || "/")),
|
|
2332
2372
|
"globalThis.__SSR_CACHE_SIZE__": JSON.stringify(viteEnv.command === "serve" ? 0 : userOpts?.ssrCacheSize ?? 50),
|
|
@@ -2415,6 +2455,7 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2415
2455
|
qwikPlugin.api.registerBundleGraphAdder?.((manifest) => {
|
|
2416
2456
|
return getRouteImports(ctx.routes, manifest);
|
|
2417
2457
|
});
|
|
2458
|
+
registerRouterChunkAsEager(qwikPlugin.api);
|
|
2418
2459
|
outDir = config.build?.outDir;
|
|
2419
2460
|
serverEntryIds = getServerEntryIds(rootDir, qwikPlugin.api.getOptions().srcDir ?? void 0, config.build?.ssr, config.build?.rolldownOptions?.input);
|
|
2420
2461
|
},
|
|
@@ -2531,6 +2572,10 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2531
2572
|
}
|
|
2532
2573
|
return null;
|
|
2533
2574
|
},
|
|
2575
|
+
outputOptions(output) {
|
|
2576
|
+
if (this.environment.config.consumer !== "client") return null;
|
|
2577
|
+
return addRouterChunkGroup(output);
|
|
2578
|
+
},
|
|
2534
2579
|
async generateBundle(_, bundles) {
|
|
2535
2580
|
const manifest = qwikPlugin.api.getManifest();
|
|
2536
2581
|
if (manifest) {
|
|
@@ -2579,7 +2624,7 @@ async function generateServerPackageJson(outDir) {
|
|
|
2579
2624
|
* their `_regSymbol` side effects run before any RPC request arrives.
|
|
2580
2625
|
*/
|
|
2581
2626
|
function serverFnsPlugin(buildContextRef) {
|
|
2582
|
-
const RESOLVED_ID = "\
|
|
2627
|
+
const RESOLVED_ID = "\0" + VIRTUAL_SERVER_FNS;
|
|
2583
2628
|
const serverFnModules = /* @__PURE__ */ new Set();
|
|
2584
2629
|
let serverFnsReady = null;
|
|
2585
2630
|
function reset() {
|
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.
|
|
4
|
+
"version": "2.0.0-rc.6",
|
|
5
5
|
"bugs": "https://github.com/QwikDev/qwik/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@azure/functions": "3.5.1",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"valibot": ">=0.36.0 <2",
|
|
29
29
|
"vfile": "6.0.3",
|
|
30
30
|
"vite-imagetools": "10.0.0",
|
|
31
|
-
"yaml": "^2.
|
|
31
|
+
"yaml": "^2.9.1",
|
|
32
32
|
"zod": "^3.25.48"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
@@ -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.
|
|
44
|
-
"@qwik.dev/core": "2.0.0-rc.
|
|
43
|
+
"vite": "8.3.8",
|
|
44
|
+
"@qwik.dev/core": "2.0.0-rc.6"
|
|
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.
|
|
169
|
+
"@qwik.dev/core": "2.0.0-rc.6"
|
|
170
170
|
},
|
|
171
171
|
"publishConfig": {
|
|
172
172
|
"access": "public"
|