@qwik.dev/router 2.0.0-beta.35 → 2.0.0-beta.37
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 +2 -4
- package/lib/adapters/shared/vite/index.mjs +26 -23
- package/lib/chunks/action-handler.mjs +782 -0
- package/lib/chunks/deepFreeze.qwik.mjs +591 -1
- package/lib/chunks/format.mjs +31 -0
- package/lib/chunks/fs.mjs +4 -6
- package/lib/chunks/{routing.qwik.mjs → head.qwik.mjs} +299 -416
- package/lib/chunks/http-error.qwik.mjs +2 -2
- package/lib/chunks/not-found-wrapper.qwik.mjs +2 -2
- package/lib/chunks/pathname.mjs +3 -32
- package/lib/chunks/request-path.mjs +60 -0
- package/lib/chunks/system.mjs +6 -7
- package/lib/chunks/use-functions.qwik.mjs +3 -15
- package/lib/chunks/worker-thread.qwik.mjs +436 -425
- package/lib/index.d.ts +180 -13
- package/lib/index.qwik.mjs +640 -447
- package/lib/middleware/aws-lambda/index.mjs +2 -1
- package/lib/middleware/request-handler/index.d.ts +56 -16
- package/lib/middleware/request-handler/index.mjs +198 -754
- package/lib/ssg/index.d.ts +3 -3
- package/lib/ssg/index.mjs +4 -3
- package/lib/vite/index.d.ts +15 -0
- package/lib/vite/index.mjs +145 -23
- package/package.json +3 -3
- package/lib/chunks/redirect-handler.mjs +0 -6
package/lib/ssg/index.d.ts
CHANGED
|
@@ -79,13 +79,13 @@ export declare interface SsgRenderOptions extends RenderOptions {
|
|
|
79
79
|
log?: 'debug' | 'quiet';
|
|
80
80
|
/**
|
|
81
81
|
* Set to `false` if the generated static HTML files should not be written to disk. Setting to
|
|
82
|
-
* `false` is useful if the SSG should only write the
|
|
82
|
+
* `false` is useful if the SSG should only write the per-loader data files to disk. Defaults to
|
|
83
83
|
* `true`.
|
|
84
84
|
*/
|
|
85
85
|
emitHtml?: boolean;
|
|
86
86
|
/**
|
|
87
|
-
* Set to `false` if the generated
|
|
88
|
-
*
|
|
87
|
+
* Set to `false` if the generated per-loader data files should not be written to disk. Defaults
|
|
88
|
+
* to `true`.
|
|
89
89
|
*/
|
|
90
90
|
emitData?: boolean;
|
|
91
91
|
/**
|
package/lib/ssg/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bold, green, dim, red, magenta } from 'kleur/colors';
|
|
2
2
|
import { relative } from 'node:path';
|
|
3
|
-
import { m as msToString
|
|
3
|
+
import { m as msToString } from '../chunks/format.mjs';
|
|
4
|
+
import { e as ensureSlash, g as getPathnameForDynamicRoute } from '../chunks/pathname.mjs';
|
|
4
5
|
|
|
5
6
|
function routeToRegExp(rule) {
|
|
6
7
|
let transformedRule;
|
|
@@ -190,7 +191,7 @@ ${bold(red(`!!! ${result.pathname}: Error during SSG`))}`);
|
|
|
190
191
|
const segments = pathname.split("/");
|
|
191
192
|
const lastSegment = segments[segments.length - 1];
|
|
192
193
|
if (!lastSegment.includes(".")) {
|
|
193
|
-
pathname
|
|
194
|
+
pathname = ensureSlash(pathname);
|
|
194
195
|
}
|
|
195
196
|
}
|
|
196
197
|
} else {
|
|
@@ -220,7 +221,7 @@ ${bold(red(`!!! ${result.pathname}: Error during SSG`))}`);
|
|
|
220
221
|
index
|
|
221
222
|
];
|
|
222
223
|
const joinedParts = pathParts.join("/");
|
|
223
|
-
const originalPathname = basePathname + (joinedParts ? joinedParts
|
|
224
|
+
const originalPathname = basePathname + (joinedParts ? ensureSlash(joinedParts) : "");
|
|
224
225
|
const paramNames = pathParts.filter((p) => p.startsWith("[") && p.endsWith("]")).map((p) => p.startsWith("[...") ? p.slice(4, -1) : p.slice(1, -1));
|
|
225
226
|
if (paramNames.length === 0) {
|
|
226
227
|
addToQueue(originalPathname, void 0);
|
package/lib/vite/index.d.ts
CHANGED
|
@@ -111,6 +111,21 @@ declare interface PluginOptions {
|
|
|
111
111
|
rewriteRoutes?: RewriteRouteOption[];
|
|
112
112
|
/** The serialization strategy for route loaders. Defaults to `never`. */
|
|
113
113
|
defaultLoadersSerializationStrategy?: SerializationStrategy;
|
|
114
|
+
/**
|
|
115
|
+
* Enable strict mode for route loaders and actions by default.
|
|
116
|
+
*
|
|
117
|
+
* When true:
|
|
118
|
+
*
|
|
119
|
+
* - Loaders without an explicit `search` option act as if `search: []` — they only re-fetch when
|
|
120
|
+
* the route path changes and ignore all URL search params.
|
|
121
|
+
* - Actions without an explicit `invalidate` option act as if `invalidate: []` — they don't re-run
|
|
122
|
+
* any loaders after completion.
|
|
123
|
+
*
|
|
124
|
+
* Individual loaders/actions can override this by specifying `search` or `invalidate` explicitly.
|
|
125
|
+
*
|
|
126
|
+
* Defaults to `true`.
|
|
127
|
+
*/
|
|
128
|
+
strictLoaders?: boolean;
|
|
114
129
|
}
|
|
115
130
|
|
|
116
131
|
/**
|
package/lib/vite/index.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { mergeConfig, normalizePath as normalizePath$1, loadEnv } from 'vite';
|
|
|
2
2
|
import fs, { existsSync } from 'node:fs';
|
|
3
3
|
import path, { join, dirname, basename, resolve, isAbsolute, extname } from 'node:path';
|
|
4
4
|
import { g as getExtension, r as removeExtension, i as isIndexModule, a as isErrorName, b as isLayoutModule, c as isEntryName, d as isMenuFileName, e as isServiceWorkerName, f as isPageModuleExt, h as isModuleExt, j as isMarkdownExt, k as normalizePath, l as getPathnameFromDirPath, m as getMenuPathname, o as createFileId, p as parseRouteIndexName, q as isPluginModule, s as isPageExt } from '../chunks/fs.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { a as addError, b as addWarning } from '../chunks/format.mjs';
|
|
6
|
+
import { i as isSameOriginUrl, e as ensureSlash } from '../chunks/pathname.mjs';
|
|
6
7
|
import { marked } from 'marked';
|
|
7
8
|
import { createHash } from 'node:crypto';
|
|
8
9
|
import { SourceMapGenerator } from 'source-map';
|
|
@@ -96,7 +97,7 @@ The link "${url}", found within "${containingFilePath}" does not have a matching
|
|
|
96
97
|
url = url.slice(0, -1);
|
|
97
98
|
}
|
|
98
99
|
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
99
|
-
url
|
|
100
|
+
url = ensureSlash(url);
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
return url;
|
|
@@ -569,7 +570,7 @@ function deriveFromTrie(opts, root) {
|
|
|
569
570
|
function translateRoute(route, config, configIndex) {
|
|
570
571
|
const replacePath = (part) => (config.paths || {})[part] ?? part;
|
|
571
572
|
const pathnamePrefix = config.prefix ? "/" + config.prefix : "";
|
|
572
|
-
const routeNamePrefix = config.prefix ? config.prefix
|
|
573
|
+
const routeNamePrefix = config.prefix ? ensureSlash(config.prefix) : "";
|
|
573
574
|
const idSuffix = config.prefix?.toUpperCase().replace(/-/g, "");
|
|
574
575
|
const patternInfix = config.prefix ? [
|
|
575
576
|
config.prefix
|
|
@@ -788,7 +789,7 @@ function normalizeOptions(rootDir, viteBasePath, userOpts) {
|
|
|
788
789
|
if (!(viteBasePath.startsWith("/") && viteBasePath.endsWith("/"))) {
|
|
789
790
|
console.error(`warning: vite's config.base must begin and end with /. This will be an error in v2. If you have a valid use case, please open an issue.`);
|
|
790
791
|
if (!viteBasePath.endsWith("/")) {
|
|
791
|
-
viteBasePath
|
|
792
|
+
viteBasePath = ensureSlash(viteBasePath);
|
|
792
793
|
}
|
|
793
794
|
}
|
|
794
795
|
const opts = {
|
|
@@ -814,12 +815,15 @@ function normalizeOptions(rootDir, viteBasePath, userOpts) {
|
|
|
814
815
|
}
|
|
815
816
|
if (!opts.basePathname.endsWith("/")) {
|
|
816
817
|
console.error(`Warning: qwik-router plugin basePathname must end with /. This will be an error in v2`);
|
|
817
|
-
opts.basePathname
|
|
818
|
+
opts.basePathname = ensureSlash(opts.basePathname);
|
|
818
819
|
}
|
|
819
820
|
const url = new URL(opts.basePathname, "https://qwik.dev/");
|
|
820
821
|
opts.basePathname = url.pathname;
|
|
821
822
|
opts.mdx = opts.mdx || {};
|
|
822
823
|
opts.platform = opts.platform || {};
|
|
824
|
+
if (opts.strictLoaders === void 0) {
|
|
825
|
+
opts.strictLoaders = true;
|
|
826
|
+
}
|
|
823
827
|
return opts;
|
|
824
828
|
}
|
|
825
829
|
function createBuildContext(rootDir, viteBasePath, userOpts, target, dynamicImports) {
|
|
@@ -1314,7 +1318,7 @@ function getClientRouteBundleNames(qwikPlugin, r) {
|
|
|
1314
1318
|
}
|
|
1315
1319
|
return bundlesNames;
|
|
1316
1320
|
}
|
|
1317
|
-
function serializeBuildTrie(ctx, qwikPlugin, node, layoutIdMap, routeIdMap, menuIdMap, errorFiles, notFoundFiles, ancestorLayouts, isSSR, indent) {
|
|
1321
|
+
function serializeBuildTrie(ctx, qwikPlugin, node, layoutIdMap, routeIdMap, menuIdMap, errorFiles, notFoundFiles, ancestorLayouts, isSSR, indent, loadersByFile) {
|
|
1318
1322
|
const lines = [];
|
|
1319
1323
|
const nextIndent = indent + " ";
|
|
1320
1324
|
if (node._P) {
|
|
@@ -1413,6 +1417,31 @@ function serializeBuildTrie(ctx, qwikPlugin, node, layoutIdMap, routeIdMap, menu
|
|
|
1413
1417
|
}
|
|
1414
1418
|
}
|
|
1415
1419
|
}
|
|
1420
|
+
{
|
|
1421
|
+
const routeFiles = node._files.filter((f) => f.type === "route" || f.type === "layout").map((f) => f.filePath);
|
|
1422
|
+
if (node === ctx.routeTrie) {
|
|
1423
|
+
for (const plugin of ctx.serverPlugins) {
|
|
1424
|
+
routeFiles.push(plugin.filePath);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
if (routeFiles.length > 0) {
|
|
1428
|
+
if (loadersByFile) {
|
|
1429
|
+
const nodeLoaderHashes = [];
|
|
1430
|
+
for (const filePath of routeFiles) {
|
|
1431
|
+
const hashes = loadersByFile.get(filePath);
|
|
1432
|
+
if (hashes) {
|
|
1433
|
+
nodeLoaderHashes.push(...hashes);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
if (nodeLoaderHashes.length > 0) {
|
|
1437
|
+
lines.push(`${nextIndent}_R: ${JSON.stringify(nodeLoaderHashes)},`);
|
|
1438
|
+
}
|
|
1439
|
+
} else {
|
|
1440
|
+
const placeholder = `__LOADERS:${routeFiles.join("|")}__`;
|
|
1441
|
+
lines.push(`${nextIndent}_R: ${JSON.stringify(placeholder)},`);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1416
1445
|
if (errorExpr) {
|
|
1417
1446
|
lines.push(`${nextIndent}_E: ${errorExpr},`);
|
|
1418
1447
|
}
|
|
@@ -1445,7 +1474,7 @@ function serializeBuildTrie(ctx, qwikPlugin, node, layoutIdMap, routeIdMap, menu
|
|
|
1445
1474
|
groupChildren.sort((a, b) => a[0].localeCompare(b[0]));
|
|
1446
1475
|
const groupStrs = [];
|
|
1447
1476
|
for (const [_key, child] of groupChildren) {
|
|
1448
|
-
const childStr = serializeBuildTrie(ctx, qwikPlugin, child, layoutIdMap, routeIdMap, menuIdMap, errorFiles, notFoundFiles, childAncestors, isSSR, nextIndent);
|
|
1477
|
+
const childStr = serializeBuildTrie(ctx, qwikPlugin, child, layoutIdMap, routeIdMap, menuIdMap, errorFiles, notFoundFiles, childAncestors, isSSR, nextIndent, loadersByFile);
|
|
1449
1478
|
if (childStr !== "{}") {
|
|
1450
1479
|
groupStrs.push(childStr);
|
|
1451
1480
|
}
|
|
@@ -1455,7 +1484,7 @@ function serializeBuildTrie(ctx, qwikPlugin, node, layoutIdMap, routeIdMap, menu
|
|
|
1455
1484
|
}
|
|
1456
1485
|
}
|
|
1457
1486
|
for (const [key, child] of regularChildren) {
|
|
1458
|
-
const childStr = serializeBuildTrie(ctx, qwikPlugin, child, layoutIdMap, routeIdMap, menuIdMap, errorFiles, notFoundFiles, childAncestors, isSSR, nextIndent);
|
|
1487
|
+
const childStr = serializeBuildTrie(ctx, qwikPlugin, child, layoutIdMap, routeIdMap, menuIdMap, errorFiles, notFoundFiles, childAncestors, isSSR, nextIndent, loadersByFile);
|
|
1459
1488
|
if (childStr !== "{}") {
|
|
1460
1489
|
const keyStr = JSON.stringify(key);
|
|
1461
1490
|
lines.push(`${nextIndent}${keyStr}: ${childStr},`);
|
|
@@ -1468,7 +1497,7 @@ function serializeBuildTrie(ctx, qwikPlugin, node, layoutIdMap, routeIdMap, menu
|
|
|
1468
1497
|
${lines.join("\n")}
|
|
1469
1498
|
${indent}}`;
|
|
1470
1499
|
}
|
|
1471
|
-
function createRoutes(ctx, qwikPlugin, c, esmImports, isSSR) {
|
|
1500
|
+
function createRoutes(ctx, qwikPlugin, c, esmImports, isSSR, loadersByFile) {
|
|
1472
1501
|
const includeEndpoints = isSSR;
|
|
1473
1502
|
const dynamicImports = ctx.dynamicImports;
|
|
1474
1503
|
const layoutIdMap = /* @__PURE__ */ new Map();
|
|
@@ -1542,7 +1571,7 @@ function createRoutes(ctx, qwikPlugin, c, esmImports, isSSR) {
|
|
|
1542
1571
|
routeIdMap.set(route.filePath, `()=>${route.id}`);
|
|
1543
1572
|
}
|
|
1544
1573
|
}
|
|
1545
|
-
const trieStr = serializeBuildTrie(ctx, qwikPlugin, ctx.routeTrie, layoutIdMap, routeIdMap, menuIdMap, errorFiles, notFoundFiles, [], isSSR, "");
|
|
1574
|
+
const trieStr = serializeBuildTrie(ctx, qwikPlugin, ctx.routeTrie, layoutIdMap, routeIdMap, menuIdMap, errorFiles, notFoundFiles, [], isSSR, "", loadersByFile);
|
|
1546
1575
|
const baseSegments = ctx.opts.basePathname.split("/").filter((s) => s.length > 0);
|
|
1547
1576
|
let routesExpr = trieStr;
|
|
1548
1577
|
for (let j = baseSegments.length - 1; j >= 0; j--) {
|
|
@@ -1567,7 +1596,7 @@ function createServerPlugins(ctx, _qwikPlugin, c, esmImports, isSSR) {
|
|
|
1567
1596
|
c.push(`];`);
|
|
1568
1597
|
}
|
|
1569
1598
|
|
|
1570
|
-
function generateQwikRouterConfig(ctx, qwikPlugin, isSSR) {
|
|
1599
|
+
function generateQwikRouterConfig(ctx, qwikPlugin, isSSR, loadersByFile) {
|
|
1571
1600
|
const esmImports = [];
|
|
1572
1601
|
const c = [];
|
|
1573
1602
|
c.push(`
|
|
@@ -1578,7 +1607,7 @@ import { isDev } from '@qwik.dev/core/build';`);
|
|
|
1578
1607
|
esmImports.push(`import 'virtual:qwik-router-server-fns';`);
|
|
1579
1608
|
}
|
|
1580
1609
|
createServerPlugins(ctx, qwikPlugin, c, esmImports, isSSR);
|
|
1581
|
-
createRoutes(ctx, qwikPlugin, c, esmImports, isSSR);
|
|
1610
|
+
createRoutes(ctx, qwikPlugin, c, esmImports, isSSR, loadersByFile);
|
|
1582
1611
|
createEntries(ctx, c);
|
|
1583
1612
|
c.push(`export const trailingSlash = ${JSON.stringify(!globalThis.__NO_TRAILING_SLASH__)};`);
|
|
1584
1613
|
c.push(`export const basePathname = ${JSON.stringify(ctx.opts.basePathname)};`);
|
|
@@ -2416,6 +2445,74 @@ const QWIK_ROUTER_ENTRIES_ID = "@qwik-router-entries";
|
|
|
2416
2445
|
const QWIK_ROUTER = "@qwik.dev/router";
|
|
2417
2446
|
const QWIK_ROUTER_SW_REGISTER = "@qwik-router-sw-register";
|
|
2418
2447
|
const VIRTUAL_SERVER_FNS = "virtual:qwik-router-server-fns";
|
|
2448
|
+
function replaceLoaderPlaceholders(code, loadersByFile) {
|
|
2449
|
+
return code.replace(/_R\s*:\s*"__LOADERS:([^"]+)__"\s*,?/g, (_match, paths) => {
|
|
2450
|
+
const filePaths = paths.split("|");
|
|
2451
|
+
const hashes = [];
|
|
2452
|
+
for (const filePath of filePaths) {
|
|
2453
|
+
const fileHashes = loadersByFile.get(filePath);
|
|
2454
|
+
if (fileHashes) {
|
|
2455
|
+
hashes.push(...fileHashes);
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
if (hashes.length > 0) {
|
|
2459
|
+
return `_R: ${JSON.stringify(hashes)},`;
|
|
2460
|
+
}
|
|
2461
|
+
return "";
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
function addRouteLoaderHash(loadersByFile, filePath, hash) {
|
|
2465
|
+
const normalizedPath = normalizePath(filePath);
|
|
2466
|
+
const existing = loadersByFile.get(normalizedPath);
|
|
2467
|
+
if (!existing) {
|
|
2468
|
+
loadersByFile.set(normalizedPath, [
|
|
2469
|
+
hash
|
|
2470
|
+
]);
|
|
2471
|
+
return true;
|
|
2472
|
+
}
|
|
2473
|
+
if (!existing.includes(hash)) {
|
|
2474
|
+
existing.push(hash);
|
|
2475
|
+
return true;
|
|
2476
|
+
}
|
|
2477
|
+
return false;
|
|
2478
|
+
}
|
|
2479
|
+
function clearRouteLoaderHashes(loadersByFile, filePath) {
|
|
2480
|
+
return loadersByFile.delete(normalizePath(filePath));
|
|
2481
|
+
}
|
|
2482
|
+
function isRouterSourceFilePath(filePath) {
|
|
2483
|
+
const fileName = basename(filePath);
|
|
2484
|
+
const extlessName = removeExtension(fileName);
|
|
2485
|
+
return isMenuFileName(fileName) || isIndexModule(extlessName) || isErrorName(extlessName) || isLayoutModule(extlessName) || isEntryName(extlessName) || isServiceWorkerName(extlessName) || isPluginModule(extlessName);
|
|
2486
|
+
}
|
|
2487
|
+
function isPathInDir(filePath, dirPath) {
|
|
2488
|
+
return filePath === dirPath || filePath.startsWith(`${dirPath}/`);
|
|
2489
|
+
}
|
|
2490
|
+
function isRouterSourceFileForContext(filePath, ctx) {
|
|
2491
|
+
const normalizedPath = normalizePath(filePath);
|
|
2492
|
+
return isRouterSourceFilePath(normalizedPath) && (isPathInDir(normalizedPath, ctx.opts.routesDir) || isPathInDir(normalizedPath, ctx.opts.serverPluginsDir));
|
|
2493
|
+
}
|
|
2494
|
+
function invalidateRouterConfigModules(server) {
|
|
2495
|
+
const modules = [];
|
|
2496
|
+
const moduleGraphs = /* @__PURE__ */ new Set();
|
|
2497
|
+
moduleGraphs.add(server.moduleGraph);
|
|
2498
|
+
const environments = server.environments;
|
|
2499
|
+
if (environments) {
|
|
2500
|
+
for (const environment of Object.values(environments)) {
|
|
2501
|
+
const graph = environment?.moduleGraph;
|
|
2502
|
+
if (graph) {
|
|
2503
|
+
moduleGraphs.add(graph);
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
for (const graph of moduleGraphs) {
|
|
2508
|
+
const mod = graph.getModuleById(QWIK_ROUTER_CONFIG_ID);
|
|
2509
|
+
if (mod) {
|
|
2510
|
+
graph.invalidateModule(mod);
|
|
2511
|
+
modules.push(mod);
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
return modules;
|
|
2515
|
+
}
|
|
2419
2516
|
async function generateServerPackageJson(outDir) {
|
|
2420
2517
|
await fs.promises.mkdir(outDir, {
|
|
2421
2518
|
recursive: true
|
|
@@ -2447,6 +2544,7 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2447
2544
|
let devSsrServer = userOpts?.devSsrServer;
|
|
2448
2545
|
const routesDir = userOpts?.routesDir ?? "src/routes";
|
|
2449
2546
|
const serverPluginsDir = userOpts?.serverPluginsDir ?? routesDir;
|
|
2547
|
+
const loadersByFile = /* @__PURE__ */ new Map();
|
|
2450
2548
|
const api = {
|
|
2451
2549
|
getBasePathname: () => ctx?.opts.basePathname ?? "/",
|
|
2452
2550
|
getRoutes: () => {
|
|
@@ -2466,7 +2564,8 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2466
2564
|
define: {
|
|
2467
2565
|
"globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__": JSON.stringify(userOpts?.defaultLoadersSerializationStrategy || "never"),
|
|
2468
2566
|
"globalThis.__NO_TRAILING_SLASH__": JSON.stringify(userOpts?.trailingSlash === false),
|
|
2469
|
-
"globalThis.__SSR_CACHE_SIZE__": JSON.stringify(viteEnv.command === "serve" ? 0 : userOpts?.ssrCacheSize ?? 50)
|
|
2567
|
+
"globalThis.__SSR_CACHE_SIZE__": JSON.stringify(viteEnv.command === "serve" ? 0 : userOpts?.ssrCacheSize ?? 50),
|
|
2568
|
+
"globalThis.__STRICT_LOADERS__": JSON.stringify(userOpts?.strictLoaders !== false)
|
|
2470
2569
|
},
|
|
2471
2570
|
appType: "custom",
|
|
2472
2571
|
resolve: {
|
|
@@ -2566,6 +2665,14 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2566
2665
|
if (!qwikPlugin) {
|
|
2567
2666
|
throw new Error("Missing vite-plugin-qwik");
|
|
2568
2667
|
}
|
|
2668
|
+
qwikPlugin.api.onSegment((parentId, segment) => {
|
|
2669
|
+
if (segment.ctxName === "routeLoader$") {
|
|
2670
|
+
const changed = addRouteLoaderHash(loadersByFile, parentId, segment.hash);
|
|
2671
|
+
if (changed && devServer) {
|
|
2672
|
+
invalidateRouterConfigModules(devServer);
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
});
|
|
2569
2676
|
if (typeof devSsrServer !== "boolean") {
|
|
2570
2677
|
devSsrServer = qwikPlugin.api._oldDevSsrServer();
|
|
2571
2678
|
}
|
|
@@ -2576,21 +2683,19 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2576
2683
|
},
|
|
2577
2684
|
async configureServer(server) {
|
|
2578
2685
|
devServer = server;
|
|
2579
|
-
const toWatch =
|
|
2686
|
+
const toWatch = [
|
|
2687
|
+
join(ctx.opts.routesDir, "**/{index,index!,index@*,layout,layout!,layout-*,error,404,entry,service-worker,menu}.{ts,tsx,js,jsx,md,mdx}"),
|
|
2688
|
+
join(ctx.opts.serverPluginsDir, "plugin{,@*}.{ts,tsx,js,jsx}")
|
|
2689
|
+
];
|
|
2580
2690
|
server.watcher.add(toWatch);
|
|
2581
2691
|
await new Promise((resolve2) => setTimeout(resolve2, 1e3));
|
|
2582
2692
|
server.watcher.on("change", (path) => {
|
|
2583
|
-
if (
|
|
2693
|
+
if (!isRouterSourceFileForContext(path, ctx)) {
|
|
2584
2694
|
return;
|
|
2585
2695
|
}
|
|
2696
|
+
clearRouteLoaderHashes(loadersByFile, path);
|
|
2586
2697
|
ctx.isDirty = true;
|
|
2587
|
-
|
|
2588
|
-
if (graph) {
|
|
2589
|
-
const mod = graph.getModuleById("@qwik-router-config");
|
|
2590
|
-
if (mod) {
|
|
2591
|
-
graph.invalidateModule(mod);
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2698
|
+
invalidateRouterConfigModules(server);
|
|
2594
2699
|
});
|
|
2595
2700
|
if (userOpts?.devSsrServer !== false) {
|
|
2596
2701
|
return () => {
|
|
@@ -2598,6 +2703,18 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2598
2703
|
};
|
|
2599
2704
|
}
|
|
2600
2705
|
},
|
|
2706
|
+
handleHotUpdate({ file, modules, server }) {
|
|
2707
|
+
if (!ctx || !isRouterSourceFileForContext(file, ctx)) {
|
|
2708
|
+
return;
|
|
2709
|
+
}
|
|
2710
|
+
clearRouteLoaderHashes(loadersByFile, file);
|
|
2711
|
+
ctx.isDirty = true;
|
|
2712
|
+
const configModules = invalidateRouterConfigModules(server);
|
|
2713
|
+
return [
|
|
2714
|
+
...modules,
|
|
2715
|
+
...configModules
|
|
2716
|
+
];
|
|
2717
|
+
},
|
|
2601
2718
|
transformIndexHtml() {
|
|
2602
2719
|
if (viteCommand !== "serve") {
|
|
2603
2720
|
return;
|
|
@@ -2638,7 +2755,7 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2638
2755
|
});
|
|
2639
2756
|
}
|
|
2640
2757
|
if (isRouterConfig) {
|
|
2641
|
-
return generateQwikRouterConfig(ctx, qwikPlugin, this.environment.config.consumer === "server");
|
|
2758
|
+
return generateQwikRouterConfig(ctx, qwikPlugin, this.environment.config.consumer === "server", devServer ? loadersByFile : void 0);
|
|
2642
2759
|
}
|
|
2643
2760
|
if (isSwRegister) {
|
|
2644
2761
|
return generateServiceWorkerRegister(ctx, swRegister);
|
|
@@ -2692,6 +2809,11 @@ function qwikRouterPlugin(userOpts, buildContextRef) {
|
|
|
2692
2809
|
return null;
|
|
2693
2810
|
},
|
|
2694
2811
|
generateBundle(_, bundles) {
|
|
2812
|
+
for (const chunk of Object.values(bundles)) {
|
|
2813
|
+
if (chunk.type === "chunk" && chunk.code.includes("__LOADERS:")) {
|
|
2814
|
+
chunk.code = replaceLoaderPlaceholders(chunk.code, loadersByFile);
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2695
2817
|
if (this.environment.config.consumer === "client") {
|
|
2696
2818
|
const entries = [
|
|
2697
2819
|
...ctx.entries,
|
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-beta.
|
|
4
|
+
"version": "2.0.0-beta.37",
|
|
5
5
|
"bugs": "https://github.com/QwikDev/qwik/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@azure/functions": "3.5.1",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"tsm": "2.3.0",
|
|
41
41
|
"typescript": "5.9.3",
|
|
42
42
|
"uvu": "0.5.6",
|
|
43
|
-
"@qwik.dev/core": "2.0.0-beta.
|
|
43
|
+
"@qwik.dev/core": "2.0.0-beta.37"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
"main": "./lib/index.qwik.mjs",
|
|
170
170
|
"peerDependencies": {
|
|
171
171
|
"vite": ">=6 <9",
|
|
172
|
-
"@qwik.dev/core": "^2.0.0-beta.
|
|
172
|
+
"@qwik.dev/core": "^2.0.0-beta.37"
|
|
173
173
|
},
|
|
174
174
|
"publishConfig": {
|
|
175
175
|
"access": "public"
|