vinext 1.0.0-beta.6 → 1.0.0-beta.8
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 +47 -3
- package/dist/build/action-owner-manifest.d.ts +42 -0
- package/dist/build/action-owner-manifest.js +110 -0
- package/dist/build/clean-output.js +1 -4
- package/dist/build/client-build-config.js +10 -11
- package/dist/build/prerender.d.ts +1 -1
- package/dist/build/prerender.js +12 -6
- package/dist/build/report.d.ts +1 -1
- package/dist/build/route-classification-manifest.d.ts +1 -1
- package/dist/build/static-export.d.ts +1 -1
- package/dist/client/app-nav-failure-handler.js +1 -0
- package/dist/client/navigation-runtime.d.ts +5 -3
- package/dist/client/navigation-runtime.js +4 -8
- package/dist/entries/app-browser-entry.d.ts +1 -1
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +111 -8
- package/dist/entries/pages-client-entry.d.ts +1 -1
- package/dist/entries/pages-server-entry.d.ts +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +119 -26
- package/dist/plugins/action-owner-manifest.d.ts +14 -0
- package/dist/plugins/action-owner-manifest.js +84 -0
- package/dist/plugins/ast-utils.d.ts +30 -1
- package/dist/plugins/ast-utils.js +76 -1
- package/dist/plugins/css-module-imports.d.ts +2 -2
- package/dist/plugins/css-module-imports.js +5 -13
- package/dist/plugins/dynamic-preload-metadata.js +13 -34
- package/dist/plugins/environment.d.ts +11 -0
- package/dist/plugins/environment.js +7 -0
- package/dist/plugins/extensionless-dynamic-import.js +11 -35
- package/dist/plugins/fonts.js +8 -12
- package/dist/plugins/ignore-dynamic-requests.d.ts +2 -4
- package/dist/plugins/ignore-dynamic-requests.js +29 -59
- package/dist/plugins/import-meta-url.d.ts +15 -9
- package/dist/plugins/import-meta-url.js +310 -85
- package/dist/plugins/instrumentation-client.js +4 -5
- package/dist/plugins/middleware-export-validation.js +5 -17
- package/dist/plugins/middleware-server-only.js +2 -2
- package/dist/plugins/og-asset-ownership.js +18 -26
- package/dist/plugins/og-assets.js +2 -4
- package/dist/plugins/optimize-imports.js +2 -4
- package/dist/plugins/pages-node-externals.js +13 -40
- package/dist/plugins/remove-console.js +2 -4
- package/dist/plugins/require-condition-resolution.d.ts +16 -0
- package/dist/plugins/require-condition-resolution.js +167 -0
- package/dist/plugins/require-context.js +11 -46
- package/dist/plugins/sass.js +1 -1
- package/dist/plugins/server-externals-manifest.js +1 -23
- package/dist/plugins/strip-server-exports.js +13 -19
- package/dist/plugins/styled-jsx.js +17 -19
- package/dist/plugins/transform-result.d.ts +10 -0
- package/dist/plugins/transform-result.js +10 -0
- package/dist/plugins/transitive-externals.js +7 -21
- package/dist/plugins/typeof-window.d.ts +3 -8
- package/dist/plugins/typeof-window.js +5 -15
- package/dist/plugins/use-cache-callable.js +12 -22
- package/dist/plugins/wasm-module-import.js +1 -1
- package/dist/plugins/worker-image-imports.d.ts +12 -0
- package/dist/plugins/worker-image-imports.js +136 -0
- package/dist/routing/app-route-graph.d.ts +3 -2
- package/dist/routing/app-route-graph.js +1 -1
- package/dist/routing/route-pattern.d.ts +8 -1
- package/dist/routing/route-pattern.js +28 -1
- package/dist/routing/route-validation.js +7 -1
- package/dist/server/accept-encoding.d.ts +1 -2
- package/dist/server/accept-encoding.js +1 -4
- package/dist/server/app-action-forwarding.d.ts +18 -0
- package/dist/server/app-action-forwarding.js +140 -0
- package/dist/server/app-browser-entry.js +231 -50
- package/dist/server/app-browser-error.d.ts +1 -2
- package/dist/server/app-browser-error.js +1 -5
- package/dist/server/app-browser-history-controller.d.ts +16 -1
- package/dist/server/app-browser-history-controller.js +135 -18
- package/dist/server/app-browser-navigation-abort.d.ts +16 -0
- package/dist/server/app-browser-navigation-abort.js +29 -0
- package/dist/server/app-browser-navigation-controller.d.ts +4 -0
- package/dist/server/app-browser-navigation-controller.js +22 -6
- package/dist/server/app-browser-navigation-response.d.ts +11 -0
- package/dist/server/app-browser-navigation-response.js +8 -0
- package/dist/server/app-browser-popstate.d.ts +6 -1
- package/dist/server/app-browser-popstate.js +6 -2
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-browser-state.d.ts +2 -2
- package/dist/server/app-browser-state.js +3 -3
- package/dist/server/app-browser-stream.d.ts +0 -2
- package/dist/server/app-browser-supplemental-refresh.d.ts +49 -0
- package/dist/server/app-browser-supplemental-refresh.js +190 -0
- package/dist/server/app-browser-visible-commit.js +23 -12
- package/dist/server/app-elements-wire.d.ts +2 -0
- package/dist/server/app-elements-wire.js +7 -0
- package/dist/server/app-history-state.d.ts +22 -1
- package/dist/server/app-history-state.js +93 -9
- package/dist/server/app-optimistic-routing.d.ts +22 -1
- package/dist/server/app-optimistic-routing.js +137 -12
- package/dist/server/app-page-cache-finalizer.d.ts +3 -1
- package/dist/server/app-page-cache-finalizer.js +6 -6
- package/dist/server/app-page-cache.d.ts +2 -1
- package/dist/server/app-page-cache.js +2 -2
- package/dist/server/app-page-dispatch.d.ts +4 -1
- package/dist/server/app-page-dispatch.js +10 -1
- package/dist/server/app-page-element-builder.d.ts +1 -0
- package/dist/server/app-page-element-builder.js +1 -0
- package/dist/server/app-page-ppr-runtime.js +3 -2
- package/dist/server/app-page-render.d.ts +2 -1
- package/dist/server/app-page-render.js +6 -3
- package/dist/server/app-page-request.d.ts +2 -33
- package/dist/server/app-page-request.js +1 -27
- package/dist/server/app-page-route-wiring.d.ts +1 -0
- package/dist/server/app-page-route-wiring.js +4 -0
- package/dist/server/app-page-segment-state.d.ts +2 -2
- package/dist/server/app-page-segment-state.js +14 -8
- package/dist/server/app-ppr-fallback-shell.d.ts +2 -2
- package/dist/server/app-ppr-fallback-shell.js +3 -6
- package/dist/server/app-route-handler-dispatch.js +4 -1
- package/dist/server/app-route-handler-execution.js +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +2 -1
- package/dist/server/app-rsc-cache-busting.js +34 -8
- package/dist/server/app-rsc-handler.d.ts +4 -2
- package/dist/server/app-rsc-handler.js +57 -9
- package/dist/server/app-rsc-request-normalization.d.ts +2 -0
- package/dist/server/app-rsc-request-normalization.js +5 -1
- package/dist/server/app-rsc-route-matching.d.ts +4 -3
- package/dist/server/app-rsc-route-matching.js +14 -42
- package/dist/server/app-server-action-execution.d.ts +3 -0
- package/dist/server/app-server-action-execution.js +77 -2
- package/dist/server/app-ssr-entry.js +6 -6
- package/dist/server/app-ssr-stream.d.ts +1 -1
- package/dist/server/app-ssr-stream.js +2 -2
- package/dist/server/app-visited-response-cache.d.ts +6 -1
- package/dist/server/app-visited-response-cache.js +18 -2
- package/dist/server/dev-route-files.js +2 -5
- package/dist/server/dev-server.d.ts +5 -13
- package/dist/server/dev-server.js +22 -22
- package/dist/server/dev-stack-sourcemap.d.ts +1 -2
- package/dist/server/dev-stack-sourcemap.js +1 -4
- package/dist/server/headers.d.ts +5 -1
- package/dist/server/headers.js +5 -1
- package/dist/server/isr-cache.d.ts +6 -14
- package/dist/server/isr-cache.js +6 -27
- package/dist/server/middleware.d.ts +3 -16
- package/dist/server/middleware.js +2 -19
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +57 -9
- package/dist/server/navigation-trace.d.ts +1 -0
- package/dist/server/navigation-trace.js +1 -0
- package/dist/server/pages-data-route.d.ts +1 -10
- package/dist/server/pages-data-route.js +1 -12
- package/dist/server/pages-node-compat.d.ts +1 -4
- package/dist/server/pages-node-compat.js +1 -7
- package/dist/server/pages-readiness.js +4 -4
- package/dist/server/prerender-route-params.d.ts +1 -2
- package/dist/server/prerender-route-params.js +1 -4
- package/dist/server/prod-server.js +3 -1
- package/dist/shims/cache-runtime.js +39 -22
- package/dist/shims/cache.d.ts +1 -1
- package/dist/shims/dynamic.d.ts +3 -3
- package/dist/shims/dynamic.js +4 -6
- package/dist/shims/error.js +1 -1
- package/dist/shims/fetch-cache.d.ts +3 -1
- package/dist/shims/fetch-cache.js +23 -4
- package/dist/shims/internal/app-route-prefetch-policy.d.ts +6 -7
- package/dist/shims/internal/app-route-prefetch-policy.js +5 -4
- package/dist/shims/link.js +1 -1
- package/dist/shims/navigation.d.ts +12 -3
- package/dist/shims/navigation.js +46 -11
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/router.js +75 -4
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/utils/built-asset-url.d.ts +1 -1
- package/dist/utils/built-asset-url.js +4 -2
- package/dist/utils/package-name.d.ts +11 -0
- package/dist/utils/package-name.js +18 -0
- package/dist/utils/path.d.ts +8 -1
- package/dist/utils/path.js +21 -1
- package/dist/utils/react-compiler-support.d.ts +20 -0
- package/dist/utils/react-compiler-support.js +29 -0
- package/package.json +3 -2
package/dist/shims/dynamic.js
CHANGED
|
@@ -114,15 +114,13 @@ function getDynamicErrorBoundary() {
|
|
|
114
114
|
return DynamicErrorBoundary;
|
|
115
115
|
}
|
|
116
116
|
const isServer = typeof window === "undefined";
|
|
117
|
-
const preloadQueue = [];
|
|
118
117
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
118
|
+
* Retained for the Pages Router render pipeline, which calls this before
|
|
119
|
+
* rendering. Dynamic imports now use React.lazy + Suspense, so there is no
|
|
120
|
+
* separate preload work to await.
|
|
122
121
|
*/
|
|
123
122
|
function flushPreloads() {
|
|
124
|
-
|
|
125
|
-
return Promise.all(pending);
|
|
123
|
+
return Promise.resolve([]);
|
|
126
124
|
}
|
|
127
125
|
function dynamic(dynamicInput, options) {
|
|
128
126
|
const normalizedOptions = normalizeDynamicOptions(dynamicInput, options);
|
package/dist/shims/error.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AppRouterContext } from "./internal/app-router-context.js";
|
|
2
2
|
import { RouterContext } from "./internal/router-context.js";
|
|
3
3
|
import { isNextRouterError } from "./navigation-errors.js";
|
|
4
|
-
import "./navigation.js";
|
|
5
4
|
import Head from "./head.js";
|
|
5
|
+
import "./navigation.js";
|
|
6
6
|
import { useUntrackedPathname } from "./internal/navigation-untracked.js";
|
|
7
7
|
import React from "react";
|
|
8
8
|
//#region src/shims/error.tsx
|
|
@@ -40,6 +40,7 @@ type FetchCacheState = {
|
|
|
40
40
|
currentRequestTags: string[];
|
|
41
41
|
currentFetchSoftTags: string[];
|
|
42
42
|
currentFetchCacheMode: FetchCacheMode | null;
|
|
43
|
+
currentFetchRevalidate: number | null;
|
|
43
44
|
currentForceDynamicFetchDefault: boolean;
|
|
44
45
|
dynamicFetchUrls: Set<string>;
|
|
45
46
|
refreshStaleFetchesInForeground: boolean;
|
|
@@ -86,6 +87,7 @@ declare function setCurrentFetchSoftTags(tags: string[]): void;
|
|
|
86
87
|
*/
|
|
87
88
|
declare function getCurrentFetchSoftTags(): string[];
|
|
88
89
|
declare function setCurrentFetchCacheMode(mode: FetchCacheMode | null): void;
|
|
90
|
+
declare function setCurrentFetchRevalidate(revalidate: number | null): void;
|
|
89
91
|
declare function setCurrentForceDynamicFetchDefault(enabled: boolean): void;
|
|
90
92
|
declare function setRefreshStaleFetchesInForeground(enabled: boolean): void;
|
|
91
93
|
/**
|
|
@@ -135,4 +137,4 @@ declare function ensureFetchPatch(): void;
|
|
|
135
137
|
*/
|
|
136
138
|
declare function getOriginalFetch(): typeof globalThis.fetch;
|
|
137
139
|
//#endregion
|
|
138
|
-
export { FetchCacheMode, FetchCacheState, _resetPendingRefetches, addCollectedRequestTags, consumeDynamicFetchObservations, ensureFetchPatch, getCollectedFetchTags, getCurrentFetchSoftTags, getOriginalFetch, peekCacheableFetchObservations, peekDynamicFetchObservations, runWithFetchCache, runWithFetchDedupe, setCurrentFetchCacheMode, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault, setRefreshStaleFetchesInForeground, withFetchCache };
|
|
140
|
+
export { FetchCacheMode, FetchCacheState, _resetPendingRefetches, addCollectedRequestTags, consumeDynamicFetchObservations, ensureFetchPatch, getCollectedFetchTags, getCurrentFetchSoftTags, getOriginalFetch, peekCacheableFetchObservations, peekDynamicFetchObservations, runWithFetchCache, runWithFetchDedupe, setCurrentFetchCacheMode, setCurrentFetchRevalidate, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault, setRefreshStaleFetchesInForeground, withFetchCache };
|
|
@@ -3,7 +3,7 @@ import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation }
|
|
|
3
3
|
import { getRequestExecutionContext } from "./request-context.js";
|
|
4
4
|
import { getDataCacheHandler } from "./cache-handler.js";
|
|
5
5
|
import { encodeCacheTags } from "../utils/encode-cache-tag.js";
|
|
6
|
-
import { markDynamicUsage } from "./headers.js";
|
|
6
|
+
import { getHeadersContext, markDynamicUsage } from "./headers.js";
|
|
7
7
|
import { _hasPendingRevalidatedTag, _setRequestScopedCacheLife } from "./cache-request-state.js";
|
|
8
8
|
import { Buffer } from "node:buffer";
|
|
9
9
|
//#region src/shims/fetch-cache.ts
|
|
@@ -345,6 +345,7 @@ const _fallbackState = _g[_FALLBACK_KEY] ??= {
|
|
|
345
345
|
currentRequestTags: [],
|
|
346
346
|
currentFetchSoftTags: [],
|
|
347
347
|
currentFetchCacheMode: null,
|
|
348
|
+
currentFetchRevalidate: null,
|
|
348
349
|
currentForceDynamicFetchDefault: false,
|
|
349
350
|
dynamicFetchUrls: /* @__PURE__ */ new Set(),
|
|
350
351
|
refreshStaleFetchesInForeground: false,
|
|
@@ -364,6 +365,7 @@ function _resetFallbackState(isFetchDedupeActive) {
|
|
|
364
365
|
_fallbackState.currentRequestTags = [];
|
|
365
366
|
_fallbackState.currentFetchSoftTags = [];
|
|
366
367
|
_fallbackState.currentFetchCacheMode = null;
|
|
368
|
+
_fallbackState.currentFetchRevalidate = null;
|
|
367
369
|
_fallbackState.currentForceDynamicFetchDefault = false;
|
|
368
370
|
_fallbackState.dynamicFetchUrls = /* @__PURE__ */ new Set();
|
|
369
371
|
_fallbackState.refreshStaleFetchesInForeground = false;
|
|
@@ -378,6 +380,7 @@ function recordDynamicFetchObservation(input) {
|
|
|
378
380
|
}
|
|
379
381
|
function markUncachedFetchForPageOutput(input) {
|
|
380
382
|
recordDynamicFetchObservation(input);
|
|
383
|
+
if (getHeadersContext()?.forceStatic !== true) _getState().currentFetchRevalidate = 0;
|
|
381
384
|
markDynamicUsage();
|
|
382
385
|
}
|
|
383
386
|
function recordCacheableFetchObservation(input) {
|
|
@@ -386,6 +389,10 @@ function recordCacheableFetchObservation(input) {
|
|
|
386
389
|
function recordFiniteFetchRevalidate(revalidateSeconds) {
|
|
387
390
|
if (Number.isFinite(revalidateSeconds) && revalidateSeconds > 0) _setRequestScopedCacheLife({ revalidate: revalidateSeconds });
|
|
388
391
|
}
|
|
392
|
+
function lowerCurrentFetchRevalidate(revalidateSeconds) {
|
|
393
|
+
const state = _getState();
|
|
394
|
+
if (state.currentFetchRevalidate === null || revalidateSeconds < state.currentFetchRevalidate) state.currentFetchRevalidate = revalidateSeconds;
|
|
395
|
+
}
|
|
389
396
|
function shouldRefreshStaleFetchInForeground() {
|
|
390
397
|
return _getState().refreshStaleFetchesInForeground;
|
|
391
398
|
}
|
|
@@ -493,6 +500,9 @@ function getCurrentFetchSoftTags() {
|
|
|
493
500
|
function setCurrentFetchCacheMode(mode) {
|
|
494
501
|
_getState().currentFetchCacheMode = mode;
|
|
495
502
|
}
|
|
503
|
+
function setCurrentFetchRevalidate(revalidate) {
|
|
504
|
+
_getState().currentFetchRevalidate = revalidate;
|
|
505
|
+
}
|
|
496
506
|
function setCurrentForceDynamicFetchDefault(enabled) {
|
|
497
507
|
_getState().currentForceDynamicFetchDefault = enabled;
|
|
498
508
|
}
|
|
@@ -661,13 +671,21 @@ function createPatchedFetch() {
|
|
|
661
671
|
if (cacheDirective === "force-cache") revalidateSeconds = nextOpts?.revalidate && typeof nextOpts.revalidate === "number" ? nextOpts.revalidate : ONE_YEAR_SECONDS;
|
|
662
672
|
else if (nextOpts?.revalidate === false) revalidateSeconds = ONE_YEAR_SECONDS;
|
|
663
673
|
else if (typeof nextOpts?.revalidate === "number" && nextOpts.revalidate > 0) revalidateSeconds = nextOpts.revalidate;
|
|
664
|
-
else if (nextOpts?.tags && nextOpts.tags.length > 0)
|
|
665
|
-
|
|
674
|
+
else if (nextOpts?.tags && nextOpts.tags.length > 0) {
|
|
675
|
+
const routeRevalidate = _getState().currentFetchRevalidate;
|
|
676
|
+
if (routeRevalidate === 0) {
|
|
677
|
+
const cleanInit = stripNextFromInit(init, cacheDirective);
|
|
678
|
+
markUncachedFetchForPageOutput(input);
|
|
679
|
+
return dedupeFetch(input, cleanInit);
|
|
680
|
+
}
|
|
681
|
+
revalidateSeconds = routeRevalidate === null || routeRevalidate === Infinity ? ONE_YEAR_SECONDS : routeRevalidate;
|
|
682
|
+
} else {
|
|
666
683
|
const cleanInit = stripNextFromInit(init, cacheDirective);
|
|
667
684
|
recordDynamicFetchObservation(input);
|
|
668
685
|
return dedupeFetch(input, cleanInit);
|
|
669
686
|
}
|
|
670
687
|
recordCacheableFetchObservation(input);
|
|
688
|
+
if (typeof nextOpts?.revalidate === "number" && nextOpts.revalidate > 0) lowerCurrentFetchRevalidate(nextOpts.revalidate);
|
|
671
689
|
recordFiniteFetchRevalidate(revalidateSeconds);
|
|
672
690
|
const reqTags = _getState().currentRequestTags;
|
|
673
691
|
const tags = encodeCacheTags(nextOpts?.tags ?? []);
|
|
@@ -807,6 +825,7 @@ async function runWithFetchCache(fn) {
|
|
|
807
825
|
currentRequestTags: [],
|
|
808
826
|
currentFetchSoftTags: [],
|
|
809
827
|
currentFetchCacheMode: null,
|
|
828
|
+
currentFetchRevalidate: null,
|
|
810
829
|
currentForceDynamicFetchDefault: false,
|
|
811
830
|
dynamicFetchUrls: /* @__PURE__ */ new Set(),
|
|
812
831
|
refreshStaleFetchesInForeground: false,
|
|
@@ -847,4 +866,4 @@ function getOriginalFetch() {
|
|
|
847
866
|
return originalFetch;
|
|
848
867
|
}
|
|
849
868
|
//#endregion
|
|
850
|
-
export { _resetPendingRefetches, addCollectedRequestTags, consumeDynamicFetchObservations, ensureFetchPatch, getCollectedFetchTags, getCurrentFetchSoftTags, getOriginalFetch, peekCacheableFetchObservations, peekDynamicFetchObservations, runWithFetchCache, runWithFetchDedupe, setCurrentFetchCacheMode, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault, setRefreshStaleFetchesInForeground, withFetchCache };
|
|
869
|
+
export { _resetPendingRefetches, addCollectedRequestTags, consumeDynamicFetchObservations, ensureFetchPatch, getCollectedFetchTags, getCurrentFetchSoftTags, getOriginalFetch, peekCacheableFetchObservations, peekDynamicFetchObservations, runWithFetchCache, runWithFetchDedupe, setCurrentFetchCacheMode, setCurrentFetchRevalidate, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault, setRefreshStaleFetchesInForeground, withFetchCache };
|
|
@@ -12,15 +12,14 @@ declare global {
|
|
|
12
12
|
*/
|
|
13
13
|
type AppRoutePrefetchPolicy = {
|
|
14
14
|
cacheForNavigation: boolean;
|
|
15
|
-
fallbackTtl: "dynamic" | "static";
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* between `auto` and `full` in `getPrefetchEntryCacheStatus`.
|
|
16
|
+
* How the dynamic stale-time signal affects this prefetch. Navigation data
|
|
17
|
+
* takes it verbatim, explicit full prefetches fall back to the static window
|
|
18
|
+
* only when it is zero, and loading shells ignore it because their contents
|
|
19
|
+
* are static.
|
|
22
20
|
*/
|
|
23
|
-
|
|
21
|
+
dynamicStaleTime: "verbatim" | "full-prefetch" | "ignore";
|
|
22
|
+
fallbackTtl: "dynamic" | "static";
|
|
24
23
|
prefetchShellFirst: boolean;
|
|
25
24
|
/** Fetch the route tree before the concrete page segment. */
|
|
26
25
|
requiresRouteTreePrefetch?: true;
|
|
@@ -19,8 +19,8 @@ function toSameOriginRouteHref(href) {
|
|
|
19
19
|
/** Href the manifest does not cover: no request, nothing reusable. */
|
|
20
20
|
const NO_APP_ROUTE_PREFETCH = {
|
|
21
21
|
cacheForNavigation: false,
|
|
22
|
+
dynamicStaleTime: "verbatim",
|
|
22
23
|
fallbackTtl: "static",
|
|
23
|
-
honorDynamicStaleTime: true,
|
|
24
24
|
prefetchShellFirst: false,
|
|
25
25
|
shouldPrefetch: false
|
|
26
26
|
};
|
|
@@ -41,10 +41,11 @@ function resolveAutoAppRoutePrefetch(href) {
|
|
|
41
41
|
const hasSearchParams = routeUrl.search !== "";
|
|
42
42
|
const isFullyDynamicRootRoute = route.patternParts.length === 1 && route.patternParts[0]?.startsWith(":");
|
|
43
43
|
const hasCacheComponentsLearningOnlyDynamicPath = route.isDynamic && String(process.env.__NEXT_CACHE_COMPONENTS) === "true" && (ENCODED_PATH_DELIMITER_RE.test(routeUrl.pathname) || isFullyDynamicRootRoute && !requiresRouteTreePrefetch);
|
|
44
|
+
const cacheForNavigation = !hasSearchParams && !hasCacheComponentsLearningOnlyDynamicPath && (requiresRouteTreePrefetch || !route.canPrefetchLoadingShell && route.requiresDynamicNavigationRequest !== true);
|
|
44
45
|
return {
|
|
45
|
-
cacheForNavigation
|
|
46
|
+
cacheForNavigation,
|
|
47
|
+
dynamicStaleTime: cacheForNavigation ? "verbatim" : "ignore",
|
|
46
48
|
fallbackTtl: "static",
|
|
47
|
-
honorDynamicStaleTime: true,
|
|
48
49
|
prefetchShellFirst: requiresRouteTreePrefetch || hasSearchParams || !route.isDynamic,
|
|
49
50
|
...requiresRouteTreePrefetch ? { requiresRouteTreePrefetch: true } : {},
|
|
50
51
|
shouldPrefetch: true
|
|
@@ -53,8 +54,8 @@ function resolveAutoAppRoutePrefetch(href) {
|
|
|
53
54
|
function resolveFullAppRoutePrefetch() {
|
|
54
55
|
return {
|
|
55
56
|
cacheForNavigation: true,
|
|
57
|
+
dynamicStaleTime: "full-prefetch",
|
|
56
58
|
fallbackTtl: "static",
|
|
57
|
-
honorDynamicStaleTime: false,
|
|
58
59
|
prefetchShellFirst: true,
|
|
59
60
|
shouldPrefetch: true
|
|
60
61
|
};
|
package/dist/shims/link.js
CHANGED
|
@@ -318,7 +318,7 @@ function prefetchUrl(href, mode, priority = "low", pagesRouteHref, locale) {
|
|
|
318
318
|
prefetchRscResponse(rscUrl, fetchPromise, interceptionContext, mountedSlotsHeader, void 0, {
|
|
319
319
|
cacheForNavigation: autoPrefetch.cacheForNavigation,
|
|
320
320
|
fallbackTtlMs: autoPrefetch.fallbackTtl === "dynamic" ? DYNAMIC_NAVIGATION_CACHE_TTL : PREFETCH_CACHE_TTL,
|
|
321
|
-
|
|
321
|
+
dynamicStaleTime: autoPrefetch.dynamicStaleTime,
|
|
322
322
|
optimisticRouteShell: isOptimisticRouteShellPrefetch,
|
|
323
323
|
prefetchKind: isOptimisticRouteShellPrefetch ? "loading-shell" : "navigation",
|
|
324
324
|
prepareSnapshot: autoPrefetch.cacheForNavigation ? prepareNavigationPrefetchSnapshot : void 0,
|
|
@@ -73,6 +73,7 @@ type PrefetchCacheEntry = {
|
|
|
73
73
|
pending?: Promise<void>;
|
|
74
74
|
preparedElements?: AppElements;
|
|
75
75
|
prefetchKind?: PrefetchCacheKind;
|
|
76
|
+
reuseAfterHistoryRestore?: boolean;
|
|
76
77
|
searchAgnosticShell?: boolean;
|
|
77
78
|
size?: number;
|
|
78
79
|
timestamp: number;
|
|
@@ -118,7 +119,14 @@ declare function hasFreshLearningOnlyPrefetchCacheEntry(rscUrl: string, intercep
|
|
|
118
119
|
declare function hasSearchAgnosticPrefetchShellForRoute(rscUrl: string, interceptionContext?: string | null, mountedSlotsHeader?: string | null): boolean;
|
|
119
120
|
declare function discardLearningOnlyPrefetchCacheEntry(rscUrl: string, interceptionContext?: string | null): boolean;
|
|
120
121
|
declare function invalidatePrefetchCache(): void;
|
|
121
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Prevent completed navigation responses from becoming authoritative again
|
|
124
|
+
* after restoring a history snapshot. Explicit Link/router prefetches remain
|
|
125
|
+
* consumable. Responses with a positive cache lifetime and interception
|
|
126
|
+
* responses retain the cache reuse licensed by Next's segment cache.
|
|
127
|
+
*/
|
|
128
|
+
declare function disableNavigationResponsePrefetchCacheReuse(): void;
|
|
129
|
+
declare function seedPrefetchResponseSnapshot(rscUrl: string, snapshot: CachedRscResponse, interceptionContext?: string | null, mountedSlotsHeader?: string | null, fallbackTtlMs?: number, reuseAfterHistoryRestore?: boolean): void;
|
|
122
130
|
declare function deletePrefetchResponseSnapshot(rscUrl: string, snapshot: CachedRscResponse, interceptionContext?: string | null): void;
|
|
123
131
|
/**
|
|
124
132
|
* Store a prefetched RSC response in the cache by snapshotting it to an
|
|
@@ -189,8 +197,8 @@ declare function fetchRouteTreeGatedPrefetch(options: {
|
|
|
189
197
|
*/
|
|
190
198
|
declare function prefetchRscResponse(rscUrl: string, fetchPromise: Promise<Response>, interceptionContext?: string | null, mountedSlotsHeader?: string | null, options?: PrefetchOptions, behavior?: {
|
|
191
199
|
cacheForNavigation?: boolean;
|
|
200
|
+
dynamicStaleTime?: "verbatim" | "full-prefetch" | "ignore";
|
|
192
201
|
fallbackTtlMs?: number;
|
|
193
|
-
honorDynamicStaleTime?: boolean;
|
|
194
202
|
optimisticRouteShell?: boolean;
|
|
195
203
|
prefetchKind?: PrefetchCacheKind;
|
|
196
204
|
prepareSnapshot?: (snapshot: CachedRscResponse) => Promise<AppElements>;
|
|
@@ -254,6 +262,7 @@ declare function getClientNavigationState(): ClientNavigationState | null;
|
|
|
254
262
|
declare function activateNavigationSnapshot(): void;
|
|
255
263
|
type ClientNavigationRenderSnapshot = {
|
|
256
264
|
pathname: string;
|
|
265
|
+
search: string;
|
|
257
266
|
searchParams: ReadonlyURLSearchParams;
|
|
258
267
|
params: Record<string, string | string[]>;
|
|
259
268
|
};
|
|
@@ -378,4 +387,4 @@ declare function useSelectedLayoutSegments(parallelRoutesKey?: string): string[]
|
|
|
378
387
|
*/
|
|
379
388
|
declare function useServerInsertedHTML(callback: () => unknown): void;
|
|
380
389
|
//#endregion
|
|
381
|
-
export { BailoutToCSRError, CachedRscResponse, ClientNavigationRenderSnapshot, DYNAMIC_NAVIGATION_CACHE_TTL, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, type NavigationContext, type NavigationStateAccessors, PREFETCH_CACHE_TTL, PrefetchCacheEntry, PrefetchCacheKind, PrefetchOptions, ReadonlyURLSearchParams, RedirectType, type SegmentMap, ServerInsertedHTMLContext, ServerStaleTime, UnrecognizedActionError, __basePath, _registerStateAccessors, activateNavigationSnapshot, appRouterInstance, applyAppRouterScrollFallback, clearPendingPathname, clearServerInsertedHTML, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createAppPrefetchRequestHeaders, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, decodeRedirectError, deletePrefetchResponseSnapshot, discardLearningOnlyPrefetchCacheEntry, fetchRouteTreeGatedPrefetch, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getClientNavigationRenderContext, getClientNavigationState, getClientParams, getCurrentInterceptionContext, getCurrentNextUrl, getFreshPrefetchCacheEntry, getLayoutSegmentContext, getMountedSlotsHeader, getNavigationContext, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasFreshLearningOnlyPrefetchCacheEntry, hasPrefetchCacheEntryForNavigation, hasSearchAgnosticPrefetchShellForRoute, invalidatePrefetchCache, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, navigateClientSide, notFound, peekPrefetchResponseForNavigation, permanentRedirect, prefetchRscResponse, preloadHybridClientRouteOwner, prepareNavigationPrefetchSnapshot, pushHistoryStateWithoutNotify, redirect, renderServerInsertedHTML, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveCachedRscResponseExpiresAt, resolveCachedRscResponseTtlMs, resolveLoadedHybridClientRewriteHref, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, seedPrefetchResponseSnapshot, setClientParams, setMountedSlotsHeader, setNavigationContext, setPendingPathname, snapshotRscResponse, storePrefetchResponse, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useClientNavigationRenderSnapshot, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
|
|
390
|
+
export { BailoutToCSRError, CachedRscResponse, ClientNavigationRenderSnapshot, DYNAMIC_NAVIGATION_CACHE_TTL, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, type NavigationContext, type NavigationStateAccessors, PREFETCH_CACHE_TTL, PrefetchCacheEntry, PrefetchCacheKind, PrefetchOptions, ReadonlyURLSearchParams, RedirectType, type SegmentMap, ServerInsertedHTMLContext, ServerStaleTime, UnrecognizedActionError, __basePath, _registerStateAccessors, activateNavigationSnapshot, appRouterInstance, applyAppRouterScrollFallback, clearPendingPathname, clearServerInsertedHTML, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createAppPrefetchRequestHeaders, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, decodeRedirectError, deletePrefetchResponseSnapshot, disableNavigationResponsePrefetchCacheReuse, discardLearningOnlyPrefetchCacheEntry, fetchRouteTreeGatedPrefetch, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getClientNavigationRenderContext, getClientNavigationState, getClientParams, getCurrentInterceptionContext, getCurrentNextUrl, getFreshPrefetchCacheEntry, getLayoutSegmentContext, getMountedSlotsHeader, getNavigationContext, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasFreshLearningOnlyPrefetchCacheEntry, hasPrefetchCacheEntryForNavigation, hasSearchAgnosticPrefetchShellForRoute, invalidatePrefetchCache, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, navigateClientSide, notFound, peekPrefetchResponseForNavigation, permanentRedirect, prefetchRscResponse, preloadHybridClientRouteOwner, prepareNavigationPrefetchSnapshot, pushHistoryStateWithoutNotify, redirect, renderServerInsertedHTML, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveCachedRscResponseExpiresAt, resolveCachedRscResponseTtlMs, resolveLoadedHybridClientRewriteHref, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, seedPrefetchResponseSnapshot, setClientParams, setMountedSlotsHeader, setNavigationContext, setPendingPathname, snapshotRscResponse, storePrefetchResponse, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useClientNavigationRenderSnapshot, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
|
package/dist/shims/navigation.js
CHANGED
|
@@ -18,8 +18,8 @@ import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, createRscRequestHeaders, createRscR
|
|
|
18
18
|
import { getNavigationRuntime, hasAppNavigationRuntime } from "../client/navigation-runtime.js";
|
|
19
19
|
import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
|
|
20
20
|
import { PUBLIC_INITIAL_BFCACHE_ID } from "../server/app-bfcache-id.js";
|
|
21
|
-
import { createExternalHistoryStatePreservingMetadata, createHashOnlyHistoryStatePreservingNavigationMetadata } from "../server/app-history-state.js";
|
|
22
21
|
import { resolveManifestNavigationInterceptionContext } from "../server/app-browser-interception-context.js";
|
|
22
|
+
import { createExternalHistoryStatePreservingMetadata, createHashOnlyHistoryStatePreservingNavigationMetadata, isAppOwnedHistoryState } from "../server/app-history-state.js";
|
|
23
23
|
import { hasPendingAppRouterPageRedirect } from "../server/app-browser-mpa-navigation.js";
|
|
24
24
|
import { extractRscCompletionMetadata } from "../server/rsc-completion-metadata.js";
|
|
25
25
|
import { navigationPlanner } from "../server/navigation-planner.js";
|
|
@@ -211,13 +211,14 @@ function resolveCachedRscResponseExpiresAt(timestamp, cached, fallbackTtlMs) {
|
|
|
211
211
|
if (isCacheExpiresAt(cached.expiresAt)) return cached.expiresAt;
|
|
212
212
|
return timestamp + resolveCachedRscResponseTtlMs(cached, fallbackTtlMs);
|
|
213
213
|
}
|
|
214
|
-
function resolvePrefetchedRscResponseExpiresAt(timestamp, cached, fallbackTtlMs,
|
|
214
|
+
function resolvePrefetchedRscResponseExpiresAt(timestamp, cached, fallbackTtlMs, dynamicStaleTime) {
|
|
215
215
|
if (isCacheExpiresAt(cached.expiresAt)) return cached.expiresAt;
|
|
216
|
-
const serverSeconds = cached.serverStaleTime?.kind === "pending" &&
|
|
216
|
+
const serverSeconds = cached.serverStaleTime?.kind === "pending" && dynamicStaleTime !== "verbatim" ? void 0 : serverStaleTimeSeconds(cached.serverStaleTime);
|
|
217
217
|
if (serverSeconds !== void 0) return timestamp + serverSeconds * 1e3;
|
|
218
|
+
if (dynamicStaleTime === "ignore") return timestamp + Math.max(fallbackTtlMs, MIN_PREFETCH_STALE_TIME_MS);
|
|
218
219
|
const seconds = isStaleTimeSeconds(cached.dynamicStaleTimeSeconds) ? cached.dynamicStaleTimeSeconds : void 0;
|
|
219
220
|
if (seconds === void 0) return timestamp + Math.max(fallbackTtlMs, MIN_PREFETCH_STALE_TIME_MS);
|
|
220
|
-
return
|
|
221
|
+
return dynamicStaleTime === "verbatim" ? timestamp + seconds * 1e3 : timestamp + (seconds === 0 ? Math.max(fallbackTtlMs, MIN_PREFETCH_STALE_TIME_MS) : Math.max(seconds * 1e3, MIN_PREFETCH_STALE_TIME_MS));
|
|
221
222
|
}
|
|
222
223
|
function resolvePrefetchCacheEntryExpiresAt(entry) {
|
|
223
224
|
if (entry.expiresAt !== void 0) return entry.expiresAt;
|
|
@@ -551,7 +552,21 @@ function invalidatePrefetchCache() {
|
|
|
551
552
|
for (const retained of retainedPrefetchInvalidations) fireRetainedPrefetchInvalidation(retained);
|
|
552
553
|
if (!isServer) getNavigationRuntime()?.functions.pingVisibleLinks?.();
|
|
553
554
|
}
|
|
554
|
-
|
|
555
|
+
/**
|
|
556
|
+
* Prevent completed navigation responses from becoming authoritative again
|
|
557
|
+
* after restoring a history snapshot. Explicit Link/router prefetches remain
|
|
558
|
+
* consumable. Responses with a positive cache lifetime and interception
|
|
559
|
+
* responses retain the cache reuse licensed by Next's segment cache.
|
|
560
|
+
*/
|
|
561
|
+
function disableNavigationResponsePrefetchCacheReuse() {
|
|
562
|
+
let didDemote = false;
|
|
563
|
+
for (const entry of new Set(getPrefetchCache().values())) if (entry.prefetchKind === void 0 && entry.reuseAfterHistoryRestore !== true) {
|
|
564
|
+
didDemote ||= entry.cacheForNavigation !== false;
|
|
565
|
+
entry.cacheForNavigation = false;
|
|
566
|
+
}
|
|
567
|
+
if (didDemote && !isServer) getNavigationRuntime()?.functions.pingVisibleLinks?.();
|
|
568
|
+
}
|
|
569
|
+
function seedPrefetchResponseSnapshot(rscUrl, snapshot, interceptionContext = null, mountedSlotsHeader = null, fallbackTtlMs = DYNAMIC_NAVIGATION_CACHE_TTL, reuseAfterHistoryRestore = false) {
|
|
555
570
|
const cacheKey = AppElementsWire.encodeCacheKey(rscUrl, interceptionContext);
|
|
556
571
|
const cache = getPrefetchCache();
|
|
557
572
|
const existing = cache.get(cacheKey);
|
|
@@ -563,6 +578,7 @@ function seedPrefetchResponseSnapshot(rscUrl, snapshot, interceptionContext = nu
|
|
|
563
578
|
expiresAt: resolveCachedRscResponseExpiresAt(timestamp, snapshot, fallbackTtlMs),
|
|
564
579
|
mountedSlotsHeader,
|
|
565
580
|
outcome: "cache-seeded",
|
|
581
|
+
reuseAfterHistoryRestore,
|
|
566
582
|
size: snapshot.buffer.byteLength,
|
|
567
583
|
snapshot,
|
|
568
584
|
timestamp
|
|
@@ -802,7 +818,7 @@ function prefetchRscResponse(rscUrl, fetchPromise, interceptionContext = null, m
|
|
|
802
818
|
entry.snapshot = snapshot;
|
|
803
819
|
entry.size = snapshot.buffer.byteLength;
|
|
804
820
|
adjustPrefetchCacheByteSize(cache, entry.size - previousSize);
|
|
805
|
-
entry.expiresAt = resolvePrefetchedRscResponseExpiresAt(entry.timestamp, entry.snapshot, behavior.fallbackTtlMs ?? PREFETCH_CACHE_TTL, behavior.
|
|
821
|
+
entry.expiresAt = resolvePrefetchedRscResponseExpiresAt(entry.timestamp, entry.snapshot, behavior.fallbackTtlMs ?? PREFETCH_CACHE_TTL, behavior.searchAgnosticShell === true ? "ignore" : behavior.dynamicStaleTime ?? (behavior.optimisticRouteShell === true ? "ignore" : "verbatim"));
|
|
806
822
|
if (behavior.prepareSnapshot) try {
|
|
807
823
|
const preparedElements = await behavior.prepareSnapshot(snapshot);
|
|
808
824
|
if (cache.get(cacheKey) !== entry) return;
|
|
@@ -1076,13 +1092,13 @@ function createClientNavigationRenderSnapshot(href, params) {
|
|
|
1076
1092
|
const url = new URL(href, origin);
|
|
1077
1093
|
return {
|
|
1078
1094
|
pathname: stripBasePath(url.pathname, __basePath),
|
|
1095
|
+
search: url.search,
|
|
1079
1096
|
searchParams: new ReadonlyURLSearchParams(url.search),
|
|
1080
1097
|
params
|
|
1081
1098
|
};
|
|
1082
1099
|
}
|
|
1083
1100
|
function createSnapshotPathAndSearch(snapshot) {
|
|
1084
|
-
|
|
1085
|
-
return query === "" ? snapshot.pathname : `${snapshot.pathname}?${query}`;
|
|
1101
|
+
return snapshot.pathname + snapshot.search;
|
|
1086
1102
|
}
|
|
1087
1103
|
let _fallbackClientParams = _EMPTY_PARAMS;
|
|
1088
1104
|
let _fallbackClientParamsJson = "{}";
|
|
@@ -1411,6 +1427,7 @@ async function navigateClientSide(href, mode, scroll, programmaticTransition = f
|
|
|
1411
1427
|
if (mode === "push") saveScrollPosition();
|
|
1412
1428
|
const earlyIntent = navigationPlanner.classifyEarlyNavigationIntent({
|
|
1413
1429
|
basePath: __basePath,
|
|
1430
|
+
currentUrlSpace: "browser",
|
|
1414
1431
|
currentHref: window.location.href,
|
|
1415
1432
|
mode,
|
|
1416
1433
|
scroll,
|
|
@@ -1440,7 +1457,7 @@ async function navigateClientSide(href, mode, scroll, programmaticTransition = f
|
|
|
1440
1457
|
if (!scroll) clearAppRouterScrollIntent();
|
|
1441
1458
|
const appNavigate = getNavigationRuntime()?.functions.navigate;
|
|
1442
1459
|
try {
|
|
1443
|
-
if (appNavigate) await appNavigate(fullHref, 0, "navigate", mode, void 0, programmaticTransition, void 0, scrollIntent, visibleCommitMode);
|
|
1460
|
+
if (appNavigate) await appNavigate(fullHref, 0, "navigate", mode, void 0, programmaticTransition, void 0, scrollIntent, visibleCommitMode, earlyIntent.bypassNavigationCache);
|
|
1444
1461
|
else {
|
|
1445
1462
|
if (mode === "replace") replaceHistoryStateWithoutNotify(null, "", fullHref);
|
|
1446
1463
|
else pushHistoryStateWithoutNotify(null, "", fullHref);
|
|
@@ -1601,12 +1618,14 @@ const _appRouter = {
|
|
|
1601
1618
|
}) : fetchFullRscPayload(), interceptionContext, mountedSlotsHeader, options, reusable ? {
|
|
1602
1619
|
cacheForNavigation: true,
|
|
1603
1620
|
fallbackTtlMs: policy.fallbackTtl === "dynamic" ? DYNAMIC_NAVIGATION_CACHE_TTL : PREFETCH_CACHE_TTL,
|
|
1604
|
-
|
|
1621
|
+
dynamicStaleTime: policy.dynamicStaleTime,
|
|
1605
1622
|
optimisticRouteShell: false,
|
|
1606
1623
|
prefetchKind: "navigation",
|
|
1607
1624
|
prepareSnapshot: prepareNavigationPrefetchSnapshot
|
|
1608
1625
|
} : {
|
|
1609
1626
|
cacheForNavigation: false,
|
|
1627
|
+
fallbackTtlMs: policy.fallbackTtl === "dynamic" ? DYNAMIC_NAVIGATION_CACHE_TTL : PREFETCH_CACHE_TTL,
|
|
1628
|
+
dynamicStaleTime: policy.dynamicStaleTime,
|
|
1610
1629
|
optimisticRouteShell: true,
|
|
1611
1630
|
prefetchKind: "navigation"
|
|
1612
1631
|
});
|
|
@@ -1734,14 +1753,30 @@ if (!isServer) {
|
|
|
1734
1753
|
}
|
|
1735
1754
|
});
|
|
1736
1755
|
window.history.pushState = function patchedPushState(data, unused, url) {
|
|
1756
|
+
if (isAppOwnedHistoryState(data)) {
|
|
1757
|
+
const previousHistoryState = window.history.state;
|
|
1758
|
+
state.originalPushState.call(window.history, data, unused, url);
|
|
1759
|
+
getNavigationRuntime()?.functions.commitAppOwnedHistoryStateWrite?.("push", previousHistoryState);
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
const previousHistoryState = window.history.state;
|
|
1737
1763
|
state.originalPushState.call(window.history, createExternalHistoryStatePreservingMetadata(data, window.history.state), unused, url);
|
|
1764
|
+
getNavigationRuntime()?.functions.claimCurrentHistoryTreeSnapshot?.("push", previousHistoryState);
|
|
1738
1765
|
if (state.suppressUrlNotifyCount === 0) {
|
|
1739
1766
|
resetStaleLinkStatus();
|
|
1740
1767
|
commitClientNavigationState();
|
|
1741
1768
|
}
|
|
1742
1769
|
};
|
|
1743
1770
|
window.history.replaceState = function patchedReplaceState(data, unused, url) {
|
|
1771
|
+
if (isAppOwnedHistoryState(data)) {
|
|
1772
|
+
const previousHistoryState = window.history.state;
|
|
1773
|
+
state.originalReplaceState.call(window.history, data, unused, url);
|
|
1774
|
+
getNavigationRuntime()?.functions.commitAppOwnedHistoryStateWrite?.("replace", previousHistoryState);
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
const previousHistoryState = window.history.state;
|
|
1744
1778
|
state.originalReplaceState.call(window.history, createExternalHistoryStatePreservingMetadata(data, window.history.state), unused, url);
|
|
1779
|
+
getNavigationRuntime()?.functions.claimCurrentHistoryTreeSnapshot?.("replace", previousHistoryState);
|
|
1745
1780
|
if (state.suppressUrlNotifyCount === 0) {
|
|
1746
1781
|
resetStaleLinkStatus();
|
|
1747
1782
|
commitClientNavigationState();
|
|
@@ -1750,4 +1785,4 @@ if (!isServer) {
|
|
|
1750
1785
|
}
|
|
1751
1786
|
}
|
|
1752
1787
|
//#endregion
|
|
1753
|
-
export { BailoutToCSRError, DYNAMIC_NAVIGATION_CACHE_TTL, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, PREFETCH_CACHE_TTL, ReadonlyURLSearchParams, RedirectType, ServerInsertedHTMLContext, UnrecognizedActionError, __basePath, _registerStateAccessors, activateNavigationSnapshot, appRouterInstance, applyAppRouterScrollFallback, clearPendingPathname, clearServerInsertedHTML, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createAppPrefetchRequestHeaders, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, decodeRedirectError, deletePrefetchResponseSnapshot, discardLearningOnlyPrefetchCacheEntry, fetchRouteTreeGatedPrefetch, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getClientNavigationRenderContext, getClientNavigationState, getClientParams, getCurrentInterceptionContext, getCurrentNextUrl, getFreshPrefetchCacheEntry, getLayoutSegmentContext, getMountedSlotsHeader, getNavigationContext, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasFreshLearningOnlyPrefetchCacheEntry, hasPrefetchCacheEntryForNavigation, hasSearchAgnosticPrefetchShellForRoute, invalidatePrefetchCache, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, navigateClientSide, notFound, peekPrefetchResponseForNavigation, permanentRedirect, prefetchRscResponse, preloadHybridClientRouteOwner, prepareNavigationPrefetchSnapshot, pushHistoryStateWithoutNotify, redirect, renderServerInsertedHTML, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveCachedRscResponseExpiresAt, resolveCachedRscResponseTtlMs, resolveLoadedHybridClientRewriteHref, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, seedPrefetchResponseSnapshot, setClientParams, setMountedSlotsHeader, setNavigationContext, setPendingPathname, snapshotRscResponse, storePrefetchResponse, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useClientNavigationRenderSnapshot, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
|
|
1788
|
+
export { BailoutToCSRError, DYNAMIC_NAVIGATION_CACHE_TTL, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, PREFETCH_CACHE_TTL, ReadonlyURLSearchParams, RedirectType, ServerInsertedHTMLContext, UnrecognizedActionError, __basePath, _registerStateAccessors, activateNavigationSnapshot, appRouterInstance, applyAppRouterScrollFallback, clearPendingPathname, clearServerInsertedHTML, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createAppPrefetchRequestHeaders, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, decodeRedirectError, deletePrefetchResponseSnapshot, disableNavigationResponsePrefetchCacheReuse, discardLearningOnlyPrefetchCacheEntry, fetchRouteTreeGatedPrefetch, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getClientNavigationRenderContext, getClientNavigationState, getClientParams, getCurrentInterceptionContext, getCurrentNextUrl, getFreshPrefetchCacheEntry, getLayoutSegmentContext, getMountedSlotsHeader, getNavigationContext, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasFreshLearningOnlyPrefetchCacheEntry, hasPrefetchCacheEntryForNavigation, hasSearchAgnosticPrefetchShellForRoute, invalidatePrefetchCache, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, navigateClientSide, notFound, peekPrefetchResponseForNavigation, permanentRedirect, prefetchRscResponse, preloadHybridClientRouteOwner, prepareNavigationPrefetchSnapshot, pushHistoryStateWithoutNotify, redirect, renderServerInsertedHTML, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveCachedRscResponseExpiresAt, resolveCachedRscResponseTtlMs, resolveLoadedHybridClientRewriteHref, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, seedPrefetchResponseSnapshot, setClientParams, setMountedSlotsHeader, setNavigationContext, setPendingPathname, snapshotRscResponse, storePrefetchResponse, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useClientNavigationRenderSnapshot, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, getLayoutSegmentContext, getNavigationContext, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
2
2
|
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
3
3
|
import "./navigation-server.js";
|
|
4
|
-
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
5
4
|
import { throwClientHookError } from "./client-hook-error.js";
|
|
5
|
+
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
6
6
|
//#region src/shims/navigation.react-server.ts
|
|
7
7
|
function usePathname() {
|
|
8
8
|
throwClientHookError("usePathname()");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { ExecutionContextLike } from "./request-context.js";
|
|
1
2
|
import { NavigationContext } from "./navigation-context-state.js";
|
|
2
3
|
import "./navigation.js";
|
|
3
4
|
import { CacheLifeConfig, CacheState } from "./cache-request-state.js";
|
|
4
5
|
import { RootParamsState } from "./root-params.js";
|
|
5
|
-
import { ExecutionContextLike } from "./request-context.js";
|
|
6
6
|
import { FetchCacheState } from "./fetch-cache.js";
|
|
7
7
|
import { HeadersAccessPhase, HeadersContext, VinextHeadersShimState } from "./headers.js";
|
|
8
8
|
import { RouterState, SSRContext } from "./router-state.js";
|
package/dist/shims/router.js
CHANGED
|
@@ -1301,6 +1301,50 @@ async function navigateClientData(url, initialTarget, controller, navId, assertS
|
|
|
1301
1301
|
if (!redirectedUrl) scheduleHardNavigationAndThrow(softRedirect, "Navigation redirected externally");
|
|
1302
1302
|
throw new InternalNavigationRedirect(redirectedUrl);
|
|
1303
1303
|
}
|
|
1304
|
+
if (res.status === 404) {
|
|
1305
|
+
let isNotFound = false;
|
|
1306
|
+
try {
|
|
1307
|
+
const notFoundBody = await res.clone().json();
|
|
1308
|
+
isNotFound = isUnknownRecord(notFoundBody) && notFoundBody.notFound === true;
|
|
1309
|
+
} catch {}
|
|
1310
|
+
if (isNotFound) {
|
|
1311
|
+
if (!window.__VINEXT_PAGE_LOADERS__?.["/404"]) {
|
|
1312
|
+
const errorLoader = window.__VINEXT_PAGE_LOADERS__?.["/_error"];
|
|
1313
|
+
const errorTarget = {
|
|
1314
|
+
...initialTarget,
|
|
1315
|
+
pattern: "/_error",
|
|
1316
|
+
pagePath: "/_error",
|
|
1317
|
+
dataKind: "none",
|
|
1318
|
+
loader: errorLoader ?? (() => import("next/error"))
|
|
1319
|
+
};
|
|
1320
|
+
const pageModule = await loadTargetPageModule(errorTarget, url, "Data navigation failed");
|
|
1321
|
+
assertStillCurrent();
|
|
1322
|
+
const PageComponent = pageModule.default;
|
|
1323
|
+
if (!isPageComponent(PageComponent)) scheduleHardNavigationAndThrow(url, "Data navigation failed: error page default export is not a component");
|
|
1324
|
+
const appComponent = await loadPagesAppComponent();
|
|
1325
|
+
assertStillCurrent();
|
|
1326
|
+
const props = await loadComponentOnlyProps(PageComponent, appComponent, errorTarget, url);
|
|
1327
|
+
assertStillCurrent();
|
|
1328
|
+
await renderPagesNavigationTarget(url, initialTarget, props, options, assertStillCurrent, {
|
|
1329
|
+
appComponent,
|
|
1330
|
+
pageModule
|
|
1331
|
+
});
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
const notFoundFetchUrl = resolvePagesErrorHtmlFetchUrl("/404", initialTarget.locale);
|
|
1335
|
+
if (!notFoundFetchUrl) scheduleHardNavigationAndThrow(url, "Data navigation failed: no 404 route available");
|
|
1336
|
+
const requestedQuery = mergeRouteParamsIntoQuery(parseQueryString(initialTarget.search), initialTarget.params);
|
|
1337
|
+
await navigateClientHtml(url, notFoundFetchUrl, controller, navId, assertStillCurrent, {
|
|
1338
|
+
...options,
|
|
1339
|
+
allowNotFoundResponse: true,
|
|
1340
|
+
nextDataRouteState: {
|
|
1341
|
+
page: initialTarget.pattern,
|
|
1342
|
+
query: requestedQuery
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1304
1348
|
if (!res.ok) {
|
|
1305
1349
|
if (options.isHydrationQueryUpdate) return;
|
|
1306
1350
|
scheduleHardNavigationAndThrow(url, "Failed to load static props");
|
|
@@ -1356,12 +1400,34 @@ async function navigateClientHtml(url, fetchUrl, controller, navId, assertStillC
|
|
|
1356
1400
|
const redirectedUrl = resolveSameOriginRedirectedUrl(res.url);
|
|
1357
1401
|
if (redirectedUrl) throw new InternalNavigationRedirect(redirectedUrl);
|
|
1358
1402
|
}
|
|
1359
|
-
if (!res.ok && !(options.allowNotFoundResponse === true && res.status === 404)) scheduleHardNavigationAndThrow(browserUrl, `Navigation failed: ${res.status} ${res.statusText}`);
|
|
1403
|
+
if (!res.ok && res.status !== 404 && !(options.allowNotFoundResponse === true && res.status === 404)) scheduleHardNavigationAndThrow(browserUrl, `Navigation failed: ${res.status} ${res.statusText}`);
|
|
1360
1404
|
const html = await res.text();
|
|
1361
1405
|
assertStillCurrent();
|
|
1362
1406
|
const nextDataJson = extractVinextNextDataJson(html);
|
|
1363
|
-
if (!nextDataJson)
|
|
1407
|
+
if (!nextDataJson) {
|
|
1408
|
+
if (!res.ok && options.allowNotFoundResponse !== true) scheduleHardNavigationAndThrow(browserUrl, `Navigation failed: ${res.status} ${res.statusText}`);
|
|
1409
|
+
scheduleHardNavigationAndThrow(url, "Navigation failed: missing __NEXT_DATA__ in response");
|
|
1410
|
+
}
|
|
1364
1411
|
const nextData = parseVinextNextDataJson(nextDataJson);
|
|
1412
|
+
let nextDataRouteState = options.nextDataRouteState;
|
|
1413
|
+
let isDevelopmentNotFound = false;
|
|
1414
|
+
if (res.status === 404 && options.allowNotFoundResponse !== true && (nextData.page === "/404" || nextData.page === "/_error") && typeof nextData.notFoundSrcPage === "string") {
|
|
1415
|
+
const requestedPathname = getLocalPathname(browserUrl);
|
|
1416
|
+
let requestedUrl = null;
|
|
1417
|
+
try {
|
|
1418
|
+
requestedUrl = new URL(browserUrl, window.location.href);
|
|
1419
|
+
} catch {}
|
|
1420
|
+
const sourcePathname = requestedPathname ? removeNavigationLocalePrefix(requestedPathname) : null;
|
|
1421
|
+
const routeParams = sourcePathname ? extractRouteParamsFromPath(nextData.notFoundSrcPage, sourcePathname) : null;
|
|
1422
|
+
if (requestedUrl && routeParams !== null) {
|
|
1423
|
+
isDevelopmentNotFound = true;
|
|
1424
|
+
nextDataRouteState = {
|
|
1425
|
+
page: nextData.notFoundSrcPage,
|
|
1426
|
+
query: mergeRouteParamsIntoQuery(parseQueryString(requestedUrl.search), routeParams)
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
if (!res.ok && !(options.allowNotFoundResponse === true && res.status === 404) && !isDevelopmentNotFound) scheduleHardNavigationAndThrow(browserUrl, `Navigation failed: ${res.status} ${res.statusText}`);
|
|
1365
1431
|
const props = nextData.props && typeof nextData.props === "object" ? nextData.props : {};
|
|
1366
1432
|
const pageProps = Object.assign({}, props.pageProps);
|
|
1367
1433
|
props.pageProps = pageProps;
|
|
@@ -1374,6 +1440,7 @@ async function navigateClientHtml(url, fetchUrl, controller, navId, assertStillC
|
|
|
1374
1440
|
let pageModule;
|
|
1375
1441
|
const loader = window.__VINEXT_PAGE_LOADERS__?.[nextData.page];
|
|
1376
1442
|
if (loader) pageModule = await loader();
|
|
1443
|
+
else if (!pageModuleUrl && isDevelopmentNotFound) pageModule = await import("next/error");
|
|
1377
1444
|
else if (!pageModuleUrl) scheduleHardNavigationAndThrow(browserUrl, "Navigation failed: no page module URL found");
|
|
1378
1445
|
else {
|
|
1379
1446
|
if (!isValidModulePath(pageModuleUrl)) {
|
|
@@ -1410,8 +1477,12 @@ async function navigateClientHtml(url, fetchUrl, controller, navId, assertStillC
|
|
|
1410
1477
|
});
|
|
1411
1478
|
else element = React.createElement(PageComponent, pageProps);
|
|
1412
1479
|
options.beforeHistoryChange?.();
|
|
1413
|
-
|
|
1414
|
-
|
|
1480
|
+
const committedNextData = nextDataRouteState ? {
|
|
1481
|
+
...nextData,
|
|
1482
|
+
...nextDataRouteState
|
|
1483
|
+
} : nextData;
|
|
1484
|
+
window.__NEXT_DATA__ = committedNextData;
|
|
1485
|
+
applyVinextLocaleGlobals(window, committedNextData);
|
|
1415
1486
|
await renderPagesRouterElement(element, options.scroll);
|
|
1416
1487
|
assertStillCurrent();
|
|
1417
1488
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ExecutionContextLike } from "./request-context.js";
|
|
1
2
|
import { CacheState } from "./cache-request-state.js";
|
|
2
3
|
import { RootParamsState } from "./root-params.js";
|
|
3
|
-
import { ExecutionContextLike } from "./request-context.js";
|
|
4
4
|
import { FetchCacheState } from "./fetch-cache.js";
|
|
5
5
|
import { VinextHeadersShimState } from "./headers.js";
|
|
6
6
|
import { RouterState } from "./router-state.js";
|
|
@@ -36,6 +36,7 @@ function createRequestContext(opts) {
|
|
|
36
36
|
currentRequestTags: [],
|
|
37
37
|
currentFetchSoftTags: [],
|
|
38
38
|
currentFetchCacheMode: null,
|
|
39
|
+
currentFetchRevalidate: null,
|
|
39
40
|
currentForceDynamicFetchDefault: false,
|
|
40
41
|
dynamicFetchUrls: /* @__PURE__ */ new Set(),
|
|
41
42
|
refreshStaleFetchesInForeground: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
//#region src/utils/built-asset-url.d.ts
|
|
2
|
-
declare function renderVinextBuiltUrl(filename: string, assetPrefix: string, deploymentId?: string, hostType?: "js" | "css" | "html"): string;
|
|
2
|
+
declare function renderVinextBuiltUrl(filename: string, assetPrefix: string, deploymentId?: string, hostType?: "js" | "css" | "html", hostId?: string): string;
|
|
3
3
|
//#endregion
|
|
4
4
|
export { renderVinextBuiltUrl };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { appendDeploymentIdQuery } from "./deployment-id.js";
|
|
2
2
|
import { ASSET_PREFIX_URL_DIR, resolveAssetUrlPrefix, resolveAssetsDir } from "./asset-prefix.js";
|
|
3
3
|
//#region src/utils/built-asset-url.ts
|
|
4
|
-
function renderVinextBuiltUrl(filename, assetPrefix, deploymentId, hostType) {
|
|
4
|
+
function renderVinextBuiltUrl(filename, assetPrefix, deploymentId, hostType, hostId) {
|
|
5
5
|
const urlPrefix = resolveAssetUrlPrefix(assetPrefix);
|
|
6
6
|
const dirPrefix = resolveAssetsDir(assetPrefix) + "/";
|
|
7
7
|
const url = urlPrefix + (filename.startsWith(dirPrefix) ? filename.slice(dirPrefix.length) : filename.startsWith(`_next/static/`) ? filename.slice(ASSET_PREFIX_URL_DIR.length + 1) : filename);
|
|
8
|
-
|
|
8
|
+
const workerPath = `${ASSET_PREFIX_URL_DIR}/workers/`;
|
|
9
|
+
const belongsToWorkerGraph = filename.includes(workerPath) || hostId?.includes(workerPath);
|
|
10
|
+
return hostType === "js" && !belongsToWorkerGraph ? url : appendDeploymentIdQuery(url, deploymentId);
|
|
9
11
|
}
|
|
10
12
|
//#endregion
|
|
11
13
|
export { renderVinextBuiltUrl };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/utils/package-name.d.ts
|
|
2
|
+
declare const BARE_PACKAGE_SPECIFIER_RE: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* Extract the npm package name from a bare package specifier.
|
|
5
|
+
*
|
|
6
|
+
* Relative and absolute paths, package imports, URL/virtual schemes, malformed
|
|
7
|
+
* scoped names, and Node builtins are not npm package references.
|
|
8
|
+
*/
|
|
9
|
+
declare function packageNameFromSpecifier(specifier: string): string | null;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { BARE_PACKAGE_SPECIFIER_RE, packageNameFromSpecifier };
|