@qwik.dev/router 2.0.0-rc.4 → 2.0.0-rc.5
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/shared/vite/index.mjs +1 -1
- package/lib/chunks/head.qwik.mjs +196 -102
- package/lib/chunks/request-path.mjs +9 -1
- package/lib/chunks/system.mjs +65 -10
- package/lib/chunks/user-response.mjs +281 -322
- package/lib/chunks/worker-thread.mjs +22 -11
- package/lib/index.d.ts +8 -6
- package/lib/index.qwik.mjs +239 -83
- package/lib/middleware/node/index.mjs +7 -1
- package/lib/middleware/request-handler/index.d.ts +2 -2
- package/lib/middleware/request-handler/index.mjs +4 -5
- package/lib/ssg/index.d.ts +7 -0
- package/lib/ssg/index.mjs +52 -6
- package/lib/vite/index.mjs +67 -20
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { i as resolveRequestHandlers, r as renderQwikMiddleware, t as runQwikRouter } from "./user-response.mjs";
|
|
4
|
-
import { _serialize } from "@qwik.dev/core/internal";
|
|
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
|
+
import { c as RequestEvHttpStatusMessage, i as resolveRequestHandlers, r as renderQwikMiddleware, t as runQwikRouter } from "./user-response.mjs";
|
|
4
|
+
import { _serialize } from "@qwik.dev/core/internal/serializer";
|
|
5
5
|
import { parentPort } from "node:worker_threads";
|
|
6
6
|
var staticWorkerThreadDeps = {
|
|
7
7
|
loadRoute,
|
|
@@ -15,7 +15,12 @@ async function workerThread(sys) {
|
|
|
15
15
|
const pendingPromises = /* @__PURE__ */ new Set();
|
|
16
16
|
const deps = {
|
|
17
17
|
...staticWorkerThreadDeps,
|
|
18
|
-
serialize: _serialize
|
|
18
|
+
serialize: _serialize,
|
|
19
|
+
announceFile: (pathname, filePath) => parentPort?.postMessage({
|
|
20
|
+
type: "file",
|
|
21
|
+
pathname,
|
|
22
|
+
filePath
|
|
23
|
+
})
|
|
19
24
|
};
|
|
20
25
|
process.on("uncaughtException", (e) => {
|
|
21
26
|
console.error("Worker uncaught exception (suppressed):", e.message);
|
|
@@ -110,6 +115,13 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
|
|
|
110
115
|
getWritableStream: (status, headers, _, _r, requestEv) => {
|
|
111
116
|
const isNotFoundPage = url.pathname.endsWith("/404.html");
|
|
112
117
|
result.ok = status >= 200 && status < 300 || isNotFoundPage && status === 404;
|
|
118
|
+
if (status >= 500) {
|
|
119
|
+
const statusMessage = requestEv.sharedMap.get(RequestEvHttpStatusMessage);
|
|
120
|
+
result.error = {
|
|
121
|
+
message: statusMessage ? `Responded with ${status}: ${statusMessage}` : `Responded with ${status}`,
|
|
122
|
+
stack: void 0
|
|
123
|
+
};
|
|
124
|
+
}
|
|
113
125
|
if (!result.ok) return createNoopWritableStream();
|
|
114
126
|
result.contentType = (headers.get("Content-Type") || "").toLowerCase();
|
|
115
127
|
const isHtml = result.contentType.includes("text/html");
|
|
@@ -122,6 +134,7 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
|
|
|
122
134
|
try {
|
|
123
135
|
if (hasRouteWriter || writeLoaderDataEnabled) await sys.ensureDir(routeFilePath);
|
|
124
136
|
if (hasRouteWriter) {
|
|
137
|
+
deps.announceFile(staticRoute.pathname, routeFilePath);
|
|
125
138
|
routeWriter = sys.createWriteStream(routeFilePath);
|
|
126
139
|
routeWriter.on("error", (e) => {
|
|
127
140
|
console.error(e);
|
|
@@ -165,6 +178,7 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
|
|
|
165
178
|
const data = loaderValues[loader.__id];
|
|
166
179
|
if (data === void 0) continue;
|
|
167
180
|
const loaderFilePath = sys.getLoaderFilePath(url.pathname, loader.__id, manifestHash);
|
|
181
|
+
deps.announceFile(staticRoute.pathname, loaderFilePath);
|
|
168
182
|
const loaderWriter = sys.createWriteStream(loaderFilePath);
|
|
169
183
|
loaderWriter.on("error", (e) => {
|
|
170
184
|
console.error(e);
|
|
@@ -207,12 +221,12 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
|
|
|
207
221
|
}
|
|
208
222
|
return completion;
|
|
209
223
|
};
|
|
210
|
-
|
|
211
|
-
return failRouteOnCaughtBoundary(
|
|
224
|
+
const failure = r ?? rsp.requestEv.sharedMap.get("@sentServerError");
|
|
225
|
+
if (routeWriter) return closePromise.then(() => failRouteOnCaughtBoundary(failure));
|
|
226
|
+
return failRouteOnCaughtBoundary(failure);
|
|
212
227
|
});
|
|
213
228
|
}).then((e) => {
|
|
214
229
|
if (e !== void 0) {
|
|
215
|
-
if (isRedirectMessage(e)) return;
|
|
216
230
|
if (e instanceof Error) result.error = {
|
|
217
231
|
message: e.message,
|
|
218
232
|
stack: e.stack
|
|
@@ -249,9 +263,6 @@ async function workerRender(sys, opts, staticRoute, pendingPromises, callback, d
|
|
|
249
263
|
}
|
|
250
264
|
/** Create a fresh no-op WritableStream (must be a real instance for pipeTo checks). */
|
|
251
265
|
var createNoopWritableStream = () => new WritableStream();
|
|
252
|
-
function isRedirectMessage(value) {
|
|
253
|
-
return typeof value === "object" && value !== null && value.constructor?.name === "RedirectMessage";
|
|
254
|
-
}
|
|
255
266
|
async function requestHandlerForSsg(serverRequestEv, opts, deps) {
|
|
256
267
|
const { render, checkOrigin, qwikRouterConfig } = opts;
|
|
257
268
|
if (!qwikRouterConfig) throw new Error("qwikRouterConfig is required.");
|
package/lib/index.d.ts
CHANGED
|
@@ -410,15 +410,14 @@ export declare interface FormProps<O, I> extends Omit<QwikJSX.IntrinsicElements[
|
|
|
410
410
|
*/
|
|
411
411
|
reloadDocument?: boolean;
|
|
412
412
|
/**
|
|
413
|
-
*
|
|
414
|
-
* form submission.
|
|
413
|
+
* Resets SPA form controls after responses, including validation failures.
|
|
415
414
|
*
|
|
416
415
|
* Defaults to `false`
|
|
417
416
|
*/
|
|
418
417
|
spaReset?: boolean;
|
|
419
418
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
419
|
+
* Runs after a form submission returns, including validation failures. Like the native `on*$`
|
|
420
|
+
* events, it accepts an inline function as well as a QRL.
|
|
422
421
|
*/
|
|
423
422
|
onSubmitCompleted$?: QRLEventHandlerMulti<CustomEvent<FormSubmitSuccessDetail<O>>, HTMLFormElement> | EventHandler<CustomEvent<FormSubmitSuccessDetail<O>>, HTMLFormElement> | undefined;
|
|
424
423
|
key?: string | number | null;
|
|
@@ -652,6 +651,9 @@ declare type LoaderOptions = {
|
|
|
652
651
|
* When set, the server includes an `ETag` header on `q-loader-*.json` responses and returns `304`
|
|
653
652
|
* if the client sends a matching `If-None-Match` header.
|
|
654
653
|
*
|
|
654
|
+
* With `serializationStrategy: 'never'`, the eTag is also sent with the page, so the first client
|
|
655
|
+
* fetch with the same eTag reuses the rendered data without re-running its subscribers.
|
|
656
|
+
*
|
|
655
657
|
* For auto-computed eTags, use `cacheKey` instead — on cache write the eTag is hashed from the
|
|
656
658
|
* serialized response and stored alongside it, so subsequent hits get the same eTag.
|
|
657
659
|
*/
|
|
@@ -1103,10 +1105,10 @@ export declare const routeLoader$: LoaderConstructor;
|
|
|
1103
1105
|
/** Shared SSR paths and client-only loader navigation state. */
|
|
1104
1106
|
declare type RouteLoaderCtx = {
|
|
1105
1107
|
loaderPaths: Record<string, string | undefined>;
|
|
1106
|
-
/**
|
|
1108
|
+
/** Resolves after navigation prepares loader requests, before their results. */
|
|
1107
1109
|
goto?: NoSerialize<(path: string, options: {
|
|
1108
1110
|
replaceState: boolean;
|
|
1109
|
-
}) =>
|
|
1111
|
+
}) => Promise<void>>;
|
|
1110
1112
|
/** Router callback that re-resolves the document head after a loader gets a new value. */
|
|
1111
1113
|
onValue?: RouteNavigate;
|
|
1112
1114
|
/** Client manifest hash for q-loader fetch URLs. */
|
package/lib/index.qwik.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { t as ensureSlash } from "./chunks/pathname.mjs";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as ContentContext, A as routeLoaderQrl, B as toUrl, C as isImmutableLoader, E as prepareRouteLoaders, F as isSameOrigin, G as getRouterConfig, H as _setRouterConfig, I as isSamePath, J as REFRESH_HEAD, K as getRoutes, L as shouldPreload, N as getClientNavPath, O as restoreRouteLoaders, P as isPromise, Q as registerPreventNav, R as toPath, U as findRouterConfig, V as _getServiceWorkerUrl, W as getBasePathname, X as internalState, Y as RUN_PENDING_ACTION, Z as preventNav, _ as getRequestEvent, a as matchRouteTree, at as RouteLoaderCtxContext, c as abortRouteLoaderNavigation, ct as RouteStateContext, d as commitRouteLoaders, dt as QFN_KEY, et as ContentInternalContext, f as ensureRouteLoaderSignals, ft as Q_ROUTE, g as getModuleRouteLoaders, i as loadRoute, it as RouteActionRunnerContext, j as setLoaderSignalValue, k as routeLoader$, l as clearNavFetchCache, lt as QACTION_KEY, m as getClientRouteLoaders, n as resolveHead, nt as HttpStatusContext, ot as RouteLocationContext, p as fetchRouteLoaderData, q as getTrailingSlash, rt as RouteActionContext, st as RouteNavigateContext, t as createDocumentHead, tt as DocumentHeadContext, ut as QDATA_KEY, z as toSafeRedirectUrl } 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
|
-
import { _deserialize, _getContextContainer, _getContextHostElement, _getDomContainer, _hasStoreEffects, _regInlinedQrl, _requestPreload,
|
|
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";
|
|
6
|
+
import { _serialize } from "@qwik.dev/core/internal/serializer";
|
|
6
7
|
import * as v from "valibot";
|
|
7
8
|
import * as z$1 from "zod";
|
|
8
9
|
import { z } from "zod";
|
|
@@ -366,8 +367,10 @@ var spa_init_default = eventQrl(/*#__PURE__*/ inlinedQrl((_, el) => {
|
|
|
366
367
|
if (window._qRouterSPA) return;
|
|
367
368
|
window._qRouterScrollEnabled = false;
|
|
368
369
|
clearTimeout(window._qRouterScrollDebounce);
|
|
369
|
-
if (hasPathChanged(location.pathname + location.search))
|
|
370
|
-
|
|
370
|
+
if (hasPathChanged(location.pathname + location.search)) {
|
|
371
|
+
if (window._qRouterInitNavigate) window._qRouterInitNavigate(location.href, { type: "popstate" });
|
|
372
|
+
else dispatchRouterPopstate(document, location.href);
|
|
373
|
+
} else if (history.scrollRestoration === "manual") {
|
|
371
374
|
const scrollState = history.state?._qRouterScroll;
|
|
372
375
|
checkAndScroll(scrollState);
|
|
373
376
|
window._qRouterScrollEnabled = true;
|
|
@@ -388,11 +391,15 @@ var spa_init_default = eventQrl(/*#__PURE__*/ inlinedQrl((_, el) => {
|
|
|
388
391
|
};
|
|
389
392
|
history.pushState = (state, title, url) => {
|
|
390
393
|
state = prepareState(state);
|
|
391
|
-
|
|
394
|
+
const result = pushState.call(history, state, title, url);
|
|
395
|
+
hasPathChanged(location.pathname + location.search);
|
|
396
|
+
return result;
|
|
392
397
|
};
|
|
393
398
|
history.replaceState = (state, title, url) => {
|
|
394
399
|
state = prepareState(state);
|
|
395
|
-
|
|
400
|
+
const result = replaceState.call(history, state, title, url);
|
|
401
|
+
hasPathChanged(location.pathname + location.search);
|
|
402
|
+
return result;
|
|
396
403
|
};
|
|
397
404
|
}
|
|
398
405
|
window._qRouterInitAnchors = (event) => {
|
|
@@ -490,8 +497,9 @@ async function submitAction(action, routeUrl) {
|
|
|
490
497
|
loaderHashes: data?.loaderHashes
|
|
491
498
|
};
|
|
492
499
|
}
|
|
500
|
+
throw new Error(`Unexpected action response (${response.status}): expected JSON`);
|
|
493
501
|
}
|
|
494
|
-
var qwik_view_transition_default = "@layer qwik{@supports selector(html:active-view-transition-type(type)){html:active-view-transition-type(qwik-navigation){
|
|
502
|
+
var qwik_view_transition_default = "@layer qwik{@supports selector(html:active-view-transition-type(type)){html:active-view-transition-type(qwik-navigation){view-transition-name:none}}@supports not selector(html:active-view-transition-type(type)){:root{view-transition-name:none}}}";
|
|
495
503
|
/** View transitions are opt-in and require browser support. */
|
|
496
504
|
var shouldStartViewTransition = (viewTransition) => viewTransition === true && "startViewTransition" in document;
|
|
497
505
|
var VIEW_TRANSITION_STYLE_ID = "qwik-view-transition";
|
|
@@ -527,10 +535,36 @@ var startViewTransition = (params) => {
|
|
|
527
535
|
var QWIK_CITY_SCROLLER = "_qCityScroller";
|
|
528
536
|
/** @public */
|
|
529
537
|
var QWIK_ROUTER_SCROLLER = "_qRouterScroller";
|
|
538
|
+
var NavigationStartType = /* @__PURE__ */ function(NavigationStartType) {
|
|
539
|
+
NavigationStartType[NavigationStartType["Unchanged"] = 0] = "Unchanged";
|
|
540
|
+
NavigationStartType[NavigationStartType["Duplicate"] = 1] = "Duplicate";
|
|
541
|
+
NavigationStartType[NavigationStartType["Prepared"] = 2] = "Prepared";
|
|
542
|
+
NavigationStartType[NavigationStartType["Superseded"] = 3] = "Superseded";
|
|
543
|
+
NavigationStartType[NavigationStartType["External"] = 4] = "External";
|
|
544
|
+
return NavigationStartType;
|
|
545
|
+
}(NavigationStartType || {});
|
|
530
546
|
var ensureRouteInternal = (routeInternal, routeLocation) => routeInternal.untrackedValue ||= {
|
|
531
547
|
type: "initial",
|
|
532
548
|
dest: routeLocation.url
|
|
533
549
|
};
|
|
550
|
+
/**
|
|
551
|
+
* A URL the client can't render itself (no matching page) may be a server `rewrite()`. Ask the
|
|
552
|
+
* server where it routes to. Returns the target pathname, `'reload'` if the server redirects, or
|
|
553
|
+
* `undefined` when the URL is not rewritten.
|
|
554
|
+
*/
|
|
555
|
+
var resolveServerRewrite = async (url) => {
|
|
556
|
+
try {
|
|
557
|
+
const response = await fetch(`${ensureSlash(url.pathname)}q-route.json${url.search}`, {
|
|
558
|
+
redirect: "manual",
|
|
559
|
+
headers: { accept: "application/json" }
|
|
560
|
+
});
|
|
561
|
+
if (response.type === "opaqueredirect" || response.status >= 300 && response.status < 400) return "reload";
|
|
562
|
+
if (response.ok) {
|
|
563
|
+
const { p } = await response.json();
|
|
564
|
+
return typeof p === "string" ? p : void 0;
|
|
565
|
+
}
|
|
566
|
+
} catch {}
|
|
567
|
+
};
|
|
534
568
|
var getRouterContainer = () => _getDomContainer(document.documentElement);
|
|
535
569
|
var getServerHttpStatus = (notFound, response) => {
|
|
536
570
|
if (notFound) return {
|
|
@@ -657,6 +691,32 @@ var useQwikRouter = (props) => {
|
|
|
657
691
|
return;
|
|
658
692
|
}
|
|
659
693
|
if (path === RUN_PENDING_ACTION) return loadNavigation(ensureRouteInternal(routeInternal, routeLocation), actionState.value, getRouterContainer());
|
|
694
|
+
return prepareNavigation(path, opt).started.then((started) => started.finished);
|
|
695
|
+
};
|
|
696
|
+
const prepareNavigation = (path, opt) => {
|
|
697
|
+
let resolvePreparation;
|
|
698
|
+
let rejectPreparation;
|
|
699
|
+
const prepared = new Promise((resolve, reject) => {
|
|
700
|
+
resolvePreparation = resolve;
|
|
701
|
+
rejectPreparation = reject;
|
|
702
|
+
});
|
|
703
|
+
prepared.catch(() => {});
|
|
704
|
+
const preparation = {
|
|
705
|
+
promise: prepared,
|
|
706
|
+
resolve: resolvePreparation
|
|
707
|
+
};
|
|
708
|
+
const started = beginNavigation(path, opt, preparation);
|
|
709
|
+
started.then(async (result) => {
|
|
710
|
+
if (result.type !== NavigationStartType.Duplicate && navResolver.preparation !== preparation && preparation.navCount !== internalState.navCount || result.type === NavigationStartType.Superseded || result.type === NavigationStartType.External) return;
|
|
711
|
+
await navResolver.routePreparation?.started;
|
|
712
|
+
if (getClientRouteLoaders(routeLoaderCtx).navCount === internalState.navCount) resolvePreparation();
|
|
713
|
+
}, rejectPreparation).catch(rejectPreparation);
|
|
714
|
+
return {
|
|
715
|
+
prepared,
|
|
716
|
+
started
|
|
717
|
+
};
|
|
718
|
+
};
|
|
719
|
+
const beginNavigation = async (path, opt, preparation) => {
|
|
660
720
|
const { type = "link", forceReload = path === void 0, replaceState = false, scroll = true } = typeof opt === "object" ? opt : { forceReload: opt };
|
|
661
721
|
const current = ensureRouteInternal(routeInternal, routeLocation);
|
|
662
722
|
if (isBrowser && type === "link" && current.type === "initial") {
|
|
@@ -666,24 +726,31 @@ var useQwikRouter = (props) => {
|
|
|
666
726
|
}
|
|
667
727
|
const lastDest = current.dest;
|
|
668
728
|
const dest = path === void 0 ? lastDest : typeof path === "number" ? path : toUrl(path, routeLocation.url);
|
|
669
|
-
if (navResolver.p && !forceReload && typeof dest !== "number" && isSamePath(dest, lastDest) && dest.href === lastDest.href) return
|
|
729
|
+
if (navResolver.p && !forceReload && typeof dest !== "number" && isSamePath(dest, lastDest) && dest.href === lastDest.href) return {
|
|
730
|
+
type: NavigationStartType.Duplicate,
|
|
731
|
+
finished: navResolver.p
|
|
732
|
+
};
|
|
733
|
+
const previousPreparation = navResolver.preparation;
|
|
734
|
+
navResolver.preparation = preparation;
|
|
735
|
+
if (previousPreparation?.navCount === void 0) previousPreparation?.resolve(preparation.promise);
|
|
670
736
|
const attemptCount = ++internalState.attemptCount;
|
|
671
737
|
if (preventNav.$cbs$ && (forceReload || typeof dest === "number" || !isSamePath(dest, lastDest) || !isSameOrigin(dest, lastDest))) {
|
|
672
738
|
const prevents = await Promise.all([...preventNav.$cbs$.values()].map((cb) => cb(dest)));
|
|
673
|
-
if (attemptCount !== internalState.attemptCount
|
|
674
|
-
|
|
675
|
-
|
|
739
|
+
if (attemptCount !== internalState.attemptCount) return { type: NavigationStartType.Superseded };
|
|
740
|
+
if (prevents.some(Boolean)) {
|
|
741
|
+
if (type === "popstate") history.pushState(null, "", lastDest);
|
|
742
|
+
return { type: NavigationStartType.Unchanged };
|
|
676
743
|
}
|
|
677
744
|
}
|
|
678
745
|
if (typeof dest === "number") {
|
|
679
746
|
if (isBrowser) history.go(dest);
|
|
680
|
-
return;
|
|
747
|
+
return { type: NavigationStartType.External };
|
|
681
748
|
}
|
|
682
749
|
if (!isSameOrigin(dest, lastDest)) {
|
|
683
750
|
if (isBrowser) location.href = dest.href;
|
|
684
|
-
return;
|
|
751
|
+
return { type: NavigationStartType.External };
|
|
685
752
|
}
|
|
686
|
-
if (!forceReload && isSamePath(dest, lastDest)) {
|
|
753
|
+
if (!forceReload && isSamePath(dest, lastDest) && (!navResolver.dest || isSamePath(navResolver.dest, dest) && navResolver.dest.href === dest.href)) {
|
|
687
754
|
if (isBrowser) {
|
|
688
755
|
if (type === "link" && dest.href !== location.href) history.pushState(null, "", dest);
|
|
689
756
|
const scroller = getScroller();
|
|
@@ -697,13 +764,34 @@ var useQwikRouter = (props) => {
|
|
|
697
764
|
const contentModules = contentInternal.untrackedValue;
|
|
698
765
|
if (contentModules) updateHead(contentModules, actionDataSignal.untrackedValue, internalState.navCount);
|
|
699
766
|
}
|
|
700
|
-
return
|
|
767
|
+
return {
|
|
768
|
+
type: NavigationStartType.Unchanged,
|
|
769
|
+
finished: navResolver.p
|
|
770
|
+
};
|
|
701
771
|
}
|
|
702
772
|
const navCount = ++internalState.navCount;
|
|
773
|
+
preparation.navCount = navCount;
|
|
774
|
+
navResolver.routePreparation?.preparation.resolve(preparation.promise);
|
|
703
775
|
internalState.currentTransition?.skipTransition();
|
|
704
776
|
navResolver.cancel?.();
|
|
705
777
|
navResolver.cancel = void 0;
|
|
706
778
|
navResolver.r?.();
|
|
779
|
+
navResolver.dest = dest;
|
|
780
|
+
const preparing = preparePageNavigation({
|
|
781
|
+
type,
|
|
782
|
+
dest,
|
|
783
|
+
forceReload,
|
|
784
|
+
replaceState,
|
|
785
|
+
scroll
|
|
786
|
+
}, navCount);
|
|
787
|
+
navResolver.routePreparation = {
|
|
788
|
+
started: preparing,
|
|
789
|
+
preparation
|
|
790
|
+
};
|
|
791
|
+
return preparing;
|
|
792
|
+
};
|
|
793
|
+
const preparePageNavigation = async (navigation, navCount) => {
|
|
794
|
+
const { type, dest, forceReload, replaceState } = navigation;
|
|
707
795
|
let historyUpdated = false;
|
|
708
796
|
if (isBrowser) getClientRouteLoaders(routeLoaderCtx, routeLocation.url.href);
|
|
709
797
|
if (isBrowser && type === "link" && !forceReload) {
|
|
@@ -719,18 +807,12 @@ var useQwikRouter = (props) => {
|
|
|
719
807
|
const container = isBrowser ? _getContextContainer() : void 0;
|
|
720
808
|
if (container && !wasNavigating) {
|
|
721
809
|
await _waitUntilRendered(container);
|
|
722
|
-
if (navCount !== internalState.navCount) return;
|
|
810
|
+
if (navCount !== internalState.navCount) return { type: NavigationStartType.Superseded };
|
|
723
811
|
}
|
|
724
812
|
actionState.value = void 0;
|
|
725
|
-
|
|
726
|
-
type,
|
|
727
|
-
dest,
|
|
728
|
-
forceReload,
|
|
729
|
-
replaceState,
|
|
730
|
-
scroll,
|
|
731
|
-
historyUpdated
|
|
732
|
-
};
|
|
813
|
+
navigation.historyUpdated = historyUpdated;
|
|
733
814
|
routeInternal.value = navigation;
|
|
815
|
+
navResolver.dest = void 0;
|
|
734
816
|
if (wasNavigating) abortRouteLoaderNavigation(routeLoaderCtx);
|
|
735
817
|
if (isBrowser) prefetchRoute(dest, false, .8, manifestHash, true);
|
|
736
818
|
navResolver.p = new Promise((resolve) => {
|
|
@@ -741,8 +823,11 @@ var useQwikRouter = (props) => {
|
|
|
741
823
|
};
|
|
742
824
|
});
|
|
743
825
|
const navigated = navResolver.p;
|
|
744
|
-
loadNavigation(navigation, void 0, container ?? getRouterContainer());
|
|
745
|
-
return
|
|
826
|
+
await loadNavigation(navigation, void 0, container ?? getRouterContainer());
|
|
827
|
+
return {
|
|
828
|
+
type: NavigationStartType.Prepared,
|
|
829
|
+
finished: navigated
|
|
830
|
+
};
|
|
746
831
|
};
|
|
747
832
|
const loadNavigation = async (navigation, action, container) => {
|
|
748
833
|
action?.resolveDispatch?.();
|
|
@@ -758,6 +843,13 @@ var useQwikRouter = (props) => {
|
|
|
758
843
|
const canceled = new Promise((resolve) => {
|
|
759
844
|
navResolver.cancel = () => resolve(void 0);
|
|
760
845
|
});
|
|
846
|
+
const abandonAction = () => {
|
|
847
|
+
action?.reject?.(/* @__PURE__ */ new Error("Action submission was superseded by a navigation"));
|
|
848
|
+
if (action) {
|
|
849
|
+
action.resolve = void 0;
|
|
850
|
+
action.reject = void 0;
|
|
851
|
+
}
|
|
852
|
+
};
|
|
761
853
|
if (trackUrl.pathname.endsWith("/")) {
|
|
762
854
|
if (globalThis.__NO_TRAILING_SLASH__) trackUrl.pathname = trackUrl.pathname.slice(0, -1);
|
|
763
855
|
} else if (!globalThis.__NO_TRAILING_SLASH__) trackUrl.pathname = ensureSlash(trackUrl.pathname);
|
|
@@ -767,27 +859,72 @@ var useQwikRouter = (props) => {
|
|
|
767
859
|
});
|
|
768
860
|
try {
|
|
769
861
|
const route = await Promise.race([loadRoutePromise, canceled]);
|
|
770
|
-
if (!route)
|
|
862
|
+
if (!route) {
|
|
863
|
+
abandonAction();
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
771
866
|
loadedRoute = route;
|
|
772
867
|
} catch (e) {
|
|
773
|
-
if (internalState.navCount !== navCountBefore)
|
|
868
|
+
if (internalState.navCount !== navCountBefore) {
|
|
869
|
+
abandonAction();
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
774
872
|
const preparedNavCount = getClientRouteLoaders(routeLoaderCtx).navCount;
|
|
775
873
|
if (preparedNavCount !== void 0) restoreRouteLoaders(loaderState, routeLoaderCtx, preparedNavCount);
|
|
776
874
|
console.error(`Could not load route ${trackUrl.pathname}, reloading:`, e);
|
|
777
875
|
window.location.href = trackUrl.href;
|
|
778
876
|
return;
|
|
779
877
|
}
|
|
780
|
-
if (internalState.navCount !== navCountBefore)
|
|
878
|
+
if (internalState.navCount !== navCountBefore) {
|
|
879
|
+
abandonAction();
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
let rewrittenTo;
|
|
883
|
+
const lastModule = loadedRoute.$mods$[loadedRoute.$mods$.length - 1];
|
|
884
|
+
if (loadedRoute.$notFound$ || typeof lastModule?.default !== "function" || loadedRoute.$routeName$.includes("[")) {
|
|
885
|
+
const resolved = await Promise.race([resolveServerRewrite(trackUrl), canceled]);
|
|
886
|
+
if (internalState.navCount !== navCountBefore) {
|
|
887
|
+
abandonAction();
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
if (resolved === "reload") {
|
|
891
|
+
if (!action) {
|
|
892
|
+
window.location.href = trackUrl.href;
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
} else if (resolved && resolved !== trackUrl.pathname) {
|
|
896
|
+
try {
|
|
897
|
+
const config = await getRouterConfig();
|
|
898
|
+
loadedRoute = await loadRoute(config.routes, config.cacheModules, resolved);
|
|
899
|
+
rewrittenTo = resolved;
|
|
900
|
+
} catch (e) {
|
|
901
|
+
if (internalState.navCount !== navCountBefore) {
|
|
902
|
+
abandonAction();
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
console.error(`Could not load rewritten route ${resolved}, reloading:`, e);
|
|
906
|
+
window.location.href = trackUrl.href;
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
if (internalState.navCount !== navCountBefore) {
|
|
910
|
+
abandonAction();
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
781
915
|
if (action) {
|
|
782
916
|
const result = await Promise.race([submitAction(action, trackUrl).then((result) => {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
917
|
+
action.resolve?.({
|
|
918
|
+
status: result.status,
|
|
919
|
+
result: result.result
|
|
920
|
+
});
|
|
921
|
+
action.resolve = void 0;
|
|
922
|
+
action.reject = void 0;
|
|
790
923
|
return result;
|
|
924
|
+
}, (error) => {
|
|
925
|
+
action.reject?.(error);
|
|
926
|
+
action.reject = void 0;
|
|
927
|
+
action.resolve = void 0;
|
|
791
928
|
}), canceled]);
|
|
792
929
|
if (internalState.navCount !== navCountBefore || action !== actionState.untrackedValue) return;
|
|
793
930
|
navResolver.cancel = void 0;
|
|
@@ -796,11 +933,14 @@ var useQwikRouter = (props) => {
|
|
|
796
933
|
type: navType,
|
|
797
934
|
dest: trackUrl
|
|
798
935
|
};
|
|
936
|
+
routeLocation.isNavigating = false;
|
|
937
|
+
navResolver.r?.();
|
|
799
938
|
return;
|
|
800
939
|
}
|
|
801
940
|
if (result.redirect) {
|
|
802
|
-
|
|
803
|
-
|
|
941
|
+
const redirectUrl = toSafeRedirectUrl(result.redirect, routeLocation.url);
|
|
942
|
+
if (result.redirect instanceof URL) location.href = redirectUrl.href;
|
|
943
|
+
else startNavigation(redirectUrl, { replaceState: true });
|
|
804
944
|
return;
|
|
805
945
|
}
|
|
806
946
|
actionData = {
|
|
@@ -813,8 +953,8 @@ var useQwikRouter = (props) => {
|
|
|
813
953
|
navResolver.cancel = void 0;
|
|
814
954
|
const { $routeName$, $params$, $mods$, $menu$, $notFound$ } = loadedRoute;
|
|
815
955
|
const contentModules = $mods$;
|
|
816
|
-
routeLoaderCtx.goto = noSerialize(
|
|
817
|
-
const routeLoaders = prepareRouteLoaders(contentModules, loaderState, routeLoaderCtx, loadedRoute.$loaderPaths$, trackUrl, prevUrl, navCountBefore, action ? actionLoaderHashes ?? null : void 0, action ?? navigation);
|
|
956
|
+
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);
|
|
818
958
|
await whenReady(() => {
|
|
819
959
|
for (let i = 0; i < routeLoaders.length; i++) {
|
|
820
960
|
const loader = routeLoaders[i];
|
|
@@ -962,6 +1102,7 @@ var useQwikRouter = (props) => {
|
|
|
962
1102
|
});
|
|
963
1103
|
});
|
|
964
1104
|
};
|
|
1105
|
+
if (isBrowser && !window._qRouterSPA) window._qRouterInitNavigate = startNavigation;
|
|
965
1106
|
return startNavigation(path, opt);
|
|
966
1107
|
}, "useQwikRouter_goto_8j8Vrz2yUIM", [
|
|
967
1108
|
actionDataSignal,
|
|
@@ -1005,6 +1146,7 @@ function initializeSPA(goto, scroller) {
|
|
|
1005
1146
|
});
|
|
1006
1147
|
window.removeEventListener("popstate", window._qRouterInitPopstate);
|
|
1007
1148
|
window._qRouterInitPopstate = void 0;
|
|
1149
|
+
window._qRouterInitNavigate = void 0;
|
|
1008
1150
|
if (!window._qRouterHistoryPatch) {
|
|
1009
1151
|
window._qRouterHistoryPatch = true;
|
|
1010
1152
|
const pushState = history.pushState;
|
|
@@ -1226,34 +1368,33 @@ Action.run() can only be called on the browser, for example when a user clicks a
|
|
|
1226
1368
|
let form;
|
|
1227
1369
|
if (input instanceof SubmitEvent) {
|
|
1228
1370
|
form = input.target;
|
|
1229
|
-
data = new FormData(form);
|
|
1230
|
-
if ((input.submitter instanceof HTMLInputElement || input.submitter instanceof HTMLButtonElement) && input.submitter.name) {
|
|
1231
|
-
if (input.submitter.name) data.append(input.submitter.name, input.submitter.value);
|
|
1232
|
-
}
|
|
1371
|
+
data = new FormData(form, input.submitter);
|
|
1233
1372
|
} else data = input;
|
|
1234
1373
|
const submission = {};
|
|
1235
1374
|
latestSubmission.current = submission;
|
|
1375
|
+
state.isRunning = true;
|
|
1236
1376
|
const previousDispatch = currentAction.pendingDispatch ?? Promise.resolve();
|
|
1237
1377
|
let resolveDispatch;
|
|
1238
1378
|
currentAction.pendingDispatch = noSerialize(new Promise((resolve) => {
|
|
1239
1379
|
resolveDispatch = resolve;
|
|
1240
1380
|
}));
|
|
1241
|
-
return previousDispatch.then(() => new Promise((resolve) => {
|
|
1381
|
+
return previousDispatch.then(() => new Promise((resolve, reject) => {
|
|
1242
1382
|
if (data instanceof FormData) state.formData = data;
|
|
1243
1383
|
state.submitted = true;
|
|
1244
|
-
state.isRunning = true;
|
|
1245
1384
|
loc.isNavigating = true;
|
|
1246
1385
|
currentAction.value = {
|
|
1247
1386
|
data,
|
|
1248
1387
|
id,
|
|
1249
1388
|
resolve: noSerialize(resolve),
|
|
1389
|
+
reject: noSerialize(reject),
|
|
1250
1390
|
resolveDispatch: noSerialize(resolveDispatch)
|
|
1251
1391
|
};
|
|
1252
1392
|
runAction?.(RUN_PENDING_ACTION);
|
|
1253
|
-
})).
|
|
1393
|
+
})).finally(() => {
|
|
1394
|
+
if (latestSubmission.current === submission) state.isRunning = false;
|
|
1395
|
+
}).then(({ result, status }) => {
|
|
1254
1396
|
const isLatestSubmission = latestSubmission.current === submission;
|
|
1255
1397
|
if (isLatestSubmission) {
|
|
1256
|
-
state.isRunning = false;
|
|
1257
1398
|
state.status = status;
|
|
1258
1399
|
state.value = result;
|
|
1259
1400
|
}
|
|
@@ -1460,29 +1601,7 @@ function serverQrl(qrl, options) {
|
|
|
1460
1601
|
const body = await _serialize(toSend);
|
|
1461
1602
|
if (method === "GET") query += `&${QDATA_KEY}=${encodeURIComponent(body)}`;
|
|
1462
1603
|
else config.body = body;
|
|
1463
|
-
|
|
1464
|
-
const contentType = res.headers.get("Content-Type");
|
|
1465
|
-
if (res.ok && contentType === "text/qwik-json-stream" && res.body) return (async function* () {
|
|
1466
|
-
try {
|
|
1467
|
-
for await (const result of deserializeStream(res.body, abortSignal)) yield result;
|
|
1468
|
-
} finally {
|
|
1469
|
-
if (!abortSignal?.aborted) await res.body.cancel();
|
|
1470
|
-
}
|
|
1471
|
-
})();
|
|
1472
|
-
else if (contentType === "application/qwik-json") {
|
|
1473
|
-
const str = await res.text();
|
|
1474
|
-
const obj = await _deserialize(str);
|
|
1475
|
-
if (res.status >= 400) throw obj;
|
|
1476
|
-
return obj;
|
|
1477
|
-
} else if (contentType === "application/json") {
|
|
1478
|
-
const obj = await res.json();
|
|
1479
|
-
if (res.status >= 400) throw obj;
|
|
1480
|
-
return obj;
|
|
1481
|
-
} else if (contentType === "text/plain" || contentType === "text/html") {
|
|
1482
|
-
const str = await res.text();
|
|
1483
|
-
if (res.status >= 400) throw str;
|
|
1484
|
-
return str;
|
|
1485
|
-
}
|
|
1604
|
+
return readServerFunctionResponse(await fetch(`${origin}?${QFN_KEY}=${qrlHash}${query}`, config), abortSignal);
|
|
1486
1605
|
}
|
|
1487
1606
|
}, "serverQrl_w03grD0Ag68", [
|
|
1488
1607
|
fetchOptions,
|
|
@@ -1492,6 +1611,32 @@ function serverQrl(qrl, options) {
|
|
|
1492
1611
|
qrl
|
|
1493
1612
|
]);
|
|
1494
1613
|
}
|
|
1614
|
+
/** @internal Exported for tests */
|
|
1615
|
+
async function readServerFunctionResponse(res, abortSignal) {
|
|
1616
|
+
const contentType = res.headers.get("Content-Type")?.split(";")[0].trim().toLowerCase();
|
|
1617
|
+
if (res.ok && contentType === "text/qwik-json-stream" && res.body) return (async function* () {
|
|
1618
|
+
try {
|
|
1619
|
+
for await (const result of deserializeStream(res.body, abortSignal)) yield result;
|
|
1620
|
+
} finally {
|
|
1621
|
+
if (!abortSignal?.aborted) await res.body.cancel();
|
|
1622
|
+
}
|
|
1623
|
+
})();
|
|
1624
|
+
else if (contentType === "application/qwik-json") {
|
|
1625
|
+
const str = await res.text();
|
|
1626
|
+
const obj = await _deserialize(str);
|
|
1627
|
+
if (res.status >= 400) throw obj;
|
|
1628
|
+
return obj;
|
|
1629
|
+
} else if (contentType === "application/json") {
|
|
1630
|
+
const obj = await res.json();
|
|
1631
|
+
if (res.status >= 400) throw obj;
|
|
1632
|
+
return obj;
|
|
1633
|
+
} else if (contentType === "text/plain") {
|
|
1634
|
+
const str = await res.text();
|
|
1635
|
+
if (res.status >= 400) throw str;
|
|
1636
|
+
return str;
|
|
1637
|
+
}
|
|
1638
|
+
throw new Error(`server$ got an unexpected response: ${res.status} ${res.headers.get("Content-Type") ?? "(no Content-Type)"}`);
|
|
1639
|
+
}
|
|
1495
1640
|
/** @public */
|
|
1496
1641
|
var server$ = /*#__PURE__*/ implicit$FirstArg(serverQrl);
|
|
1497
1642
|
function getValidators(rest, qrl) {
|
|
@@ -1564,23 +1709,34 @@ var _hf0_str$1 = "p0.spaReset?\"true\":undefined";
|
|
|
1564
1709
|
/** @public */
|
|
1565
1710
|
var Form = ({ action, spaReset, reloadDocument, onSubmit$, ...rest }, key) => {
|
|
1566
1711
|
if (action) {
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
"preventdefault:submit": !reloadDocument,
|
|
1572
|
-
"q-e:submit": [...onSubmit$, !reloadDocument ? /*#__PURE__*/ inlinedQrl((evt) => {
|
|
1573
|
-
let action = _capturesObj._[0];
|
|
1574
|
-
if (!action.submitted) return action.submit(evt);
|
|
1575
|
-
}, "Form_form_q_e_submit_6i0Jq5q8JFg", [action]) : void 0],
|
|
1576
|
-
["data-spa-reset"]: spaReset ? "true" : void 0
|
|
1577
|
-
}, { method: "post" }, null, 0, key);
|
|
1712
|
+
const submitHandlers = [onSubmit$].flat(Infinity);
|
|
1713
|
+
const firstAsyncHandler = submitHandlers.findIndex((handler) => handler && !_isSyncQrl(handler));
|
|
1714
|
+
const syncHandlers = firstAsyncHandler === -1 ? submitHandlers : submitHandlers.slice(0, firstAsyncHandler);
|
|
1715
|
+
const asyncHandlers = firstAsyncHandler === -1 ? [] : submitHandlers.slice(firstAsyncHandler);
|
|
1578
1716
|
return /*#__PURE__*/ _jsxSplit("form", {
|
|
1579
1717
|
..._getVarProps(rest),
|
|
1580
1718
|
..._getConstProps(rest),
|
|
1581
1719
|
action: _wrapProp(action, "actionPath"),
|
|
1582
1720
|
"preventdefault:submit": !reloadDocument,
|
|
1583
|
-
"q-e:submit": [
|
|
1721
|
+
"q-e:submit": [
|
|
1722
|
+
!reloadDocument ? _qrlSync((event, form) => {
|
|
1723
|
+
form._qSubmit ??= event;
|
|
1724
|
+
}, "(event,form)=>{form._qSubmit??=event;}") : void 0,
|
|
1725
|
+
...!reloadDocument ? syncHandlers : [],
|
|
1726
|
+
!reloadDocument ? /*#__PURE__*/ inlinedQrl(async (event, form) => {
|
|
1727
|
+
let action = _capturesObj._[0], asyncHandlers = _capturesObj._[1];
|
|
1728
|
+
if (form._qSubmit !== event) return;
|
|
1729
|
+
try {
|
|
1730
|
+
for (const handler of asyncHandlers) await handler?.(event, form);
|
|
1731
|
+
await action.submit(event);
|
|
1732
|
+
} finally {
|
|
1733
|
+
delete form._qSubmit;
|
|
1734
|
+
}
|
|
1735
|
+
}, "Form_form_q_e_submit_6i0Jq5q8JFg", [action, asyncHandlers]) : onSubmit$,
|
|
1736
|
+
!reloadDocument ? _qrlSync((event, form) => {
|
|
1737
|
+
if (form._qSubmit === event) delete form._qSubmit;
|
|
1738
|
+
}, "(event,form)=>{if(form._qSubmit===event){delete form._qSubmit;}}") : void 0
|
|
1739
|
+
],
|
|
1584
1740
|
["data-spa-reset"]: spaReset ? "true" : void 0
|
|
1585
1741
|
}, { method: "post" }, null, 0, key);
|
|
1586
1742
|
} else return /*#__PURE__*/ _jsxSplit(GetForm, {
|
|
@@ -269,8 +269,14 @@ function createQwikRouter(opts) {
|
|
|
269
269
|
const handled = await requestHandler(serverRequestEv, opts);
|
|
270
270
|
if (handled) {
|
|
271
271
|
const err = await handled.completion;
|
|
272
|
+
if (err) {
|
|
273
|
+
if (res.headersSent && !res.writableEnded) {
|
|
274
|
+
res.destroy();
|
|
275
|
+
res.end();
|
|
276
|
+
}
|
|
277
|
+
throw err;
|
|
278
|
+
}
|
|
272
279
|
if (handled.requestEv.headersSent) return;
|
|
273
|
-
if (err) throw err;
|
|
274
280
|
}
|
|
275
281
|
next();
|
|
276
282
|
} catch (e) {
|