@qwik.dev/router 2.0.0-alpha.9 → 2.0.0-beta.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/README.md +1 -1
- package/lib/adapters/azure-swa/vite/index.cjs +3 -3
- package/lib/adapters/azure-swa/vite/index.d.ts +13 -13
- package/lib/adapters/bun-server/vite/index.cjs +3 -3
- package/lib/adapters/bun-server/vite/index.d.ts +14 -14
- package/lib/adapters/cloud-run/vite/index.cjs +3 -3
- package/lib/adapters/cloud-run/vite/index.d.ts +13 -13
- package/lib/adapters/cloudflare-pages/vite/index.cjs +3 -3
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +27 -27
- package/lib/adapters/deno-server/vite/index.cjs +3 -3
- package/lib/adapters/deno-server/vite/index.d.ts +14 -14
- package/lib/adapters/netlify-edge/vite/index.cjs +3 -3
- package/lib/adapters/netlify-edge/vite/index.d.ts +44 -44
- package/lib/adapters/node-server/vite/index.cjs +3 -3
- package/lib/adapters/node-server/vite/index.d.ts +14 -14
- package/lib/adapters/shared/vite/index.cjs +10 -3
- package/lib/adapters/shared/vite/index.d.ts +114 -114
- package/lib/adapters/shared/vite/index.mjs +7 -0
- package/lib/adapters/static/vite/index.cjs +10 -3
- package/lib/adapters/static/vite/index.d.ts +10 -10
- package/lib/adapters/static/vite/index.mjs +7 -0
- package/lib/adapters/vercel-edge/vite/index.cjs +3 -3
- package/lib/adapters/vercel-edge/vite/index.d.ts +45 -45
- package/lib/index.d.ts +878 -810
- package/lib/index.qwik.cjs +110 -48
- package/lib/index.qwik.mjs +112 -50
- package/lib/middleware/aws-lambda/index.d.ts +48 -48
- package/lib/middleware/azure-swa/index.d.ts +28 -28
- package/lib/middleware/bun/index.d.ts +35 -35
- package/lib/middleware/cloudflare-pages/index.d.ts +35 -35
- package/lib/middleware/deno/index.d.ts +47 -47
- package/lib/middleware/firebase/index.d.ts +26 -26
- package/lib/middleware/netlify-edge/index.d.ts +27 -27
- package/lib/middleware/node/index.cjs +3 -3
- package/lib/middleware/node/index.d.ts +64 -64
- package/lib/middleware/request-handler/index.cjs +142 -73
- package/lib/middleware/request-handler/index.d.ts +710 -676
- package/lib/middleware/request-handler/index.mjs +138 -70
- package/lib/middleware/vercel-edge/index.d.ts +26 -26
- package/lib/service-worker.cjs +13 -263
- package/lib/service-worker.d.ts +15 -4
- package/lib/service-worker.mjs +13 -263
- package/lib/static/index.cjs +3 -3
- package/lib/static/index.d.ts +96 -96
- package/lib/static/node.cjs +3 -3
- package/lib/vite/index.cjs +209 -261
- package/lib/vite/index.d.ts +154 -154
- package/lib/vite/index.mjs +207 -259
- package/package.json +7 -7
package/lib/index.qwik.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("@qwik.dev/core/jsx-runtime");
|
|
4
4
|
const core = require("@qwik.dev/core");
|
|
5
|
+
const preloader = require("@qwik.dev/core/preloader");
|
|
5
6
|
const internal = require("@qwik.dev/core/internal");
|
|
6
7
|
const qwikRouterConfig = require("@qwik-router-config");
|
|
7
8
|
const zod = require("zod");
|
|
@@ -37,7 +38,6 @@ const ErrorBoundary = core.component$((props) => {
|
|
|
37
38
|
});
|
|
38
39
|
const MODULE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
39
40
|
const CLIENT_DATA_CACHE = /* @__PURE__ */ new Map();
|
|
40
|
-
const PREFETCHED_NAVIGATE_PATHS = /* @__PURE__ */ new Set();
|
|
41
41
|
const QACTION_KEY = "qaction";
|
|
42
42
|
const QFN_KEY = "qfunc";
|
|
43
43
|
const QDATA_KEY = "qdata";
|
|
@@ -75,15 +75,7 @@ const getClientNavPath = (props, baseUrl) => {
|
|
|
75
75
|
}
|
|
76
76
|
return null;
|
|
77
77
|
};
|
|
78
|
-
const
|
|
79
|
-
if (clientNavPath) {
|
|
80
|
-
const prefetchUrl = toUrl(clientNavPath, currentLoc.url);
|
|
81
|
-
const currentUrl = toUrl("", currentLoc.url);
|
|
82
|
-
return !isSamePath(prefetchUrl, currentUrl);
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
};
|
|
86
|
-
const shouldPrefetchSymbols = (clientNavPath, currentLoc) => {
|
|
78
|
+
const shouldPreload = (clientNavPath, currentLoc) => {
|
|
87
79
|
if (clientNavPath) {
|
|
88
80
|
const prefetchUrl = toUrl(clientNavPath, currentLoc.url);
|
|
89
81
|
const currentUrl = toUrl("", currentLoc.url);
|
|
@@ -133,16 +125,8 @@ const newScrollState = () => {
|
|
|
133
125
|
const prefetchSymbols = (path) => {
|
|
134
126
|
if (core.isBrowser) {
|
|
135
127
|
path = path.endsWith("/") ? path : path + "/";
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
document.dispatchEvent(new CustomEvent("qprefetch", {
|
|
139
|
-
detail: {
|
|
140
|
-
links: [
|
|
141
|
-
path
|
|
142
|
-
]
|
|
143
|
-
}
|
|
144
|
-
}));
|
|
145
|
-
}
|
|
128
|
+
path = path.length > 1 && path.startsWith("/") ? path.slice(1) : path;
|
|
129
|
+
preloader.p(path, 0.8);
|
|
146
130
|
}
|
|
147
131
|
};
|
|
148
132
|
const loadClientData = async (url, element, opts) => {
|
|
@@ -158,7 +142,7 @@ const loadClientData = async (url, element, opts) => {
|
|
|
158
142
|
}
|
|
159
143
|
let resolveFn;
|
|
160
144
|
if (!qData) {
|
|
161
|
-
const fetchOptions = getFetchOptions(opts?.action);
|
|
145
|
+
const fetchOptions = getFetchOptions(opts?.action, opts?.clearCache);
|
|
162
146
|
if (opts?.action) {
|
|
163
147
|
opts.action.data = void 0;
|
|
164
148
|
}
|
|
@@ -214,16 +198,19 @@ const loadClientData = async (url, element, opts) => {
|
|
|
214
198
|
return v;
|
|
215
199
|
});
|
|
216
200
|
};
|
|
217
|
-
const getFetchOptions = (action) => {
|
|
201
|
+
const getFetchOptions = (action, noCache) => {
|
|
218
202
|
const actionData = action?.data;
|
|
219
203
|
if (!actionData) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
204
|
+
if (noCache) {
|
|
205
|
+
return {
|
|
206
|
+
cache: "no-cache",
|
|
207
|
+
headers: {
|
|
208
|
+
"Cache-Control": "no-cache",
|
|
209
|
+
Pragma: "no-cache"
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return void 0;
|
|
227
214
|
}
|
|
228
215
|
if (actionData instanceof FormData) {
|
|
229
216
|
return {
|
|
@@ -267,14 +254,15 @@ const Link = core.component$((props) => {
|
|
|
267
254
|
const nav = useNavigate();
|
|
268
255
|
const loc = useLocation();
|
|
269
256
|
const originalHref = props.href;
|
|
257
|
+
const anchorRef = core.useSignal();
|
|
270
258
|
const { onClick$, prefetch: prefetchProp, reload, replaceState, scroll, ...linkProps } = /* @__PURE__ */ (() => props)();
|
|
271
259
|
const clientNavPath = core.untrack(() => getClientNavPath({
|
|
272
260
|
...linkProps,
|
|
273
261
|
reload
|
|
274
262
|
}, loc));
|
|
275
263
|
linkProps.href = clientNavPath || originalHref;
|
|
276
|
-
const prefetchData = core.untrack(() => !!clientNavPath && prefetchProp !== false && prefetchProp !== "js"
|
|
277
|
-
const prefetch = core.untrack(() => prefetchData || !!clientNavPath && prefetchProp !== false &&
|
|
264
|
+
const prefetchData = core.untrack(() => !!clientNavPath && prefetchProp !== false && prefetchProp !== "js" || void 0);
|
|
265
|
+
const prefetch = core.untrack(() => prefetchData || !!clientNavPath && prefetchProp !== false && shouldPreload(clientNavPath, loc));
|
|
278
266
|
const handlePrefetch = prefetch ? core.$((_, elm) => {
|
|
279
267
|
if (navigator.connection?.saveData) {
|
|
280
268
|
return;
|
|
@@ -308,7 +296,23 @@ const Link = core.component$((props) => {
|
|
|
308
296
|
}
|
|
309
297
|
}
|
|
310
298
|
}) : void 0;
|
|
299
|
+
core.useVisibleTask$(({ track }) => {
|
|
300
|
+
track(() => loc.url.pathname);
|
|
301
|
+
const handler = linkProps.onQVisible$;
|
|
302
|
+
if (handler) {
|
|
303
|
+
const event = new CustomEvent("qvisible");
|
|
304
|
+
if (Array.isArray(handler)) {
|
|
305
|
+
handler.flat(10).forEach((handler2) => handler2?.(event, anchorRef.value));
|
|
306
|
+
} else {
|
|
307
|
+
handler?.(event, anchorRef.value);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (!core.isDev && anchorRef.value) {
|
|
311
|
+
handlePrefetch?.(void 0, anchorRef.value);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
311
314
|
return /* @__PURE__ */ jsxRuntime.jsx("a", {
|
|
315
|
+
ref: anchorRef,
|
|
312
316
|
"q:link": !!clientNavPath,
|
|
313
317
|
...linkProps,
|
|
314
318
|
onClick$: [
|
|
@@ -325,11 +329,8 @@ const Link = core.component$((props) => {
|
|
|
325
329
|
linkProps.onFocus$,
|
|
326
330
|
handlePrefetch
|
|
327
331
|
],
|
|
328
|
-
//
|
|
329
|
-
onQVisible$: [
|
|
330
|
-
linkProps.onQVisible$,
|
|
331
|
-
!core.isDev ? handlePrefetch : void 0
|
|
332
|
-
],
|
|
332
|
+
// We need to prevent the onQVisible$ from being called twice since it is handled in the visible task
|
|
333
|
+
onQVisible$: [],
|
|
333
334
|
children: /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {})
|
|
334
335
|
});
|
|
335
336
|
});
|
|
@@ -770,6 +771,26 @@ const spaInit = core.event$((_, el) => {
|
|
|
770
771
|
}, 0);
|
|
771
772
|
}
|
|
772
773
|
});
|
|
774
|
+
const startViewTransition = (params) => {
|
|
775
|
+
if (!params.update) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
if ("startViewTransition" in document) {
|
|
779
|
+
let transition;
|
|
780
|
+
try {
|
|
781
|
+
transition = document.startViewTransition(params);
|
|
782
|
+
} catch {
|
|
783
|
+
transition = document.startViewTransition(params.update);
|
|
784
|
+
}
|
|
785
|
+
const event = new CustomEvent("qviewtransition", {
|
|
786
|
+
detail: transition
|
|
787
|
+
});
|
|
788
|
+
document.dispatchEvent(event);
|
|
789
|
+
return transition;
|
|
790
|
+
} else {
|
|
791
|
+
params.update?.();
|
|
792
|
+
}
|
|
793
|
+
};
|
|
773
794
|
const QWIK_CITY_SCROLLER = "_qCityScroller";
|
|
774
795
|
const QWIK_ROUTER_SCROLLER = "_qRouterScroller";
|
|
775
796
|
const preventNav = {};
|
|
@@ -777,7 +798,18 @@ const internalState = {
|
|
|
777
798
|
navCount: 0
|
|
778
799
|
};
|
|
779
800
|
const QwikRouterProvider = core.component$((props) => {
|
|
780
|
-
core.useStyles$(
|
|
801
|
+
core.useStyles$(`
|
|
802
|
+
@layer qwik {
|
|
803
|
+
@supports selector(html:active-view-transition-type(type)) {
|
|
804
|
+
html:active-view-transition-type(qwik-router-spa) {
|
|
805
|
+
:root{view-transition-name:none}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
@supports not selector(html:active-view-transition-type(type)) {
|
|
809
|
+
:root{view-transition-name:none}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
`);
|
|
781
813
|
const env = useQwikRouterEnv();
|
|
782
814
|
if (!env?.params) {
|
|
783
815
|
throw new Error(`Missing Qwik Router Env Data for help visit https://github.com/QwikDev/qwik/issues/6237`);
|
|
@@ -786,6 +818,11 @@ const QwikRouterProvider = core.component$((props) => {
|
|
|
786
818
|
if (!urlEnv) {
|
|
787
819
|
throw new Error(`Missing Qwik URL Env Data`);
|
|
788
820
|
}
|
|
821
|
+
if (core.isServer) {
|
|
822
|
+
if (env.ev.originalUrl.pathname !== env.ev.url.pathname && !__EXPERIMENTAL__.enableRequestRewrite) {
|
|
823
|
+
throw new Error(`enableRequestRewrite is an experimental feature and is not enabled. Please enable the feature flag by adding \`experimental: ["enableRequestRewrite"]\` to your qwikVite plugin options.`);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
789
826
|
const url = new URL(urlEnv);
|
|
790
827
|
const routeLocation = core.useStore({
|
|
791
828
|
url,
|
|
@@ -974,12 +1011,21 @@ const QwikRouterProvider = core.component$((props) => {
|
|
|
974
1011
|
const newHref = pageData.href;
|
|
975
1012
|
const newURL = new URL(newHref, trackUrl);
|
|
976
1013
|
if (!isSamePath(newURL, trackUrl)) {
|
|
977
|
-
|
|
978
|
-
|
|
1014
|
+
if (!pageData.isRewrite) {
|
|
1015
|
+
trackUrl = newURL;
|
|
1016
|
+
}
|
|
1017
|
+
loadRoutePromise = loadRoute(
|
|
1018
|
+
qwikRouterConfig__namespace.routes,
|
|
1019
|
+
qwikRouterConfig__namespace.menus,
|
|
1020
|
+
qwikRouterConfig__namespace.cacheModules,
|
|
1021
|
+
newURL.pathname
|
|
1022
|
+
// Load the actual required path.
|
|
1023
|
+
);
|
|
979
1024
|
}
|
|
980
1025
|
try {
|
|
981
1026
|
loadedRoute = await loadRoutePromise;
|
|
982
1027
|
} catch (e) {
|
|
1028
|
+
console.error(e);
|
|
983
1029
|
window.location.href = newHref;
|
|
984
1030
|
return;
|
|
985
1031
|
}
|
|
@@ -1014,9 +1060,6 @@ const QwikRouterProvider = core.component$((props) => {
|
|
|
1014
1060
|
documentHead.title = resolvedHead.title;
|
|
1015
1061
|
documentHead.frontmatter = resolvedHead.frontmatter;
|
|
1016
1062
|
if (core.isBrowser) {
|
|
1017
|
-
if (props.viewTransition !== false) {
|
|
1018
|
-
document.__q_view_transition__ = true;
|
|
1019
|
-
}
|
|
1020
1063
|
let scrollState;
|
|
1021
1064
|
if (navType === "popstate") {
|
|
1022
1065
|
scrollState = getScrollHistory();
|
|
@@ -1139,8 +1182,27 @@ const QwikRouterProvider = core.component$((props) => {
|
|
|
1139
1182
|
const scrollState2 = currentScrollState(scroller);
|
|
1140
1183
|
saveScrollHistory(scrollState2);
|
|
1141
1184
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1185
|
+
const navigate = () => {
|
|
1186
|
+
clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
|
|
1187
|
+
return internal._waitUntilRendered(elm);
|
|
1188
|
+
};
|
|
1189
|
+
const _waitNextPage = () => {
|
|
1190
|
+
if (core.isServer || props.viewTransition === false) {
|
|
1191
|
+
return navigate();
|
|
1192
|
+
} else {
|
|
1193
|
+
const viewTransition = startViewTransition({
|
|
1194
|
+
update: navigate,
|
|
1195
|
+
types: [
|
|
1196
|
+
"qwik-navigation"
|
|
1197
|
+
]
|
|
1198
|
+
});
|
|
1199
|
+
if (!viewTransition) {
|
|
1200
|
+
return Promise.resolve();
|
|
1201
|
+
}
|
|
1202
|
+
return viewTransition.ready;
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
_waitNextPage().then(() => {
|
|
1144
1206
|
const container = internal._getQContainerElement(elm);
|
|
1145
1207
|
container.setAttribute("q:route", routeName);
|
|
1146
1208
|
const scrollState2 = currentScrollState(scroller);
|
|
@@ -1155,11 +1217,10 @@ const QwikRouterProvider = core.component$((props) => {
|
|
|
1155
1217
|
}
|
|
1156
1218
|
}
|
|
1157
1219
|
}
|
|
1158
|
-
const promise = run();
|
|
1159
1220
|
if (core.isServer) {
|
|
1160
|
-
return
|
|
1221
|
+
return run();
|
|
1161
1222
|
} else {
|
|
1162
|
-
|
|
1223
|
+
run();
|
|
1163
1224
|
}
|
|
1164
1225
|
});
|
|
1165
1226
|
return /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {});
|
|
@@ -1722,7 +1783,8 @@ const deserializeStream = async function* (stream, ctxElm, abortSignal) {
|
|
|
1722
1783
|
reader.releaseLock();
|
|
1723
1784
|
}
|
|
1724
1785
|
};
|
|
1725
|
-
const ServiceWorkerRegister = (props) =>
|
|
1786
|
+
const ServiceWorkerRegister = (props) => /* @__PURE__ */ jsxRuntime.jsx("script", {
|
|
1787
|
+
type: "module",
|
|
1726
1788
|
dangerouslySetInnerHTML: swRegister,
|
|
1727
1789
|
nonce: props.nonce
|
|
1728
1790
|
});
|
package/lib/index.qwik.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from "@qwik.dev/core/jsx-runtime";
|
|
2
|
-
import { component$, useErrorBoundary, useOnWindow, $, Slot, isBrowser, createContextId, implicit$FirstArg, useContext, useVisibleTask$, noSerialize, useServerData, untrack, sync$, isDev, withLocale, event$, useStyles$,
|
|
3
|
-
import {
|
|
2
|
+
import { component$, useErrorBoundary, useOnWindow, $, Slot, isBrowser, createContextId, implicit$FirstArg, useContext, useVisibleTask$, noSerialize, useServerData, useSignal, untrack, sync$, isDev, withLocale, event$, useStyles$, isServer, useStore, useContextProvider, useTask$, getLocale, jsx as jsx$1, SkipRender } from "@qwik.dev/core";
|
|
3
|
+
import { p } from "@qwik.dev/core/preloader";
|
|
4
|
+
import { _deserialize, _weakSerialize, _getContextElement, _getQContainerElement, _waitUntilRendered, _wrapStore, _getContextEvent, _serialize } from "@qwik.dev/core/internal";
|
|
4
5
|
import * as qwikRouterConfig from "@qwik-router-config";
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
import { z as z2 } from "zod";
|
|
@@ -19,7 +20,6 @@ const ErrorBoundary = component$((props) => {
|
|
|
19
20
|
});
|
|
20
21
|
const MODULE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
21
22
|
const CLIENT_DATA_CACHE = /* @__PURE__ */ new Map();
|
|
22
|
-
const PREFETCHED_NAVIGATE_PATHS = /* @__PURE__ */ new Set();
|
|
23
23
|
const QACTION_KEY = "qaction";
|
|
24
24
|
const QFN_KEY = "qfunc";
|
|
25
25
|
const QDATA_KEY = "qdata";
|
|
@@ -57,15 +57,7 @@ const getClientNavPath = (props, baseUrl) => {
|
|
|
57
57
|
}
|
|
58
58
|
return null;
|
|
59
59
|
};
|
|
60
|
-
const
|
|
61
|
-
if (clientNavPath) {
|
|
62
|
-
const prefetchUrl = toUrl(clientNavPath, currentLoc.url);
|
|
63
|
-
const currentUrl = toUrl("", currentLoc.url);
|
|
64
|
-
return !isSamePath(prefetchUrl, currentUrl);
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
};
|
|
68
|
-
const shouldPrefetchSymbols = (clientNavPath, currentLoc) => {
|
|
60
|
+
const shouldPreload = (clientNavPath, currentLoc) => {
|
|
69
61
|
if (clientNavPath) {
|
|
70
62
|
const prefetchUrl = toUrl(clientNavPath, currentLoc.url);
|
|
71
63
|
const currentUrl = toUrl("", currentLoc.url);
|
|
@@ -115,16 +107,8 @@ const newScrollState = () => {
|
|
|
115
107
|
const prefetchSymbols = (path) => {
|
|
116
108
|
if (isBrowser) {
|
|
117
109
|
path = path.endsWith("/") ? path : path + "/";
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
document.dispatchEvent(new CustomEvent("qprefetch", {
|
|
121
|
-
detail: {
|
|
122
|
-
links: [
|
|
123
|
-
path
|
|
124
|
-
]
|
|
125
|
-
}
|
|
126
|
-
}));
|
|
127
|
-
}
|
|
110
|
+
path = path.length > 1 && path.startsWith("/") ? path.slice(1) : path;
|
|
111
|
+
p(path, 0.8);
|
|
128
112
|
}
|
|
129
113
|
};
|
|
130
114
|
const loadClientData = async (url, element, opts) => {
|
|
@@ -140,7 +124,7 @@ const loadClientData = async (url, element, opts) => {
|
|
|
140
124
|
}
|
|
141
125
|
let resolveFn;
|
|
142
126
|
if (!qData) {
|
|
143
|
-
const fetchOptions = getFetchOptions(opts?.action);
|
|
127
|
+
const fetchOptions = getFetchOptions(opts?.action, opts?.clearCache);
|
|
144
128
|
if (opts?.action) {
|
|
145
129
|
opts.action.data = void 0;
|
|
146
130
|
}
|
|
@@ -196,16 +180,19 @@ const loadClientData = async (url, element, opts) => {
|
|
|
196
180
|
return v;
|
|
197
181
|
});
|
|
198
182
|
};
|
|
199
|
-
const getFetchOptions = (action) => {
|
|
183
|
+
const getFetchOptions = (action, noCache) => {
|
|
200
184
|
const actionData = action?.data;
|
|
201
185
|
if (!actionData) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
186
|
+
if (noCache) {
|
|
187
|
+
return {
|
|
188
|
+
cache: "no-cache",
|
|
189
|
+
headers: {
|
|
190
|
+
"Cache-Control": "no-cache",
|
|
191
|
+
Pragma: "no-cache"
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return void 0;
|
|
209
196
|
}
|
|
210
197
|
if (actionData instanceof FormData) {
|
|
211
198
|
return {
|
|
@@ -249,14 +236,15 @@ const Link = component$((props) => {
|
|
|
249
236
|
const nav = useNavigate();
|
|
250
237
|
const loc = useLocation();
|
|
251
238
|
const originalHref = props.href;
|
|
239
|
+
const anchorRef = useSignal();
|
|
252
240
|
const { onClick$, prefetch: prefetchProp, reload, replaceState, scroll, ...linkProps } = /* @__PURE__ */ (() => props)();
|
|
253
241
|
const clientNavPath = untrack(() => getClientNavPath({
|
|
254
242
|
...linkProps,
|
|
255
243
|
reload
|
|
256
244
|
}, loc));
|
|
257
245
|
linkProps.href = clientNavPath || originalHref;
|
|
258
|
-
const prefetchData = untrack(() => !!clientNavPath && prefetchProp !== false && prefetchProp !== "js"
|
|
259
|
-
const prefetch = untrack(() => prefetchData || !!clientNavPath && prefetchProp !== false &&
|
|
246
|
+
const prefetchData = untrack(() => !!clientNavPath && prefetchProp !== false && prefetchProp !== "js" || void 0);
|
|
247
|
+
const prefetch = untrack(() => prefetchData || !!clientNavPath && prefetchProp !== false && shouldPreload(clientNavPath, loc));
|
|
260
248
|
const handlePrefetch = prefetch ? $((_, elm) => {
|
|
261
249
|
if (navigator.connection?.saveData) {
|
|
262
250
|
return;
|
|
@@ -290,7 +278,23 @@ const Link = component$((props) => {
|
|
|
290
278
|
}
|
|
291
279
|
}
|
|
292
280
|
}) : void 0;
|
|
281
|
+
useVisibleTask$(({ track }) => {
|
|
282
|
+
track(() => loc.url.pathname);
|
|
283
|
+
const handler = linkProps.onQVisible$;
|
|
284
|
+
if (handler) {
|
|
285
|
+
const event = new CustomEvent("qvisible");
|
|
286
|
+
if (Array.isArray(handler)) {
|
|
287
|
+
handler.flat(10).forEach((handler2) => handler2?.(event, anchorRef.value));
|
|
288
|
+
} else {
|
|
289
|
+
handler?.(event, anchorRef.value);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (!isDev && anchorRef.value) {
|
|
293
|
+
handlePrefetch?.(void 0, anchorRef.value);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
293
296
|
return /* @__PURE__ */ jsx("a", {
|
|
297
|
+
ref: anchorRef,
|
|
294
298
|
"q:link": !!clientNavPath,
|
|
295
299
|
...linkProps,
|
|
296
300
|
onClick$: [
|
|
@@ -307,11 +311,8 @@ const Link = component$((props) => {
|
|
|
307
311
|
linkProps.onFocus$,
|
|
308
312
|
handlePrefetch
|
|
309
313
|
],
|
|
310
|
-
//
|
|
311
|
-
onQVisible$: [
|
|
312
|
-
linkProps.onQVisible$,
|
|
313
|
-
!isDev ? handlePrefetch : void 0
|
|
314
|
-
],
|
|
314
|
+
// We need to prevent the onQVisible$ from being called twice since it is handled in the visible task
|
|
315
|
+
onQVisible$: [],
|
|
315
316
|
children: /* @__PURE__ */ jsx(Slot, {})
|
|
316
317
|
});
|
|
317
318
|
});
|
|
@@ -752,6 +753,26 @@ const spaInit = event$((_, el) => {
|
|
|
752
753
|
}, 0);
|
|
753
754
|
}
|
|
754
755
|
});
|
|
756
|
+
const startViewTransition = (params) => {
|
|
757
|
+
if (!params.update) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
if ("startViewTransition" in document) {
|
|
761
|
+
let transition;
|
|
762
|
+
try {
|
|
763
|
+
transition = document.startViewTransition(params);
|
|
764
|
+
} catch {
|
|
765
|
+
transition = document.startViewTransition(params.update);
|
|
766
|
+
}
|
|
767
|
+
const event = new CustomEvent("qviewtransition", {
|
|
768
|
+
detail: transition
|
|
769
|
+
});
|
|
770
|
+
document.dispatchEvent(event);
|
|
771
|
+
return transition;
|
|
772
|
+
} else {
|
|
773
|
+
params.update?.();
|
|
774
|
+
}
|
|
775
|
+
};
|
|
755
776
|
const QWIK_CITY_SCROLLER = "_qCityScroller";
|
|
756
777
|
const QWIK_ROUTER_SCROLLER = "_qRouterScroller";
|
|
757
778
|
const preventNav = {};
|
|
@@ -759,7 +780,18 @@ const internalState = {
|
|
|
759
780
|
navCount: 0
|
|
760
781
|
};
|
|
761
782
|
const QwikRouterProvider = component$((props) => {
|
|
762
|
-
useStyles$(
|
|
783
|
+
useStyles$(`
|
|
784
|
+
@layer qwik {
|
|
785
|
+
@supports selector(html:active-view-transition-type(type)) {
|
|
786
|
+
html:active-view-transition-type(qwik-router-spa) {
|
|
787
|
+
:root{view-transition-name:none}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
@supports not selector(html:active-view-transition-type(type)) {
|
|
791
|
+
:root{view-transition-name:none}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
`);
|
|
763
795
|
const env = useQwikRouterEnv();
|
|
764
796
|
if (!env?.params) {
|
|
765
797
|
throw new Error(`Missing Qwik Router Env Data for help visit https://github.com/QwikDev/qwik/issues/6237`);
|
|
@@ -768,6 +800,11 @@ const QwikRouterProvider = component$((props) => {
|
|
|
768
800
|
if (!urlEnv) {
|
|
769
801
|
throw new Error(`Missing Qwik URL Env Data`);
|
|
770
802
|
}
|
|
803
|
+
if (isServer) {
|
|
804
|
+
if (env.ev.originalUrl.pathname !== env.ev.url.pathname && !__EXPERIMENTAL__.enableRequestRewrite) {
|
|
805
|
+
throw new Error(`enableRequestRewrite is an experimental feature and is not enabled. Please enable the feature flag by adding \`experimental: ["enableRequestRewrite"]\` to your qwikVite plugin options.`);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
771
808
|
const url = new URL(urlEnv);
|
|
772
809
|
const routeLocation = useStore({
|
|
773
810
|
url,
|
|
@@ -956,12 +993,21 @@ const QwikRouterProvider = component$((props) => {
|
|
|
956
993
|
const newHref = pageData.href;
|
|
957
994
|
const newURL = new URL(newHref, trackUrl);
|
|
958
995
|
if (!isSamePath(newURL, trackUrl)) {
|
|
959
|
-
|
|
960
|
-
|
|
996
|
+
if (!pageData.isRewrite) {
|
|
997
|
+
trackUrl = newURL;
|
|
998
|
+
}
|
|
999
|
+
loadRoutePromise = loadRoute(
|
|
1000
|
+
qwikRouterConfig.routes,
|
|
1001
|
+
qwikRouterConfig.menus,
|
|
1002
|
+
qwikRouterConfig.cacheModules,
|
|
1003
|
+
newURL.pathname
|
|
1004
|
+
// Load the actual required path.
|
|
1005
|
+
);
|
|
961
1006
|
}
|
|
962
1007
|
try {
|
|
963
1008
|
loadedRoute = await loadRoutePromise;
|
|
964
1009
|
} catch (e) {
|
|
1010
|
+
console.error(e);
|
|
965
1011
|
window.location.href = newHref;
|
|
966
1012
|
return;
|
|
967
1013
|
}
|
|
@@ -996,9 +1042,6 @@ const QwikRouterProvider = component$((props) => {
|
|
|
996
1042
|
documentHead.title = resolvedHead.title;
|
|
997
1043
|
documentHead.frontmatter = resolvedHead.frontmatter;
|
|
998
1044
|
if (isBrowser) {
|
|
999
|
-
if (props.viewTransition !== false) {
|
|
1000
|
-
document.__q_view_transition__ = true;
|
|
1001
|
-
}
|
|
1002
1045
|
let scrollState;
|
|
1003
1046
|
if (navType === "popstate") {
|
|
1004
1047
|
scrollState = getScrollHistory();
|
|
@@ -1121,8 +1164,27 @@ const QwikRouterProvider = component$((props) => {
|
|
|
1121
1164
|
const scrollState2 = currentScrollState(scroller);
|
|
1122
1165
|
saveScrollHistory(scrollState2);
|
|
1123
1166
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1167
|
+
const navigate = () => {
|
|
1168
|
+
clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
|
|
1169
|
+
return _waitUntilRendered(elm);
|
|
1170
|
+
};
|
|
1171
|
+
const _waitNextPage = () => {
|
|
1172
|
+
if (isServer || props.viewTransition === false) {
|
|
1173
|
+
return navigate();
|
|
1174
|
+
} else {
|
|
1175
|
+
const viewTransition = startViewTransition({
|
|
1176
|
+
update: navigate,
|
|
1177
|
+
types: [
|
|
1178
|
+
"qwik-navigation"
|
|
1179
|
+
]
|
|
1180
|
+
});
|
|
1181
|
+
if (!viewTransition) {
|
|
1182
|
+
return Promise.resolve();
|
|
1183
|
+
}
|
|
1184
|
+
return viewTransition.ready;
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
_waitNextPage().then(() => {
|
|
1126
1188
|
const container = _getQContainerElement(elm);
|
|
1127
1189
|
container.setAttribute("q:route", routeName);
|
|
1128
1190
|
const scrollState2 = currentScrollState(scroller);
|
|
@@ -1137,11 +1199,10 @@ const QwikRouterProvider = component$((props) => {
|
|
|
1137
1199
|
}
|
|
1138
1200
|
}
|
|
1139
1201
|
}
|
|
1140
|
-
const promise = run();
|
|
1141
1202
|
if (isServer) {
|
|
1142
|
-
return
|
|
1203
|
+
return run();
|
|
1143
1204
|
} else {
|
|
1144
|
-
|
|
1205
|
+
run();
|
|
1145
1206
|
}
|
|
1146
1207
|
});
|
|
1147
1208
|
return /* @__PURE__ */ jsx(Slot, {});
|
|
@@ -1704,7 +1765,8 @@ const deserializeStream = async function* (stream, ctxElm, abortSignal) {
|
|
|
1704
1765
|
reader.releaseLock();
|
|
1705
1766
|
}
|
|
1706
1767
|
};
|
|
1707
|
-
const ServiceWorkerRegister = (props) => jsx
|
|
1768
|
+
const ServiceWorkerRegister = (props) => /* @__PURE__ */ jsx("script", {
|
|
1769
|
+
type: "module",
|
|
1708
1770
|
dangerouslySetInnerHTML: swRegister,
|
|
1709
1771
|
nonce: props.nonce
|
|
1710
1772
|
});
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { Http2ServerRequest } from 'http2';
|
|
2
|
-
import { IncomingMessage } from 'http';
|
|
3
|
-
import { NodeRequestNextFunction } from '@qwik.dev/router/middleware/node';
|
|
4
|
-
import type { QwikCityPlan } from '@qwik.dev/router';
|
|
5
|
-
import type { QwikManifest } from '@qwik.dev/core/optimizer';
|
|
6
|
-
import type { QwikRouterConfig } from '@qwik.dev/router';
|
|
7
|
-
import type { Render } from '@qwik.dev/core/server';
|
|
8
|
-
import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler';
|
|
9
|
-
import { ServerResponse } from 'http';
|
|
10
|
-
|
|
11
|
-
declare interface AwsOpt {
|
|
12
|
-
render: Render;
|
|
13
|
-
manifest
|
|
14
|
-
qwikRouterConfig: QwikRouterConfig;
|
|
15
|
-
/** @deprecated Use `QwikRouterConfig` instead. Will be removed in V3 */
|
|
16
|
-
qwikCityPlan?: QwikCityPlan;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
export declare const createQwikCity: typeof createQwikRouter;
|
|
24
|
-
|
|
25
|
-
/** @public */
|
|
26
|
-
export declare function createQwikRouter(opts: AwsOpt): {
|
|
27
|
-
fixPath: (pathT: string) => string;
|
|
28
|
-
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
|
|
29
|
-
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
30
|
-
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>;
|
|
31
|
-
handle: (req: any, res: any) => void;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/** @public */
|
|
35
|
-
export declare interface PlatformAwsLambda extends Object {
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated Use `QwikRouterAwsLambdaOptions` instead. Will be removed in V3
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
export declare type QwikCityAwsLambdaOptions = QwikRouterAwsLambdaOptions;
|
|
43
|
-
|
|
44
|
-
/** @public */
|
|
45
|
-
export declare interface QwikRouterAwsLambdaOptions extends ServerRenderOptions {
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export { }
|
|
1
|
+
import { Http2ServerRequest } from 'http2';
|
|
2
|
+
import { IncomingMessage } from 'http';
|
|
3
|
+
import { NodeRequestNextFunction } from '@qwik.dev/router/middleware/node';
|
|
4
|
+
import type { QwikCityPlan } from '@qwik.dev/router';
|
|
5
|
+
import type { QwikManifest } from '@qwik.dev/core/optimizer';
|
|
6
|
+
import type { QwikRouterConfig } from '@qwik.dev/router';
|
|
7
|
+
import type { Render } from '@qwik.dev/core/server';
|
|
8
|
+
import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler';
|
|
9
|
+
import { ServerResponse } from 'http';
|
|
10
|
+
|
|
11
|
+
declare interface AwsOpt {
|
|
12
|
+
render: Render;
|
|
13
|
+
manifest?: QwikManifest;
|
|
14
|
+
qwikRouterConfig: QwikRouterConfig;
|
|
15
|
+
/** @deprecated Use `QwikRouterConfig` instead. Will be removed in V3 */
|
|
16
|
+
qwikCityPlan?: QwikCityPlan;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare const createQwikCity: typeof createQwikRouter;
|
|
24
|
+
|
|
25
|
+
/** @public */
|
|
26
|
+
export declare function createQwikRouter(opts: AwsOpt): {
|
|
27
|
+
fixPath: (pathT: string) => string;
|
|
28
|
+
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
|
|
29
|
+
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
30
|
+
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>;
|
|
31
|
+
handle: (req: any, res: any) => void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** @public */
|
|
35
|
+
export declare interface PlatformAwsLambda extends Object {
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use `QwikRouterAwsLambdaOptions` instead. Will be removed in V3
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare type QwikCityAwsLambdaOptions = QwikRouterAwsLambdaOptions;
|
|
43
|
+
|
|
44
|
+
/** @public */
|
|
45
|
+
export declare interface QwikRouterAwsLambdaOptions extends ServerRenderOptions {
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { }
|