vinext 0.1.3 → 0.1.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/dist/build/client-build-config.d.ts +11 -2
- package/dist/build/client-build-config.js +17 -6
- package/dist/build/css-url-assets.d.ts +1 -1
- package/dist/build/css-url-assets.js +9 -7
- package/dist/build/prerender.js +3 -1
- package/dist/cache/cache-adapters-virtual.js +1 -1
- package/dist/client/pages-router-link-navigation.d.ts +33 -7
- package/dist/client/pages-router-link-navigation.js +32 -2
- package/dist/client/vinext-next-data.js +2 -0
- package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +1 -1
- package/dist/config/config-matchers.d.ts +11 -1
- package/dist/config/config-matchers.js +14 -2
- package/dist/config/tsconfig-paths.js +14 -1
- package/dist/deploy.js +20 -13
- package/dist/entries/app-rsc-entry.js +27 -22
- package/dist/entries/pages-client-entry.js +14 -13
- package/dist/entries/pages-server-entry.js +8 -27
- package/dist/index.js +365 -147
- package/dist/plugins/css-data-url.js +30 -26
- package/dist/plugins/dynamic-preload-metadata.js +2 -4
- package/dist/plugins/extensionless-dynamic-import.js +27 -24
- package/dist/plugins/fonts.js +5 -4
- package/dist/plugins/import-meta-url.js +21 -15
- package/dist/plugins/instrumentation-client.js +1 -1
- package/dist/plugins/middleware-server-only.js +7 -6
- package/dist/plugins/og-assets.js +48 -46
- package/dist/plugins/optimize-imports.js +9 -3
- package/dist/plugins/remove-console.d.ts +7 -1
- package/dist/plugins/remove-console.js +4 -1
- package/dist/plugins/require-context.js +21 -20
- package/dist/plugins/strip-server-exports.d.ts +16 -8
- package/dist/plugins/strip-server-exports.js +496 -46
- package/dist/routing/app-route-graph.js +2 -2
- package/dist/server/app-bfcache-identity.d.ts +26 -0
- package/dist/server/app-bfcache-identity.js +127 -0
- package/dist/server/app-browser-action-result.js +1 -1
- package/dist/server/app-browser-entry.js +22 -12
- package/dist/server/app-browser-navigation-controller.d.ts +1 -1
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-state.d.ts +3 -22
- package/dist/server/app-browser-state.js +23 -139
- package/dist/server/app-browser-stream.js +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +1 -1
- package/dist/server/app-browser-visible-commit.js +3 -2
- package/dist/server/app-fallback-renderer.d.ts +1 -1
- package/dist/server/app-layout-param-observation.d.ts +1 -1
- package/dist/server/app-layout-param-observation.js +1 -1
- package/dist/server/app-middleware.js +2 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -1
- package/dist/server/app-page-boundary.js +1 -1
- package/dist/server/app-page-cache-finalizer.d.ts +62 -0
- package/dist/server/app-page-cache-finalizer.js +122 -0
- package/dist/server/app-page-cache-render.d.ts +2 -2
- package/dist/server/app-page-cache-render.js +1 -1
- package/dist/server/app-page-cache.d.ts +2 -53
- package/dist/server/app-page-cache.js +5 -131
- package/dist/server/app-page-dispatch.d.ts +2 -2
- package/dist/server/app-page-dispatch.js +10 -8
- package/dist/server/app-page-probe.js +3 -2
- package/dist/server/app-page-render-observation.js +2 -2
- package/dist/server/app-page-render.d.ts +3 -3
- package/dist/server/app-page-render.js +3 -2
- package/dist/server/app-page-stream.d.ts +2 -9
- package/dist/server/app-page-stream.js +1 -35
- package/dist/server/app-pages-bridge.d.ts +5 -1
- package/dist/server/app-pages-bridge.js +5 -13
- package/dist/server/app-request-context.d.ts +1 -2
- package/dist/server/app-request-context.js +2 -1
- package/dist/server/app-route-handler-dispatch.js +3 -2
- package/dist/server/app-route-handler-execution.d.ts +1 -1
- package/dist/server/app-route-handler-execution.js +1 -1
- package/dist/server/app-route-handler-response.d.ts +1 -1
- package/dist/server/app-router-entry.js +2 -1
- package/dist/server/app-rsc-handler.d.ts +3 -0
- package/dist/server/app-rsc-handler.js +73 -31
- package/dist/server/app-rsc-response-finalizer.js +1 -1
- package/dist/server/app-rsc-route-matching.js +6 -2
- package/dist/server/app-server-action-execution.d.ts +1 -1
- package/dist/server/app-server-action-execution.js +10 -6
- package/dist/server/app-ssr-entry.d.ts +1 -1
- package/dist/server/app-ssr-entry.js +12 -38
- package/dist/server/app-ssr-router-instance.d.ts +6 -0
- package/dist/server/app-ssr-router-instance.js +24 -0
- package/dist/server/app-ssr-stream.js +1 -1
- package/dist/server/artifact-compatibility.js +1 -1
- package/dist/server/before-interactive-head.d.ts +17 -0
- package/dist/server/before-interactive-head.js +35 -0
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/csp.js +1 -4
- package/dist/server/defer-until-stream-consumed.d.ts +7 -0
- package/dist/server/defer-until-stream-consumed.js +34 -0
- package/dist/server/dev-server.js +82 -37
- package/dist/server/instrumentation.js +1 -1
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +1 -1
- package/dist/server/isr-decision.d.ts +1 -1
- package/dist/server/middleware-matcher.js +20 -9
- package/dist/server/middleware-runtime.d.ts +3 -4
- package/dist/server/middleware-runtime.js +4 -2
- package/dist/server/navigation-planner.d.ts +3 -12
- package/dist/server/navigation-planner.js +24 -0
- package/dist/server/navigation-trace.d.ts +2 -1
- package/dist/server/navigation-trace.js +1 -0
- package/dist/server/open-redirect.d.ts +12 -0
- package/dist/server/open-redirect.js +21 -0
- package/dist/server/operation-token.d.ts +40 -0
- package/dist/server/operation-token.js +85 -0
- package/dist/server/pages-data-route.d.ts +1 -1
- package/dist/server/pages-data-route.js +7 -4
- package/dist/server/pages-dev-module-url.d.ts +4 -0
- package/dist/server/pages-dev-module-url.js +15 -0
- package/dist/server/pages-document-initial-props.d.ts +4 -15
- package/dist/server/pages-document-initial-props.js +27 -56
- package/dist/server/pages-i18n.js +2 -2
- package/dist/server/pages-page-data.d.ts +1 -1
- package/dist/server/pages-page-data.js +3 -1
- package/dist/server/pages-page-handler.js +3 -1
- package/dist/server/pages-page-response.d.ts +3 -1
- package/dist/server/pages-page-response.js +6 -6
- package/dist/server/pages-readiness.js +1 -1
- package/dist/server/pages-request-pipeline.d.ts +7 -7
- package/dist/server/pages-request-pipeline.js +63 -21
- package/dist/server/prod-server.d.ts +3 -1
- package/dist/server/prod-server.js +43 -11
- package/dist/server/request-pipeline.d.ts +1 -24
- package/dist/server/request-pipeline.js +1 -33
- package/dist/server/seed-cache.d.ts +1 -1
- package/dist/server/static-file-cache.js +16 -4
- package/dist/shims/before-interactive-context.d.ts +14 -3
- package/dist/shims/cache-handler.d.ts +106 -0
- package/dist/shims/cache-handler.js +176 -0
- package/dist/shims/cache-request-state.d.ts +47 -0
- package/dist/shims/cache-request-state.js +126 -0
- package/dist/shims/cache-runtime.d.ts +2 -2
- package/dist/shims/cache-runtime.js +3 -14
- package/dist/shims/cache.d.ts +3 -231
- package/dist/shims/cache.js +17 -383
- package/dist/shims/cdn-cache.d.ts +1 -1
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/document.d.ts +15 -20
- package/dist/shims/document.js +5 -8
- package/dist/shims/error-boundary-navigation.d.ts +7 -0
- package/dist/shims/error-boundary-navigation.js +44 -0
- package/dist/shims/error-boundary.js +10 -8
- package/dist/shims/error.js +2 -1
- package/dist/shims/fetch-cache.js +1 -1
- package/dist/shims/form.js +1 -1
- package/dist/shims/image.js +74 -9
- package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -0
- package/dist/shims/internal/app-page-props-cache-key.js +16 -0
- package/dist/shims/internal/navigation-untracked.js +2 -1
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +6 -7
- package/dist/shims/internal/pages-data-fetch-dedup.js +67 -14
- package/dist/shims/internal/pages-data-target.js +1 -1
- package/dist/shims/layout-segment-context.d.ts +1 -1
- package/dist/shims/layout-segment-context.js +2 -1
- package/dist/shims/link.js +38 -17
- package/dist/shims/metadata.js +4 -4
- package/dist/shims/navigation-context-state.d.ts +40 -0
- package/dist/shims/navigation-context-state.js +116 -0
- package/dist/shims/navigation-errors.d.ts +55 -0
- package/dist/shims/navigation-errors.js +110 -0
- package/dist/shims/navigation-server.d.ts +3 -0
- package/dist/shims/navigation-server.js +3 -0
- package/dist/shims/navigation-state.d.ts +1 -2
- package/dist/shims/navigation-state.js +2 -1
- package/dist/shims/navigation.d.ts +3 -291
- package/dist/shims/navigation.js +16 -445
- package/dist/shims/navigation.react-server.d.ts +2 -2
- package/dist/shims/navigation.react-server.js +3 -1
- package/dist/shims/request-state-types.d.ts +3 -3
- package/dist/shims/router.d.ts +6 -2
- package/dist/shims/router.js +99 -20
- package/dist/shims/script.js +9 -5
- package/dist/shims/slot.js +3 -1
- package/dist/shims/unified-request-context.d.ts +2 -2
- package/dist/utils/has-trailing-comma.d.ts +24 -0
- package/dist/utils/has-trailing-comma.js +62 -0
- package/dist/utils/text-stream.d.ts +1 -1
- package/dist/utils/text-stream.js +2 -2
- package/dist/utils/virtual-module.d.ts +5 -0
- package/dist/utils/virtual-module.js +0 -0
- package/dist/utils/vite-version.d.ts +12 -1
- package/dist/utils/vite-version.js +9 -1
- package/package.json +5 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as React$1 from "react";
|
|
2
|
+
//#region src/shims/navigation-context-state.ts
|
|
3
|
+
const LAYOUT_SEGMENT_CONTEXT_KEY = Symbol.for("vinext.layoutSegmentContext");
|
|
4
|
+
const SERVER_INSERTED_HTML_CONTEXT_KEY = Symbol.for("vinext.serverInsertedHTMLContext");
|
|
5
|
+
const BFCACHE_ID_MAP_CONTEXT_KEY = Symbol.for("vinext.bfcacheIdMapContext");
|
|
6
|
+
const BFCACHE_SEGMENT_ID_CONTEXT_KEY = Symbol.for("vinext.bfcacheSegmentIdContext");
|
|
7
|
+
const GLOBAL_HYDRATION_CONTEXT_KEY = Symbol.for("vinext.navigation.clientHydrationContext");
|
|
8
|
+
const NAVIGATION_FALLBACK_STATE_KEY = Symbol.for("vinext.navigation.fallback");
|
|
9
|
+
function createContextIfAvailable(defaultValue) {
|
|
10
|
+
return typeof React$1.createContext === "function" ? React$1.createContext(defaultValue) : null;
|
|
11
|
+
}
|
|
12
|
+
function getServerInsertedHTMLContext() {
|
|
13
|
+
const globalState = globalThis;
|
|
14
|
+
if (!globalState[SERVER_INSERTED_HTML_CONTEXT_KEY]) globalState[SERVER_INSERTED_HTML_CONTEXT_KEY] = createContextIfAvailable(null);
|
|
15
|
+
return globalState[SERVER_INSERTED_HTML_CONTEXT_KEY] ?? null;
|
|
16
|
+
}
|
|
17
|
+
const ServerInsertedHTMLContext = getServerInsertedHTMLContext();
|
|
18
|
+
function getLayoutSegmentContext() {
|
|
19
|
+
const globalState = globalThis;
|
|
20
|
+
if (!globalState[LAYOUT_SEGMENT_CONTEXT_KEY]) globalState[LAYOUT_SEGMENT_CONTEXT_KEY] = createContextIfAvailable({ children: [] });
|
|
21
|
+
return globalState[LAYOUT_SEGMENT_CONTEXT_KEY] ?? null;
|
|
22
|
+
}
|
|
23
|
+
function getBfcacheIdMapContext() {
|
|
24
|
+
const globalState = globalThis;
|
|
25
|
+
if (!globalState[BFCACHE_ID_MAP_CONTEXT_KEY]) globalState[BFCACHE_ID_MAP_CONTEXT_KEY] = createContextIfAvailable(null);
|
|
26
|
+
return globalState[BFCACHE_ID_MAP_CONTEXT_KEY] ?? null;
|
|
27
|
+
}
|
|
28
|
+
function getBfcacheSegmentIdContext() {
|
|
29
|
+
const globalState = globalThis;
|
|
30
|
+
if (!globalState[BFCACHE_SEGMENT_ID_CONTEXT_KEY]) globalState[BFCACHE_SEGMENT_ID_CONTEXT_KEY] = createContextIfAvailable(null);
|
|
31
|
+
return globalState[BFCACHE_SEGMENT_ID_CONTEXT_KEY] ?? null;
|
|
32
|
+
}
|
|
33
|
+
const GLOBAL_ACCESSORS_KEY = Symbol.for("vinext.navigation.globalAccessors");
|
|
34
|
+
function getFallbackState() {
|
|
35
|
+
const globalState = globalThis;
|
|
36
|
+
return globalState[NAVIGATION_FALLBACK_STATE_KEY] ??= {
|
|
37
|
+
serverContext: null,
|
|
38
|
+
serverInsertedHTMLCallbacks: []
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function getGlobalAccessors() {
|
|
42
|
+
return globalThis[GLOBAL_ACCESSORS_KEY];
|
|
43
|
+
}
|
|
44
|
+
function getClientHydrationContext() {
|
|
45
|
+
const globalState = globalThis;
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(globalState, GLOBAL_HYDRATION_CONTEXT_KEY)) return globalState[GLOBAL_HYDRATION_CONTEXT_KEY] ?? null;
|
|
47
|
+
}
|
|
48
|
+
function setClientHydrationContext(context) {
|
|
49
|
+
globalThis[GLOBAL_HYDRATION_CONTEXT_KEY] = context;
|
|
50
|
+
}
|
|
51
|
+
function clearClientHydrationContext() {
|
|
52
|
+
if (typeof window !== "undefined") setClientHydrationContext(null);
|
|
53
|
+
}
|
|
54
|
+
let getServerContext = () => {
|
|
55
|
+
if (typeof window !== "undefined") {
|
|
56
|
+
const hydrationContext = getClientHydrationContext();
|
|
57
|
+
return hydrationContext !== void 0 ? hydrationContext : getFallbackState().serverContext;
|
|
58
|
+
}
|
|
59
|
+
return getGlobalAccessors()?.getServerContext() ?? getFallbackState().serverContext;
|
|
60
|
+
};
|
|
61
|
+
let setServerContext = (context) => {
|
|
62
|
+
if (typeof window !== "undefined") {
|
|
63
|
+
getFallbackState().serverContext = context;
|
|
64
|
+
setClientHydrationContext(context);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const accessors = getGlobalAccessors();
|
|
68
|
+
if (accessors) accessors.setServerContext(context);
|
|
69
|
+
else getFallbackState().serverContext = context;
|
|
70
|
+
};
|
|
71
|
+
let getInsertedHTMLCallbacks = () => getGlobalAccessors()?.getInsertedHTMLCallbacks() ?? getFallbackState().serverInsertedHTMLCallbacks;
|
|
72
|
+
let clearInsertedHTMLCallbacks = () => {
|
|
73
|
+
const accessors = getGlobalAccessors();
|
|
74
|
+
if (accessors) accessors.clearInsertedHTMLCallbacks();
|
|
75
|
+
else getFallbackState().serverInsertedHTMLCallbacks = [];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Register request-scoped accessors supplied by navigation-state.ts.
|
|
79
|
+
* The global accessor key also bridges separate Vite module instances.
|
|
80
|
+
*/
|
|
81
|
+
function _registerStateAccessors(accessors) {
|
|
82
|
+
getServerContext = accessors.getServerContext;
|
|
83
|
+
setServerContext = accessors.setServerContext;
|
|
84
|
+
getInsertedHTMLCallbacks = accessors.getInsertedHTMLCallbacks;
|
|
85
|
+
clearInsertedHTMLCallbacks = accessors.clearInsertedHTMLCallbacks;
|
|
86
|
+
}
|
|
87
|
+
function getNavigationContext() {
|
|
88
|
+
return getServerContext();
|
|
89
|
+
}
|
|
90
|
+
function setNavigationContext(context) {
|
|
91
|
+
setServerContext(context);
|
|
92
|
+
}
|
|
93
|
+
function registerServerInsertedHTMLCallback(callback) {
|
|
94
|
+
getInsertedHTMLCallbacks().push(callback);
|
|
95
|
+
}
|
|
96
|
+
function renderInsertedHTMLCallbacks(clear) {
|
|
97
|
+
const callbacks = getInsertedHTMLCallbacks();
|
|
98
|
+
const results = [];
|
|
99
|
+
for (const callback of callbacks) try {
|
|
100
|
+
const result = callback();
|
|
101
|
+
if (result != null) results.push(result);
|
|
102
|
+
} catch {}
|
|
103
|
+
if (clear) callbacks.length = 0;
|
|
104
|
+
return results;
|
|
105
|
+
}
|
|
106
|
+
function flushServerInsertedHTML() {
|
|
107
|
+
return renderInsertedHTMLCallbacks(true);
|
|
108
|
+
}
|
|
109
|
+
function renderServerInsertedHTML() {
|
|
110
|
+
return renderInsertedHTMLCallbacks(false);
|
|
111
|
+
}
|
|
112
|
+
function clearServerInsertedHTML() {
|
|
113
|
+
clearInsertedHTMLCallbacks();
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//#region src/shims/navigation-errors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Server-safe navigation control-flow errors and predicates.
|
|
4
|
+
*
|
|
5
|
+
* This module intentionally has no React or browser-runtime dependencies so
|
|
6
|
+
* RSC, SSR, and the public next/navigation shim can share one implementation.
|
|
7
|
+
*/
|
|
8
|
+
declare const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
|
|
9
|
+
declare function isHTTPAccessFallbackError(error: unknown): boolean;
|
|
10
|
+
declare function getAccessFallbackHTTPStatus(error: unknown): number;
|
|
11
|
+
declare enum RedirectType {
|
|
12
|
+
push = "push",
|
|
13
|
+
replace = "replace"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The omitted redirect type is resolved by the catch site: push for Server
|
|
17
|
+
* Actions and replace for ordinary SSR/RSC rendering.
|
|
18
|
+
*/
|
|
19
|
+
declare function redirect(url: string, type?: "replace" | "push" | RedirectType): never;
|
|
20
|
+
declare function permanentRedirect(url: string, type?: "replace" | "push" | RedirectType): never;
|
|
21
|
+
declare function notFound(): never;
|
|
22
|
+
declare function forbidden(): never;
|
|
23
|
+
declare function unauthorized(): never;
|
|
24
|
+
type RedirectErrorShape = Error & {
|
|
25
|
+
digest: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* vinext accepts its three-part redirect digest and Next.js's five-part form.
|
|
29
|
+
* A prefix check is deliberate because vinext permits an empty redirect type.
|
|
30
|
+
*/
|
|
31
|
+
declare function isRedirectError(error: unknown): error is RedirectErrorShape;
|
|
32
|
+
declare function decodeRedirectError(digest: string): {
|
|
33
|
+
url: string;
|
|
34
|
+
type: "push" | "replace";
|
|
35
|
+
} | null;
|
|
36
|
+
declare function isNextRouterError(error: unknown): boolean;
|
|
37
|
+
declare class BailoutToCSRError extends Error {
|
|
38
|
+
readonly digest = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
|
|
39
|
+
readonly reason: string;
|
|
40
|
+
constructor(reason: string);
|
|
41
|
+
}
|
|
42
|
+
declare function isBailoutToCSRError(error: unknown): error is BailoutToCSRError;
|
|
43
|
+
declare class DynamicServerError extends Error {
|
|
44
|
+
readonly digest = "DYNAMIC_SERVER_USAGE";
|
|
45
|
+
readonly description: string;
|
|
46
|
+
constructor(description: string);
|
|
47
|
+
}
|
|
48
|
+
declare function isDynamicServerError(error: unknown): error is DynamicServerError;
|
|
49
|
+
/**
|
|
50
|
+
* Rethrow framework control-flow signals before user error handling consumes
|
|
51
|
+
* them. This covers the categories vinext can currently produce.
|
|
52
|
+
*/
|
|
53
|
+
declare function unstable_rethrow(error: unknown): void;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//#region src/shims/navigation-errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Server-safe navigation control-flow errors and predicates.
|
|
4
|
+
*
|
|
5
|
+
* This module intentionally has no React or browser-runtime dependencies so
|
|
6
|
+
* RSC, SSR, and the public next/navigation shim can share one implementation.
|
|
7
|
+
*/
|
|
8
|
+
const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
|
|
9
|
+
function isHTTPAccessFallbackError(error) {
|
|
10
|
+
if (!error || typeof error !== "object" || !("digest" in error)) return false;
|
|
11
|
+
const digest = String(error.digest);
|
|
12
|
+
return digest === "NEXT_NOT_FOUND" || digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`);
|
|
13
|
+
}
|
|
14
|
+
function getAccessFallbackHTTPStatus(error) {
|
|
15
|
+
if (error && typeof error === "object" && "digest" in error) {
|
|
16
|
+
const digest = String(error.digest);
|
|
17
|
+
if (digest === "NEXT_NOT_FOUND") return 404;
|
|
18
|
+
if (digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`)) return Number.parseInt(digest.split(";")[1], 10);
|
|
19
|
+
}
|
|
20
|
+
return 404;
|
|
21
|
+
}
|
|
22
|
+
let RedirectType = /* @__PURE__ */ function(RedirectType) {
|
|
23
|
+
RedirectType["push"] = "push";
|
|
24
|
+
RedirectType["replace"] = "replace";
|
|
25
|
+
return RedirectType;
|
|
26
|
+
}({});
|
|
27
|
+
var VinextNavigationError = class extends Error {
|
|
28
|
+
digest;
|
|
29
|
+
constructor(message, digest) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.digest = digest;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The omitted redirect type is resolved by the catch site: push for Server
|
|
36
|
+
* Actions and replace for ordinary SSR/RSC rendering.
|
|
37
|
+
*/
|
|
38
|
+
function redirect(url, type) {
|
|
39
|
+
throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type ?? ""};${encodeURIComponent(url)}`);
|
|
40
|
+
}
|
|
41
|
+
function permanentRedirect(url, type = "replace") {
|
|
42
|
+
throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type};${encodeURIComponent(url)};308`);
|
|
43
|
+
}
|
|
44
|
+
function notFound() {
|
|
45
|
+
throw new VinextNavigationError("NEXT_NOT_FOUND", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);
|
|
46
|
+
}
|
|
47
|
+
function forbidden() {
|
|
48
|
+
throw new VinextNavigationError("NEXT_FORBIDDEN", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);
|
|
49
|
+
}
|
|
50
|
+
function unauthorized() {
|
|
51
|
+
throw new VinextNavigationError("NEXT_UNAUTHORIZED", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* vinext accepts its three-part redirect digest and Next.js's five-part form.
|
|
55
|
+
* A prefix check is deliberate because vinext permits an empty redirect type.
|
|
56
|
+
*/
|
|
57
|
+
function isRedirectError(error) {
|
|
58
|
+
return !!error && typeof error === "object" && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_REDIRECT;");
|
|
59
|
+
}
|
|
60
|
+
function decodeRedirectError(digest) {
|
|
61
|
+
if (!digest.startsWith("NEXT_REDIRECT;")) return null;
|
|
62
|
+
const parts = digest.split(";");
|
|
63
|
+
const encodedTarget = parts.length >= 5 ? parts.slice(2, -2).join(";") : parts[2];
|
|
64
|
+
if (!encodedTarget) return null;
|
|
65
|
+
try {
|
|
66
|
+
return {
|
|
67
|
+
url: decodeURIComponent(encodedTarget),
|
|
68
|
+
type: parts[1] === "push" ? "push" : "replace"
|
|
69
|
+
};
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function isNextRouterError(error) {
|
|
75
|
+
return isRedirectError(error) || isHTTPAccessFallbackError(error);
|
|
76
|
+
}
|
|
77
|
+
const BAILOUT_TO_CSR_DIGEST = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
|
|
78
|
+
var BailoutToCSRError = class extends Error {
|
|
79
|
+
digest = BAILOUT_TO_CSR_DIGEST;
|
|
80
|
+
reason;
|
|
81
|
+
constructor(reason) {
|
|
82
|
+
super(`Bail out to client-side rendering: ${reason}`);
|
|
83
|
+
this.reason = reason;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
function isBailoutToCSRError(error) {
|
|
87
|
+
return !!error && typeof error === "object" && "digest" in error && error.digest === BAILOUT_TO_CSR_DIGEST;
|
|
88
|
+
}
|
|
89
|
+
const DYNAMIC_SERVER_USAGE_DIGEST = "DYNAMIC_SERVER_USAGE";
|
|
90
|
+
var DynamicServerError = class extends Error {
|
|
91
|
+
digest = DYNAMIC_SERVER_USAGE_DIGEST;
|
|
92
|
+
description;
|
|
93
|
+
constructor(description) {
|
|
94
|
+
super(`Dynamic server usage: ${description}`);
|
|
95
|
+
this.description = description;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
function isDynamicServerError(error) {
|
|
99
|
+
return !!error && typeof error === "object" && "digest" in error && error.digest === DYNAMIC_SERVER_USAGE_DIGEST;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Rethrow framework control-flow signals before user error handling consumes
|
|
103
|
+
* them. This covers the categories vinext can currently produce.
|
|
104
|
+
*/
|
|
105
|
+
function unstable_rethrow(error) {
|
|
106
|
+
if (isNextRouterError(error) || isBailoutToCSRError(error) || isDynamicServerError(error)) throw error;
|
|
107
|
+
if (error instanceof Error && "cause" in error) unstable_rethrow(error.cause);
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
export { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GLOBAL_ACCESSORS_KEY, NavigationContext, NavigationStateAccessors, SegmentMap, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
2
|
+
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
3
|
+
export { BailoutToCSRError, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, type NavigationContext, type NavigationStateAccessors, RedirectType, type SegmentMap, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, decodeRedirectError, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext, unauthorized, unstable_rethrow };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
2
|
+
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
3
|
+
export { BailoutToCSRError, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, decodeRedirectError, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext, unauthorized, unstable_rethrow };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getOrCreateAls } from "./internal/als-registry.js";
|
|
2
2
|
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
3
|
-
import { GLOBAL_ACCESSORS_KEY, _registerStateAccessors } from "./navigation.js";
|
|
3
|
+
import { GLOBAL_ACCESSORS_KEY, _registerStateAccessors } from "./navigation-context-state.js";
|
|
4
|
+
import "./navigation-server.js";
|
|
4
5
|
//#region src/shims/navigation-state.ts
|
|
5
6
|
/**
|
|
6
7
|
* Server-only navigation state backed by AsyncLocalStorage.
|
|
@@ -2,57 +2,12 @@ import { AppRouterScrollIntent } from "./app-router-scroll-state.js";
|
|
|
2
2
|
import { NavigationRuntimeVisibleCommitMode } from "../client/navigation-runtime.js";
|
|
3
3
|
import { AppRouterInstance, NavigateOptions, PrefetchOptions as PrefetchOptions$1 } from "./internal/app-router-context.js";
|
|
4
4
|
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
5
|
+
import { GLOBAL_ACCESSORS_KEY, NavigationContext, NavigationStateAccessors, SegmentMap, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
6
|
+
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
5
7
|
import { UnrecognizedActionError, unstable_isUnrecognizedActionError } from "./unrecognized-action-error.js";
|
|
6
8
|
import * as React$1 from "react";
|
|
7
9
|
|
|
8
10
|
//#region src/shims/navigation.d.ts
|
|
9
|
-
/**
|
|
10
|
-
* Map of parallel route key → child segments below the current layout.
|
|
11
|
-
* The "children" key is always present (the default parallel route).
|
|
12
|
-
* Named parallel routes add their own keys (e.g., "team", "analytics").
|
|
13
|
-
*
|
|
14
|
-
* Arrays are mutable (`string[]`) to match Next.js's public API return type
|
|
15
|
-
* without requiring `as` casts. The map itself is Readonly — no key addition.
|
|
16
|
-
*/
|
|
17
|
-
type SegmentMap = Readonly<Record<string, string[]>> & {
|
|
18
|
-
readonly children: string[];
|
|
19
|
-
};
|
|
20
|
-
declare const ServerInsertedHTMLContext: React$1.Context<((callback: () => unknown) => void) | null> | null;
|
|
21
|
-
/**
|
|
22
|
-
* Get or create the layout segment context.
|
|
23
|
-
* Returns null in the RSC environment (createContext unavailable).
|
|
24
|
-
*/
|
|
25
|
-
declare function getLayoutSegmentContext(): React$1.Context<SegmentMap> | null;
|
|
26
|
-
declare function getBfcacheIdMapContext(): React$1.Context<Readonly<Record<string, string>> | null> | null;
|
|
27
|
-
declare function getBfcacheSegmentIdContext(): React$1.Context<string | null> | null;
|
|
28
|
-
type NavigationContext = {
|
|
29
|
-
pathname: string;
|
|
30
|
-
searchParams: URLSearchParams;
|
|
31
|
-
params: Record<string, string | string[]>;
|
|
32
|
-
};
|
|
33
|
-
type _StateAccessors = {
|
|
34
|
-
getServerContext: () => NavigationContext | null;
|
|
35
|
-
setServerContext: (ctx: NavigationContext | null) => void;
|
|
36
|
-
getInsertedHTMLCallbacks: () => Array<() => unknown>;
|
|
37
|
-
clearInsertedHTMLCallbacks: () => void;
|
|
38
|
-
};
|
|
39
|
-
declare const GLOBAL_ACCESSORS_KEY: unique symbol;
|
|
40
|
-
/**
|
|
41
|
-
* Register ALS-backed state accessors. Called by navigation-state.ts on import.
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
|
-
declare function _registerStateAccessors(accessors: _StateAccessors): void;
|
|
45
|
-
/**
|
|
46
|
-
* Get the navigation context for the current SSR/RSC render.
|
|
47
|
-
* Reads from AsyncLocalStorage when available (concurrent-safe),
|
|
48
|
-
* otherwise falls back to module-level state.
|
|
49
|
-
*/
|
|
50
|
-
declare function getNavigationContext(): NavigationContext | null;
|
|
51
|
-
/**
|
|
52
|
-
* Set the navigation context for the current SSR/RSC render.
|
|
53
|
-
* Called by the framework entry before rendering each request.
|
|
54
|
-
*/
|
|
55
|
-
declare function setNavigationContext(ctx: NavigationContext | null): void;
|
|
56
11
|
/** basePath from next.config.js, injected by the plugin at build time */
|
|
57
12
|
declare const __basePath: string;
|
|
58
13
|
/** Maximum number of entries in the RSC prefetch cache. */
|
|
@@ -327,248 +282,5 @@ declare function useSelectedLayoutSegments(parallelRoutesKey?: string): string[]
|
|
|
327
282
|
* });
|
|
328
283
|
*/
|
|
329
284
|
declare function useServerInsertedHTML(callback: () => unknown): void;
|
|
330
|
-
/**
|
|
331
|
-
* Flush all collected useServerInsertedHTML callbacks.
|
|
332
|
-
* Returns an array of results (React elements or strings).
|
|
333
|
-
* Clears the callback list so the next render starts fresh.
|
|
334
|
-
*
|
|
335
|
-
* Called by the SSR entry after renderToReadableStream completes.
|
|
336
|
-
*/
|
|
337
|
-
declare function flushServerInsertedHTML(): unknown[];
|
|
338
|
-
/**
|
|
339
|
-
* Render collected useServerInsertedHTML callbacks without unregistering them.
|
|
340
|
-
*
|
|
341
|
-
* Streaming SSR needs to invoke the same style-registry callbacks after each
|
|
342
|
-
* Fizz flush. Libraries such as styled-components and Emotion clear their own
|
|
343
|
-
* per-flush buffers inside the callback; the registration itself must survive
|
|
344
|
-
* until the request stream is closed.
|
|
345
|
-
*/
|
|
346
|
-
declare function renderServerInsertedHTML(): unknown[];
|
|
347
|
-
/**
|
|
348
|
-
* Clear all collected useServerInsertedHTML callbacks without flushing.
|
|
349
|
-
* Used for cleanup between requests.
|
|
350
|
-
*/
|
|
351
|
-
declare function clearServerInsertedHTML(): void;
|
|
352
|
-
/**
|
|
353
|
-
* HTTP Access Fallback error code — shared prefix for notFound/forbidden/unauthorized.
|
|
354
|
-
* Matches Next.js 16's unified error handling approach.
|
|
355
|
-
*/
|
|
356
|
-
declare const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
|
|
357
|
-
/**
|
|
358
|
-
* Check if an error is an HTTP Access Fallback error (notFound, forbidden, unauthorized).
|
|
359
|
-
*/
|
|
360
|
-
declare function isHTTPAccessFallbackError(error: unknown): boolean;
|
|
361
|
-
/**
|
|
362
|
-
* Extract the HTTP status code from an HTTP Access Fallback error.
|
|
363
|
-
* Returns 404 for legacy NEXT_NOT_FOUND errors.
|
|
364
|
-
*/
|
|
365
|
-
declare function getAccessFallbackHTTPStatus(error: unknown): number;
|
|
366
|
-
/**
|
|
367
|
-
* Enum matching Next.js RedirectType for type-safe redirect calls.
|
|
368
|
-
*/
|
|
369
|
-
declare enum RedirectType {
|
|
370
|
-
push = "push",
|
|
371
|
-
replace = "replace"
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Throw a redirect. Caught by the framework to send a redirect response.
|
|
375
|
-
*
|
|
376
|
-
* When `type` is omitted, the digest carries an empty sentinel so the
|
|
377
|
-
* catch site can resolve the default based on context:
|
|
378
|
-
* - Server Action context → "push" (Back button works after form submission)
|
|
379
|
-
* - SSR render context → "replace"
|
|
380
|
-
*
|
|
381
|
-
* This matches Next.js behavior where `redirect()` checks
|
|
382
|
-
* `actionAsyncStorage.getStore()?.isAction` at call time.
|
|
383
|
-
*
|
|
384
|
-
* @see https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect.ts
|
|
385
|
-
*/
|
|
386
|
-
declare function redirect(url: string, type?: "replace" | "push" | RedirectType): never;
|
|
387
|
-
/**
|
|
388
|
-
* Trigger a permanent redirect (308).
|
|
389
|
-
*
|
|
390
|
-
* Accepts an optional `type` parameter matching Next.js's signature.
|
|
391
|
-
* Defaults to "replace" (not context-dependent like `redirect()`).
|
|
392
|
-
*
|
|
393
|
-
* @see https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect.ts
|
|
394
|
-
*/
|
|
395
|
-
declare function permanentRedirect(url: string, type?: "replace" | "push" | RedirectType): never;
|
|
396
|
-
/**
|
|
397
|
-
* Trigger a not-found response (404). Caught by the framework.
|
|
398
|
-
*/
|
|
399
|
-
declare function notFound(): never;
|
|
400
|
-
/**
|
|
401
|
-
* Trigger a forbidden response (403). Caught by the framework.
|
|
402
|
-
* In Next.js, this is gated behind experimental.authInterrupts — we
|
|
403
|
-
* support it unconditionally for maximum compatibility.
|
|
404
|
-
*/
|
|
405
|
-
declare function forbidden(): never;
|
|
406
|
-
/**
|
|
407
|
-
* Trigger an unauthorized response (401). Caught by the framework.
|
|
408
|
-
* In Next.js, this is gated behind experimental.authInterrupts — we
|
|
409
|
-
* support it unconditionally for maximum compatibility.
|
|
410
|
-
*/
|
|
411
|
-
declare function unauthorized(): never;
|
|
412
|
-
type _RedirectErrorShape = Error & {
|
|
413
|
-
digest: string;
|
|
414
|
-
};
|
|
415
|
-
/**
|
|
416
|
-
* Check whether an error was produced by `redirect()` or `permanentRedirect()`.
|
|
417
|
-
*
|
|
418
|
-
* **Note on vinext public surface:** Next.js does NOT expose `isRedirectError`
|
|
419
|
-
* from `next/navigation` — it's an internal predicate. vinext exposes it for
|
|
420
|
-
* symmetry with the already-public `isHTTPAccessFallbackError` and because
|
|
421
|
-
* `unstable_rethrow` consumers benefit from being able to narrow types.
|
|
422
|
-
* Treat it as a vinext-only extension.
|
|
423
|
-
*
|
|
424
|
-
* **Divergence from Next.js:** Next.js's internal `isRedirectError` performs
|
|
425
|
-
* full 4-segment validation — it splits the digest on `;`, checks `type` ∈
|
|
426
|
-
* {push, replace}, requires a non-empty destination, and validates the
|
|
427
|
-
* status code (303, 307, 308). See:
|
|
428
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect-error.ts
|
|
429
|
-
*
|
|
430
|
-
* vinext instead uses a simple prefix check (`startsWith("NEXT_REDIRECT;")`).
|
|
431
|
-
* Reasons:
|
|
432
|
-
* 1. vinext emits two digest shapes — 3-part for `redirect()`
|
|
433
|
-
* (`NEXT_REDIRECT;{type};{encoded-url}`) and 4-part for
|
|
434
|
-
* `permanentRedirect()` (`NEXT_REDIRECT;{type};{encoded-url};308`).
|
|
435
|
-
* Strict validation would have to special-case both, and Next.js's
|
|
436
|
-
* validator (tuned to its 5-part canary digests) rejects them.
|
|
437
|
-
* 2. The `type` field is sometimes empty in vinext's redirect digests
|
|
438
|
-
* (context-dependent resolution; see `redirect()` above), which the
|
|
439
|
-
* strict check disallows.
|
|
440
|
-
*
|
|
441
|
-
* **Consequence:** A malformed digest such as `"NEXT_REDIRECT;garbage"`
|
|
442
|
-
* returns `true` here, whereas Next.js would return `false`. In practice,
|
|
443
|
-
* the only callers of this predicate are vinext-internal code paths
|
|
444
|
-
* (`unstable_rethrow`, `unstable_catchError`, the redirect error boundary)
|
|
445
|
-
* that see digests vinext itself emits — so the divergence does not surface
|
|
446
|
-
* in normal use. Maintainers extending the prefix logic should keep this
|
|
447
|
-
* predicate in lockstep with the corresponding `decode*` helpers in
|
|
448
|
-
* `shims/error-boundary.tsx`.
|
|
449
|
-
*/
|
|
450
|
-
declare function isRedirectError(error: unknown): error is _RedirectErrorShape;
|
|
451
|
-
/**
|
|
452
|
-
* Parse a redirect error digest into its URL and type components.
|
|
453
|
-
*
|
|
454
|
-
* Supports two formats:
|
|
455
|
-
* - vinext's 3-part: `NEXT_REDIRECT;{type};{encoded-url}`
|
|
456
|
-
* - Next.js's 5-part: `NEXT_REDIRECT;{type};{url};{status};{isClient}`
|
|
457
|
-
*
|
|
458
|
-
* The URL segment is always percent-encoded on the write side
|
|
459
|
-
* (encodeURIComponent is used), so re-joining with ";" for the 5-part
|
|
460
|
-
* format is defensive — it correctly handles any unencoded ";" that
|
|
461
|
-
* might appear in an externally-sourced digest.
|
|
462
|
-
*
|
|
463
|
-
* Returns null for malformed digests that have an empty URL segment, or
|
|
464
|
-
* when the URL contains invalid percent-encoding.
|
|
465
|
-
*/
|
|
466
|
-
declare function decodeRedirectError(digest: string): {
|
|
467
|
-
url: string;
|
|
468
|
-
type: "push" | "replace";
|
|
469
|
-
} | null;
|
|
470
|
-
/**
|
|
471
|
-
* Returns true if the error is a Next.js navigation signal — either a redirect
|
|
472
|
-
* or an HTTP access fallback (notFound / forbidden / unauthorized).
|
|
473
|
-
*
|
|
474
|
-
* **Note on vinext public surface:** Like `isRedirectError`, Next.js does NOT
|
|
475
|
-
* expose this from `next/navigation`. vinext exposes it for symmetry — treat
|
|
476
|
-
* it as a vinext-only extension.
|
|
477
|
-
*
|
|
478
|
-
* Ported from Next.js:
|
|
479
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/is-next-router-error.ts
|
|
480
|
-
*/
|
|
481
|
-
declare function isNextRouterError(error: unknown): boolean;
|
|
482
|
-
declare const _BAILOUT_TO_CSR_DIGEST = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
|
|
483
|
-
/**
|
|
484
|
-
* Error thrown to bail out of server rendering and fall back to client-side
|
|
485
|
-
* rendering. Used by `next/dynamic` with `ssr: false`.
|
|
486
|
-
*
|
|
487
|
-
* vinext does not yet emit this error itself — it's exposed so user code and
|
|
488
|
-
* third-party libraries that mimic `next/dynamic`'s bailout semantics can
|
|
489
|
-
* construct an error with the canonical digest that `unstable_rethrow`
|
|
490
|
-
* recognises.
|
|
491
|
-
*
|
|
492
|
-
* Ported 1:1 from Next.js:
|
|
493
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/lazy-dynamic/bailout-to-csr.ts
|
|
494
|
-
*/
|
|
495
|
-
declare class BailoutToCSRError extends Error {
|
|
496
|
-
readonly digest: typeof _BAILOUT_TO_CSR_DIGEST;
|
|
497
|
-
readonly reason: string;
|
|
498
|
-
constructor(reason: string);
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Returns true if the error is a `BailoutToCSRError`. Matches Next.js's
|
|
502
|
-
* digest-based predicate, so any error from a foreign module instance of
|
|
503
|
-
* the class (or constructed manually with the canonical digest) is also
|
|
504
|
-
* detected.
|
|
505
|
-
*
|
|
506
|
-
* **Note on vinext public surface:** Next.js does NOT expose this from
|
|
507
|
-
* `next/navigation`. vinext exposes it for symmetry with `isRedirectError`
|
|
508
|
-
* — treat it as a vinext-only extension. The matching producer
|
|
509
|
-
* (`BailoutToCSRError`) is the public detection contract; Next.js exposes
|
|
510
|
-
* neither.
|
|
511
|
-
*
|
|
512
|
-
* Ported from Next.js:
|
|
513
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/lazy-dynamic/bailout-to-csr.ts
|
|
514
|
-
*/
|
|
515
|
-
declare function isBailoutToCSRError(error: unknown): error is BailoutToCSRError;
|
|
516
|
-
declare const _DYNAMIC_SERVER_USAGE_DIGEST = "DYNAMIC_SERVER_USAGE";
|
|
517
|
-
/**
|
|
518
|
-
* Error thrown when dynamic server APIs (`cookies()`, `headers()`, etc.) are
|
|
519
|
-
* used inside a static/prerender context. Carries the `DYNAMIC_SERVER_USAGE`
|
|
520
|
-
* digest so `unstable_rethrow` can recognise and propagate it.
|
|
521
|
-
*
|
|
522
|
-
* vinext does not construct this error itself — exposed for the same
|
|
523
|
-
* "stable detection contract" reason as `BailoutToCSRError` above.
|
|
524
|
-
*
|
|
525
|
-
* Ported 1:1 from Next.js:
|
|
526
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/hooks-server-context.ts
|
|
527
|
-
*/
|
|
528
|
-
declare class DynamicServerError extends Error {
|
|
529
|
-
readonly digest: typeof _DYNAMIC_SERVER_USAGE_DIGEST;
|
|
530
|
-
readonly description: string;
|
|
531
|
-
constructor(description: string);
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Returns true if the error is a `DynamicServerError` (or any error with the
|
|
535
|
-
* canonical `DYNAMIC_SERVER_USAGE` digest).
|
|
536
|
-
*
|
|
537
|
-
* **Note on vinext public surface:** Next.js does NOT expose this from
|
|
538
|
-
* `next/navigation`. vinext exposes it for symmetry — treat it as a
|
|
539
|
-
* vinext-only extension.
|
|
540
|
-
*
|
|
541
|
-
* Ported from Next.js:
|
|
542
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/hooks-server-context.ts
|
|
543
|
-
*/
|
|
544
|
-
declare function isDynamicServerError(error: unknown): error is DynamicServerError;
|
|
545
|
-
/**
|
|
546
|
-
* Rethrow internal Next.js errors so they're handled by the framework.
|
|
547
|
-
*
|
|
548
|
-
* When wrapping an API that uses errors for control flow (redirect, notFound,
|
|
549
|
-
* cookies in static render, `next/dynamic` SSR bailout, etc.), call this
|
|
550
|
-
* inside `catch` blocks before doing your own error handling. If the error
|
|
551
|
-
* is a Next.js internal error, it's rethrown; otherwise this is a no-op
|
|
552
|
-
* (apart from recursing through `error.cause`).
|
|
553
|
-
*
|
|
554
|
-
* Recognises (matches Next.js's browser build + the subset of the server
|
|
555
|
-
* build that vinext can realistically encounter):
|
|
556
|
-
* - `isNextRouterError`: redirect / notFound / forbidden / unauthorized
|
|
557
|
-
* - `isBailoutToCSRError`: `next/dynamic` `ssr: false` bailout
|
|
558
|
-
* - `isDynamicServerError`: dynamic API used in static render
|
|
559
|
-
*
|
|
560
|
-
* vinext does not yet recognise four additional server-only Next.js
|
|
561
|
-
* categories — `isDynamicPostpone`, `isPostpone`,
|
|
562
|
-
* `isHangingPromiseRejectionError`, `isPrerenderInterruptedError` — because
|
|
563
|
-
* they signal PPR / prerender-controller events that vinext's render
|
|
564
|
-
* pipeline does not generate. User code cannot construct these in normal
|
|
565
|
-
* use; they will be added if/when vinext grows PPR support.
|
|
566
|
-
*
|
|
567
|
-
* Ported from Next.js:
|
|
568
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/unstable-rethrow.ts
|
|
569
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/unstable-rethrow.server.ts
|
|
570
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/unstable-rethrow.browser.ts
|
|
571
|
-
*/
|
|
572
|
-
declare function unstable_rethrow(error: unknown): void;
|
|
573
285
|
//#endregion
|
|
574
|
-
export { BailoutToCSRError, CachedRscResponse, ClientNavigationRenderSnapshot, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, NavigationContext, PREFETCH_CACHE_TTL, PrefetchCacheEntry, PrefetchOptions, ReadonlyURLSearchParams, RedirectType, SegmentMap, ServerInsertedHTMLContext, UnrecognizedActionError, __basePath, _registerStateAccessors, activateNavigationSnapshot, appRouterInstance, applyAppRouterScrollFallback, clearPendingPathname, clearServerInsertedHTML, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, decodeRedirectError, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getClientNavigationRenderContext, getClientNavigationState, getClientParams, getCurrentInterceptionContext, getCurrentNextUrl, getLayoutSegmentContext, getMountedSlotsHeader, getNavigationContext, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, invalidatePrefetchCache, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, navigateClientSide, notFound, permanentRedirect, prefetchRscResponse, pushHistoryStateWithoutNotify, redirect, renderServerInsertedHTML, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveCachedRscResponseExpiresAt, resolveCachedRscResponseTtlMs, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, setClientParams, setMountedSlotsHeader, setNavigationContext, setPendingPathname, snapshotRscResponse, storePrefetchResponse, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useClientNavigationRenderSnapshot, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
|
|
286
|
+
export { BailoutToCSRError, CachedRscResponse, ClientNavigationRenderSnapshot, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, type NavigationContext, type NavigationStateAccessors, PREFETCH_CACHE_TTL, PrefetchCacheEntry, PrefetchOptions, ReadonlyURLSearchParams, RedirectType, type SegmentMap, ServerInsertedHTMLContext, UnrecognizedActionError, __basePath, _registerStateAccessors, activateNavigationSnapshot, appRouterInstance, applyAppRouterScrollFallback, clearPendingPathname, clearServerInsertedHTML, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, decodeRedirectError, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getClientNavigationRenderContext, getClientNavigationState, getClientParams, getCurrentInterceptionContext, getCurrentNextUrl, getLayoutSegmentContext, getMountedSlotsHeader, getNavigationContext, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, invalidatePrefetchCache, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, navigateClientSide, notFound, permanentRedirect, prefetchRscResponse, pushHistoryStateWithoutNotify, redirect, renderServerInsertedHTML, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveCachedRscResponseExpiresAt, resolveCachedRscResponseTtlMs, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, setClientParams, setMountedSlotsHeader, setNavigationContext, setPendingPathname, snapshotRscResponse, storePrefetchResponse, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useClientNavigationRenderSnapshot, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
|