vinext 0.0.43 → 0.0.45
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/dist/build/google-fonts/build-url.d.ts +10 -0
- package/dist/build/google-fonts/build-url.js +30 -0
- package/dist/build/google-fonts/build-url.js.map +1 -0
- package/dist/build/google-fonts/font-data.js +24985 -0
- package/dist/build/google-fonts/font-data.js.map +1 -0
- package/dist/build/google-fonts/font-metadata.d.ts +17 -0
- package/dist/build/google-fonts/font-metadata.js +7 -0
- package/dist/build/google-fonts/font-metadata.js.map +1 -0
- package/dist/build/google-fonts/get-axes.d.ts +7 -0
- package/dist/build/google-fonts/get-axes.js +39 -0
- package/dist/build/google-fonts/get-axes.js.map +1 -0
- package/dist/build/google-fonts/sort-variants.d.ts +5 -0
- package/dist/build/google-fonts/sort-variants.js +14 -0
- package/dist/build/google-fonts/sort-variants.js.map +1 -0
- package/dist/build/google-fonts/validate.d.ts +28 -0
- package/dist/build/google-fonts/validate.js +56 -0
- package/dist/build/google-fonts/validate.js.map +1 -0
- package/dist/build/layout-classification.d.ts +1 -1
- package/dist/build/layout-classification.js.map +1 -1
- package/dist/build/nitro-route-rules.d.ts +1 -1
- package/dist/build/nitro-route-rules.js.map +1 -1
- package/dist/build/precompress.d.ts +1 -1
- package/dist/build/precompress.js.map +1 -1
- package/dist/build/prerender.d.ts +1 -7
- package/dist/build/prerender.js +7 -3
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/run-prerender.d.ts +1 -13
- package/dist/build/run-prerender.js +5 -1
- package/dist/build/run-prerender.js.map +1 -1
- package/dist/build/standalone.d.ts +1 -1
- package/dist/build/standalone.js.map +1 -1
- package/dist/client/vinext-next-data.d.ts +1 -3
- package/dist/cloudflare/kv-cache-handler.d.ts +5 -0
- package/dist/cloudflare/kv-cache-handler.js +56 -35
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.d.ts +1 -16
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/dotenv.d.ts +1 -1
- package/dist/config/dotenv.js.map +1 -1
- package/dist/deploy.d.ts +1 -1
- package/dist/deploy.js +21 -4
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-rsc-entry.js +93 -15
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.js.map +1 -1
- package/dist/plugins/async-hooks-stub.d.ts +1 -2
- package/dist/plugins/async-hooks-stub.js +2 -2
- package/dist/plugins/async-hooks-stub.js.map +1 -1
- package/dist/plugins/fonts.d.ts +1 -20
- package/dist/plugins/fonts.js +42 -21
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/server-externals-manifest.d.ts +1 -11
- package/dist/plugins/server-externals-manifest.js +1 -1
- package/dist/plugins/server-externals-manifest.js.map +1 -1
- package/dist/routing/app-router.d.ts +2 -1
- package/dist/routing/app-router.js +12 -6
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +1 -3
- package/dist/routing/file-matcher.js +1 -1
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/utils.d.ts +1 -29
- package/dist/routing/utils.js +1 -1
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/app-browser-entry.js +183 -99
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-state.d.ts +1 -1
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-stream.d.ts +1 -1
- package/dist/server/app-browser-stream.js.map +1 -1
- package/dist/server/app-elements.d.ts +1 -2
- package/dist/server/app-elements.js +1 -1
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-page-boundary-render.d.ts +3 -1
- package/dist/server/app-page-boundary-render.js +2 -0
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.d.ts +2 -1
- package/dist/server/app-page-boundary.js +10 -5
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +4 -2
- package/dist/server/app-page-execution.js +19 -4
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-probe.d.ts +1 -1
- package/dist/server/app-page-probe.js.map +1 -1
- package/dist/server/app-page-render.d.ts +2 -2
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +1 -1
- package/dist/server/app-page-request.js.map +1 -1
- package/dist/server/app-page-response.d.ts +1 -1
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +2 -8
- package/dist/server/app-page-route-wiring.js +13 -3
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +2 -1
- package/dist/server/app-page-stream.js +5 -3
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-route-handler-cache.d.ts +1 -1
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +1 -1
- package/dist/server/app-route-handler-execution.js +9 -4
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-policy.d.ts +6 -2
- package/dist/server/app-route-handler-policy.js +8 -3
- package/dist/server/app-route-handler-policy.js.map +1 -1
- package/dist/server/app-route-handler-response.d.ts +1 -1
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-route-handler-runtime.d.ts +1 -1
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-handler-runtime.js.map +1 -1
- package/dist/server/app-router-entry.js +8 -1
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-server-action-execution.d.ts +35 -0
- package/dist/server/app-server-action-execution.js +105 -0
- package/dist/server/app-server-action-execution.js.map +1 -0
- package/dist/server/app-ssr-entry.js +2 -1
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +1 -1
- package/dist/server/app-ssr-stream.js.map +1 -1
- package/dist/server/csp.d.ts +1 -2
- package/dist/server/csp.js +1 -1
- package/dist/server/csp.js.map +1 -1
- package/dist/server/dev-module-runner.d.ts +1 -1
- package/dist/server/dev-module-runner.js.map +1 -1
- package/dist/server/middleware-request-headers.d.ts +1 -3
- package/dist/server/middleware-request-headers.js +4 -4
- package/dist/server/middleware-request-headers.js.map +1 -1
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/pages-api-route.d.ts +1 -1
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-i18n.d.ts +2 -3
- package/dist/server/pages-i18n.js +1 -1
- package/dist/server/pages-i18n.js.map +1 -1
- package/dist/server/pages-node-compat.d.ts +1 -2
- package/dist/server/pages-node-compat.js +1 -1
- package/dist/server/pages-node-compat.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +1 -1
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +1 -1
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prod-server.js +18 -13
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +33 -1
- package/dist/server/request-pipeline.js +44 -2
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/socket-error-backstop.d.ts +17 -0
- package/dist/server/socket-error-backstop.js +129 -0
- package/dist/server/socket-error-backstop.js.map +1 -0
- package/dist/server/static-file-cache.d.ts +1 -1
- package/dist/server/static-file-cache.js.map +1 -1
- package/dist/shims/cache-runtime.js +16 -3
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +3 -1
- package/dist/shims/cache.js +83 -22
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +1 -1
- package/dist/shims/fetch-cache.d.ts +10 -1
- package/dist/shims/fetch-cache.js +24 -4
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/font-google-base.d.ts +16 -18
- package/dist/shims/font-google-base.js +25 -16
- package/dist/shims/font-google-base.js.map +1 -1
- package/dist/shims/form.js +1 -1
- package/dist/shims/link.js +1 -1
- package/dist/shims/navigation.d.ts +7 -3
- package/dist/shims/navigation.js +28 -5
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/server.d.ts +2 -0
- package/dist/shims/server.js +18 -5
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/shims/url-safety.d.ts +3 -1
- package/dist/shims/url-safety.js +5 -1
- package/dist/shims/url-safety.js.map +1 -1
- package/dist/utils/error-cause.d.ts +5 -0
- package/dist/utils/error-cause.js +97 -0
- package/dist/utils/error-cause.js.map +1 -0
- package/dist/utils/lazy-chunks.d.ts +1 -1
- package/dist/utils/lazy-chunks.js.map +1 -1
- package/package.json +1 -1
- package/dist/client/entry.d.ts +0 -1
- package/dist/client/entry.js +0 -60
- package/dist/client/entry.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DANGEROUS_URL_BLOCK_MESSAGE, isDangerousScheme } from "../shims/url-safety.js";
|
|
1
2
|
import { stripBasePath } from "../utils/base-path.js";
|
|
2
3
|
import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
|
|
3
4
|
import { createAppPayloadCacheKey, getMountedSlotIdsHeader, normalizeAppElements, readAppElementsMetadata, resolveVisitedResponseInterceptionContext } from "./app-elements.js";
|
|
@@ -8,8 +9,8 @@ import { chunksToReadableStream, createProgressiveRscStream, getVinextBrowserGlo
|
|
|
8
9
|
import { createHistoryStateWithPreviousNextUrl, createPendingNavigationCommit, readHistoryStatePreviousNextUrl, resolveAndClassifyNavigationCommit, resolveInterceptionContextFromPreviousNextUrl, resolvePendingNavigationCommitDisposition, resolveServerActionRequestState, routerReducer } from "./app-browser-state.js";
|
|
9
10
|
import { devOnCaughtError } from "./app-browser-error.js";
|
|
10
11
|
import { createElement, startTransition, use, useLayoutEffect, useRef, useState } from "react";
|
|
11
|
-
import { hydrateRoot } from "react-dom/client";
|
|
12
12
|
import { createFromFetch, createFromReadableStream, createTemporaryReferenceSet, encodeReply, setServerCallback } from "@vitejs/plugin-rsc/browser";
|
|
13
|
+
import { hydrateRoot } from "react-dom/client";
|
|
13
14
|
//#region src/server/app-browser-entry.ts
|
|
14
15
|
function toActionType(kind) {
|
|
15
16
|
return kind === "traverse" ? "traverse" : "navigate";
|
|
@@ -109,13 +110,13 @@ function drainPrePaintEffects(upToRenderId) {
|
|
|
109
110
|
for (const [id, effect] of pendingNavigationPrePaintEffects) if (id <= upToRenderId) {
|
|
110
111
|
pendingNavigationPrePaintEffects.delete(id);
|
|
111
112
|
if (id === upToRenderId) effect();
|
|
112
|
-
else commitClientNavigationState(void 0);
|
|
113
|
+
else commitClientNavigationState(void 0, { releaseSnapshot: true });
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
function createNavigationCommitEffect(href, historyUpdateMode, navId, params, previousNextUrl) {
|
|
116
117
|
return () => {
|
|
117
118
|
if (navId !== activeNavigationId) {
|
|
118
|
-
commitClientNavigationState(void 0);
|
|
119
|
+
commitClientNavigationState(void 0, { releaseSnapshot: true });
|
|
119
120
|
return;
|
|
120
121
|
}
|
|
121
122
|
const targetHref = new URL(href, window.location.origin).href;
|
|
@@ -371,17 +372,78 @@ function restoreHydrationNavigationContext(pathname, searchParams, params) {
|
|
|
371
372
|
params
|
|
372
373
|
});
|
|
373
374
|
}
|
|
375
|
+
function decodeHashFragment(fragment) {
|
|
376
|
+
try {
|
|
377
|
+
return decodeURIComponent(fragment);
|
|
378
|
+
} catch {
|
|
379
|
+
return fragment;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function scrollToHashTarget(hash) {
|
|
383
|
+
const fragment = decodeHashFragment(hash.startsWith("#") ? hash.slice(1) : hash);
|
|
384
|
+
requestAnimationFrame(() => {
|
|
385
|
+
if (fragment === "" || fragment === "top") {
|
|
386
|
+
window.scrollTo(0, 0);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const idElement = document.getElementById(fragment);
|
|
390
|
+
if (idElement) {
|
|
391
|
+
idElement.scrollIntoView({ behavior: "auto" });
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
document.getElementsByName(fragment)[0]?.scrollIntoView({ behavior: "auto" });
|
|
395
|
+
});
|
|
396
|
+
}
|
|
374
397
|
function restorePopstateScrollPosition(state) {
|
|
375
|
-
if (!(state && typeof state === "object" && "__vinext_scrollY" in state))
|
|
398
|
+
if (!(state && typeof state === "object" && "__vinext_scrollY" in state)) {
|
|
399
|
+
if (window.location.hash) scrollToHashTarget(window.location.hash);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
376
402
|
const y = Number(state.__vinext_scrollY);
|
|
377
403
|
const x = "__vinext_scrollX" in state ? Number(state.__vinext_scrollX) : 0;
|
|
378
404
|
requestAnimationFrame(() => {
|
|
379
405
|
window.scrollTo(x, y);
|
|
380
406
|
});
|
|
381
407
|
}
|
|
408
|
+
let isPageUnloading = false;
|
|
409
|
+
const RSC_RELOAD_KEY = "__vinext_rsc_initial_reload__";
|
|
410
|
+
function readReloadFlag() {
|
|
411
|
+
try {
|
|
412
|
+
return sessionStorage.getItem(RSC_RELOAD_KEY);
|
|
413
|
+
} catch {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function writeReloadFlag(path) {
|
|
418
|
+
try {
|
|
419
|
+
sessionStorage.setItem(RSC_RELOAD_KEY, path);
|
|
420
|
+
} catch {}
|
|
421
|
+
}
|
|
422
|
+
function clearReloadFlag() {
|
|
423
|
+
try {
|
|
424
|
+
sessionStorage.removeItem(RSC_RELOAD_KEY);
|
|
425
|
+
} catch {}
|
|
426
|
+
}
|
|
427
|
+
function recoverFromBadInitialRscResponse(reason) {
|
|
428
|
+
const currentPath = window.location.pathname + window.location.search;
|
|
429
|
+
if (readReloadFlag() === currentPath) {
|
|
430
|
+
clearReloadFlag();
|
|
431
|
+
console.error(`[vinext] Initial RSC fetch ${reason} after reload; aborting hydration. Server-rendered HTML remains visible; client components will not hydrate.`);
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
writeReloadFlag(currentPath);
|
|
435
|
+
if (readReloadFlag() !== currentPath) {
|
|
436
|
+
console.error(`[vinext] Initial RSC fetch ${reason}; sessionStorage unavailable so the reload-loop guard cannot persist — aborting hydration. Server-rendered HTML remains visible; client components will not hydrate.`);
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
console.warn(`[vinext] Initial RSC fetch ${reason}; reloading once to let the server render the HTML error page`);
|
|
440
|
+
window.location.reload();
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
382
443
|
async function readInitialRscStream() {
|
|
383
444
|
const vinext = getVinextBrowserGlobal();
|
|
384
445
|
if (vinext.__VINEXT_RSC__ || vinext.__VINEXT_RSC_CHUNKS__ || vinext.__VINEXT_RSC_DONE__) {
|
|
446
|
+
clearReloadFlag();
|
|
385
447
|
if (vinext.__VINEXT_RSC__) {
|
|
386
448
|
const embedData = vinext.__VINEXT_RSC__;
|
|
387
449
|
delete vinext.__VINEXT_RSC__;
|
|
@@ -396,6 +458,11 @@ async function readInitialRscStream() {
|
|
|
396
458
|
return createProgressiveRscStream();
|
|
397
459
|
}
|
|
398
460
|
const rscResponse = await fetch(toRscUrl(window.location.pathname + window.location.search));
|
|
461
|
+
if (!rscResponse.ok) return recoverFromBadInitialRscResponse(`returned ${rscResponse.status}`);
|
|
462
|
+
const contentType = rscResponse.headers.get("content-type") ?? "";
|
|
463
|
+
if (!contentType.startsWith("text/x-component")) return recoverFromBadInitialRscResponse(`returned non-RSC content-type "${contentType || "(missing)"}"`);
|
|
464
|
+
if (!rscResponse.body) return recoverFromBadInitialRscResponse("returned empty body");
|
|
465
|
+
clearReloadFlag();
|
|
399
466
|
let params = {};
|
|
400
467
|
const paramsHeader = rscResponse.headers.get("X-Vinext-Params");
|
|
401
468
|
if (paramsHeader) try {
|
|
@@ -403,7 +470,6 @@ async function readInitialRscStream() {
|
|
|
403
470
|
applyClientParams(params);
|
|
404
471
|
} catch {}
|
|
405
472
|
restoreHydrationNavigationContext(window.location.pathname, window.location.search, params);
|
|
406
|
-
if (!rscResponse.body) throw new Error("[vinext] Initial RSC response had no body");
|
|
407
473
|
return rscResponse.body;
|
|
408
474
|
}
|
|
409
475
|
function registerServerActionCallback() {
|
|
@@ -424,6 +490,10 @@ function registerServerActionCallback() {
|
|
|
424
490
|
});
|
|
425
491
|
const actionRedirect = fetchResponse.headers.get("x-action-redirect");
|
|
426
492
|
if (actionRedirect) {
|
|
493
|
+
if (isDangerousScheme(actionRedirect)) {
|
|
494
|
+
console.error(DANGEROUS_URL_BLOCK_MESSAGE);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
427
497
|
try {
|
|
428
498
|
if (new URL(actionRedirect, window.location.origin).origin !== window.location.origin) {
|
|
429
499
|
window.location.href = actionRedirect;
|
|
@@ -442,7 +512,12 @@ function registerServerActionCallback() {
|
|
|
442
512
|
}
|
|
443
513
|
async function main() {
|
|
444
514
|
registerServerActionCallback();
|
|
445
|
-
const
|
|
515
|
+
const rscStream = await readInitialRscStream();
|
|
516
|
+
if (rscStream === null) return;
|
|
517
|
+
bootstrapHydration(rscStream);
|
|
518
|
+
}
|
|
519
|
+
function bootstrapHydration(rscStream) {
|
|
520
|
+
const root = normalizeAppElementsPromise(createFromReadableStream(rscStream));
|
|
446
521
|
const initialNavigationSnapshot = createClientNavigationRenderSnapshot(window.location.href, latestClientParams);
|
|
447
522
|
replaceHistoryStateWithoutNotify(createHistoryStateWithPreviousNextUrl(window.history.state, null), "", window.location.href);
|
|
448
523
|
window.__VINEXT_RSC_ROOT__ = hydrateRoot(document, createElement(BrowserRoot, {
|
|
@@ -451,121 +526,122 @@ async function main() {
|
|
|
451
526
|
}), import.meta.env.DEV ? { onCaughtError: devOnCaughtError } : void 0);
|
|
452
527
|
window.__VINEXT_HYDRATED_AT = performance.now();
|
|
453
528
|
window.__VINEXT_RSC_NAVIGATE__ = async function navigateRsc(href, redirectDepth = 0, navigationKind = "navigate", historyUpdateMode, previousNextUrlOverride, programmaticTransition = false) {
|
|
454
|
-
if (redirectDepth > 10) {
|
|
455
|
-
console.error("[vinext] Too many RSC redirects — aborting navigation to prevent infinite loop.");
|
|
456
|
-
window.location.href = href;
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
529
|
let _snapshotPending = false;
|
|
460
530
|
let pendingRouterState = null;
|
|
461
531
|
const navId = ++activeNavigationId;
|
|
532
|
+
let currentHref = href;
|
|
533
|
+
let currentHistoryMode = historyUpdateMode;
|
|
534
|
+
let currentPrevNextUrl = previousNextUrlOverride;
|
|
535
|
+
let redirectCount = redirectDepth;
|
|
462
536
|
try {
|
|
463
537
|
if (programmaticTransition) pendingRouterState = beginPendingBrowserRouterState();
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
538
|
+
while (true) {
|
|
539
|
+
if (redirectCount > 10) {
|
|
540
|
+
console.error("[vinext] Too many RSC redirects — aborting navigation to prevent infinite loop.");
|
|
541
|
+
window.location.href = currentHref;
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const url = new URL(currentHref, window.location.origin);
|
|
545
|
+
const rscUrl = toRscUrl(url.pathname + url.search);
|
|
546
|
+
const requestState = getRequestState(navigationKind, currentPrevNextUrl);
|
|
547
|
+
const requestInterceptionContext = requestState.interceptionContext;
|
|
548
|
+
const requestPreviousNextUrl = requestState.previousNextUrl;
|
|
549
|
+
const navState = getClientNavigationState();
|
|
550
|
+
const currentPath = navState?.pendingPathname ?? navState?.cachedPathname ?? stripBasePath(window.location.pathname, __basePath);
|
|
551
|
+
const isSameRoute = stripBasePath(url.pathname, __basePath) === currentPath;
|
|
552
|
+
setPendingPathname(url.pathname, navId);
|
|
553
|
+
const elementsAtNavStart = getBrowserRouterState().elements;
|
|
554
|
+
const mountedSlotsHeader = getMountedSlotIdsHeader(elementsAtNavStart);
|
|
555
|
+
const cachedRoute = getVisitedResponse(rscUrl, requestInterceptionContext, mountedSlotsHeader, navigationKind);
|
|
556
|
+
if (cachedRoute) {
|
|
557
|
+
if (navId !== activeNavigationId) return;
|
|
558
|
+
const cachedParams = cachedRoute.params;
|
|
559
|
+
const cachedNavigationSnapshot = createClientNavigationRenderSnapshot(currentHref, cachedParams);
|
|
560
|
+
const cachedPayload = normalizeAppElementsPromise(createFromFetch(Promise.resolve(restoreRscResponse(cachedRoute.response))));
|
|
561
|
+
if (navId !== activeNavigationId) return;
|
|
562
|
+
_snapshotPending = true;
|
|
563
|
+
try {
|
|
564
|
+
await renderNavigationPayload(cachedPayload, cachedNavigationSnapshot, currentHref, navId, currentHistoryMode, cachedParams, requestPreviousNextUrl, pendingRouterState, isSameRoute, toActionType(navigationKind));
|
|
565
|
+
} finally {
|
|
566
|
+
_snapshotPending = false;
|
|
567
|
+
}
|
|
479
568
|
return;
|
|
480
569
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
570
|
+
let navResponse;
|
|
571
|
+
let navResponseUrl = null;
|
|
572
|
+
if (navigationKind !== "refresh") {
|
|
573
|
+
const prefetchedResponse = consumePrefetchResponse(rscUrl, requestInterceptionContext, mountedSlotsHeader);
|
|
574
|
+
if (prefetchedResponse) {
|
|
575
|
+
navResponse = restoreRscResponse(prefetchedResponse, false);
|
|
576
|
+
navResponseUrl = prefetchedResponse.url;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
if (!navResponse) {
|
|
580
|
+
const requestHeaders = createRscRequestHeaders(requestInterceptionContext);
|
|
581
|
+
if (mountedSlotsHeader) requestHeaders.set("X-Vinext-Mounted-Slots", mountedSlotsHeader);
|
|
582
|
+
navResponse = await fetch(rscUrl, {
|
|
583
|
+
headers: requestHeaders,
|
|
584
|
+
credentials: "include"
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
if (navId !== activeNavigationId) return;
|
|
588
|
+
const isRscResponse = (navResponse.headers.get("content-type") ?? "").startsWith("text/x-component");
|
|
589
|
+
if (!navResponse.ok || !isRscResponse || !navResponse.body) {
|
|
590
|
+
const responseUrl = navResponseUrl ?? navResponse.url;
|
|
591
|
+
let hardNavTarget = currentHref;
|
|
592
|
+
if (responseUrl) {
|
|
593
|
+
const parsed = new URL(responseUrl, window.location.origin);
|
|
594
|
+
const origUrl = new URL(currentHref, window.location.origin);
|
|
595
|
+
let pathname = parsed.pathname.replace(/\.rsc$/, "");
|
|
596
|
+
if (origUrl.pathname.length > 1 && origUrl.pathname.endsWith("/") && !pathname.endsWith("/")) pathname += "/";
|
|
597
|
+
hardNavTarget = pathname + parsed.search;
|
|
598
|
+
if (origUrl.hash) hardNavTarget += origUrl.hash;
|
|
599
|
+
}
|
|
600
|
+
window.location.href = hardNavTarget;
|
|
486
601
|
return;
|
|
487
602
|
}
|
|
603
|
+
const finalUrl = new URL(navResponseUrl ?? navResponse.url, window.location.origin);
|
|
604
|
+
const requestedUrl = new URL(rscUrl, window.location.origin);
|
|
605
|
+
if (finalUrl.pathname !== requestedUrl.pathname) {
|
|
606
|
+
const destinationPath = finalUrl.pathname.replace(/\.rsc$/, "") + finalUrl.search;
|
|
607
|
+
replaceHistoryStateWithoutNotify(createHistoryStateWithPreviousNextUrl(null, requestPreviousNextUrl), "", destinationPath);
|
|
608
|
+
currentHref = destinationPath;
|
|
609
|
+
currentHistoryMode = void 0;
|
|
610
|
+
currentPrevNextUrl = requestPreviousNextUrl;
|
|
611
|
+
redirectCount += 1;
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
let navParams = {};
|
|
615
|
+
const paramsHeader = navResponse.headers.get("X-Vinext-Params");
|
|
616
|
+
if (paramsHeader) try {
|
|
617
|
+
navParams = JSON.parse(decodeURIComponent(paramsHeader));
|
|
618
|
+
} catch {}
|
|
619
|
+
const navigationSnapshot = createClientNavigationRenderSnapshot(currentHref, navParams);
|
|
620
|
+
const responseSnapshot = await snapshotRscResponse(navResponse);
|
|
621
|
+
if (navId !== activeNavigationId) return;
|
|
622
|
+
const rscPayload = normalizeAppElementsPromise(createFromFetch(Promise.resolve(restoreRscResponse(responseSnapshot))));
|
|
623
|
+
if (navId !== activeNavigationId) return;
|
|
488
624
|
_snapshotPending = true;
|
|
489
625
|
try {
|
|
490
|
-
await renderNavigationPayload(
|
|
626
|
+
await renderNavigationPayload(rscPayload, navigationSnapshot, currentHref, navId, currentHistoryMode, navParams, requestPreviousNextUrl, pendingRouterState, isSameRoute, toActionType(navigationKind));
|
|
491
627
|
} finally {
|
|
492
628
|
_snapshotPending = false;
|
|
493
629
|
}
|
|
630
|
+
if (navId !== activeNavigationId) return;
|
|
631
|
+
storeVisitedResponseSnapshot(rscUrl, resolveVisitedResponseInterceptionContext(requestInterceptionContext, readAppElementsMetadata(await rscPayload).interceptionContext), responseSnapshot, navParams);
|
|
494
632
|
return;
|
|
495
633
|
}
|
|
496
|
-
let navResponse;
|
|
497
|
-
let navResponseUrl = null;
|
|
498
|
-
if (navigationKind !== "refresh") {
|
|
499
|
-
const prefetchedResponse = consumePrefetchResponse(rscUrl, requestInterceptionContext, mountedSlotsHeader);
|
|
500
|
-
if (prefetchedResponse) {
|
|
501
|
-
navResponse = restoreRscResponse(prefetchedResponse, false);
|
|
502
|
-
navResponseUrl = prefetchedResponse.url;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if (!navResponse) {
|
|
506
|
-
const requestHeaders = createRscRequestHeaders(requestInterceptionContext);
|
|
507
|
-
if (mountedSlotsHeader) requestHeaders.set("X-Vinext-Mounted-Slots", mountedSlotsHeader);
|
|
508
|
-
navResponse = await fetch(rscUrl, {
|
|
509
|
-
headers: requestHeaders,
|
|
510
|
-
credentials: "include"
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
if (navId !== activeNavigationId) {
|
|
514
|
-
settlePendingBrowserRouterState(pendingRouterState);
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
const finalUrl = new URL(navResponseUrl ?? navResponse.url, window.location.origin);
|
|
518
|
-
const requestedUrl = new URL(rscUrl, window.location.origin);
|
|
519
|
-
if (finalUrl.pathname !== requestedUrl.pathname) {
|
|
520
|
-
const destinationPath = finalUrl.pathname.replace(/\.rsc$/, "") + finalUrl.search;
|
|
521
|
-
replaceHistoryStateWithoutNotify(createHistoryStateWithPreviousNextUrl(null, requestPreviousNextUrl), "", destinationPath);
|
|
522
|
-
const navigate = window.__VINEXT_RSC_NAVIGATE__;
|
|
523
|
-
if (!navigate) {
|
|
524
|
-
settlePendingBrowserRouterState(pendingRouterState);
|
|
525
|
-
window.location.href = destinationPath;
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
settlePendingBrowserRouterState(pendingRouterState);
|
|
529
|
-
return navigate(destinationPath, redirectDepth + 1, navigationKind, void 0, requestPreviousNextUrl, false);
|
|
530
|
-
}
|
|
531
|
-
let navParams = {};
|
|
532
|
-
const paramsHeader = navResponse.headers.get("X-Vinext-Params");
|
|
533
|
-
if (paramsHeader) try {
|
|
534
|
-
navParams = JSON.parse(decodeURIComponent(paramsHeader));
|
|
535
|
-
} catch {}
|
|
536
|
-
const navigationSnapshot = createClientNavigationRenderSnapshot(href, navParams);
|
|
537
|
-
const responseSnapshot = await snapshotRscResponse(navResponse);
|
|
538
|
-
if (navId !== activeNavigationId) {
|
|
539
|
-
settlePendingBrowserRouterState(pendingRouterState);
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
const rscPayload = normalizeAppElementsPromise(createFromFetch(Promise.resolve(restoreRscResponse(responseSnapshot))));
|
|
543
|
-
if (navId !== activeNavigationId) {
|
|
544
|
-
settlePendingBrowserRouterState(pendingRouterState);
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
_snapshotPending = true;
|
|
548
|
-
try {
|
|
549
|
-
await renderNavigationPayload(rscPayload, navigationSnapshot, href, navId, historyUpdateMode, navParams, requestPreviousNextUrl, pendingRouterState, isSameRoute, toActionType(navigationKind));
|
|
550
|
-
} finally {
|
|
551
|
-
_snapshotPending = false;
|
|
552
|
-
}
|
|
553
|
-
if (navId !== activeNavigationId) {
|
|
554
|
-
settlePendingBrowserRouterState(pendingRouterState);
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
storeVisitedResponseSnapshot(rscUrl, resolveVisitedResponseInterceptionContext(requestInterceptionContext, readAppElementsMetadata(await rscPayload).interceptionContext), responseSnapshot, navParams);
|
|
558
|
-
return;
|
|
559
634
|
} catch (error) {
|
|
560
635
|
if (_snapshotPending) {
|
|
561
636
|
_snapshotPending = false;
|
|
562
637
|
commitClientNavigationState(navId);
|
|
563
638
|
}
|
|
639
|
+
if (navId !== activeNavigationId) return;
|
|
640
|
+
if (!isPageUnloading) console.error("[vinext] RSC navigation error:", error);
|
|
641
|
+
window.location.href = currentHref;
|
|
642
|
+
} finally {
|
|
564
643
|
settlePendingBrowserRouterState(pendingRouterState);
|
|
565
644
|
if (navId === activeNavigationId) clearPendingPathname(navId);
|
|
566
|
-
if (navId !== activeNavigationId) return;
|
|
567
|
-
console.error("[vinext] RSC navigation error:", error);
|
|
568
|
-
window.location.href = href;
|
|
569
645
|
}
|
|
570
646
|
};
|
|
571
647
|
if ("scrollRestoration" in history) history.scrollRestoration = "manual";
|
|
@@ -595,7 +671,15 @@ async function main() {
|
|
|
595
671
|
}
|
|
596
672
|
});
|
|
597
673
|
}
|
|
598
|
-
if (typeof document !== "undefined")
|
|
674
|
+
if (typeof document !== "undefined") {
|
|
675
|
+
window.addEventListener("pagehide", () => {
|
|
676
|
+
isPageUnloading = true;
|
|
677
|
+
});
|
|
678
|
+
window.addEventListener("pageshow", () => {
|
|
679
|
+
isPageUnloading = false;
|
|
680
|
+
});
|
|
681
|
+
main();
|
|
682
|
+
}
|
|
599
683
|
//#endregion
|
|
600
684
|
export {};
|
|
601
685
|
|