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
package/dist/shims/navigation.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { stripBasePath } from "../utils/base-path.js";
|
|
2
2
|
import { VINEXT_DYNAMIC_STALE_TIME_HEADER, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_PARAMS_HEADER } from "../server/headers.js";
|
|
3
3
|
import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
4
|
-
import { markPprFallbackShellDynamicBoundary } from "./ppr-fallback-shell.js";
|
|
5
4
|
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
6
5
|
import "../server/app-elements.js";
|
|
6
|
+
import { markPprFallbackShellDynamicBoundary } from "./ppr-fallback-shell.js";
|
|
7
7
|
import { AppRouterContext } from "./internal/app-router-context.js";
|
|
8
8
|
import { resolveHybridClientRouteOwner } from "./internal/hybrid-client-route-owner.js";
|
|
9
9
|
import { isAbsoluteOrProtocolRelativeUrl, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
10
10
|
import { retryScrollTo, scrollToHashTarget } from "./hash-scroll.js";
|
|
11
|
+
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
12
|
+
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";
|
|
13
|
+
import { clearAppNavigationFailureTarget, stageAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
|
|
14
|
+
import { beginAppRouterScrollIntent, clearAppRouterScrollIntent, consumeAppRouterScrollIntent, getPendingAppRouterScrollIntent } from "./app-router-scroll-state.js";
|
|
15
|
+
import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam } from "../server/app-rsc-cache-busting.js";
|
|
11
16
|
import { getNavigationRuntime, hasAppNavigationRuntime } from "../client/navigation-runtime.js";
|
|
12
17
|
import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
|
|
13
|
-
import { clearAppNavigationFailureTarget, stageAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
|
|
14
18
|
import { PUBLIC_INITIAL_BFCACHE_ID } from "../server/app-bfcache-id.js";
|
|
15
|
-
import { resolveManifestNavigationInterceptionContext } from "../server/app-browser-interception-context.js";
|
|
16
19
|
import { createExternalHistoryStatePreservingMetadata, createHashOnlyHistoryStatePreservingNavigationMetadata } from "../server/app-history-state.js";
|
|
17
|
-
import {
|
|
20
|
+
import { resolveManifestNavigationInterceptionContext } from "../server/app-browser-interception-context.js";
|
|
18
21
|
import { hasPendingAppRouterPageRedirect } from "../server/app-browser-mpa-navigation.js";
|
|
19
22
|
import { navigationPlanner } from "../server/navigation-planner.js";
|
|
20
23
|
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
21
24
|
import { getPagesNavigationContext } from "./internal/pages-router-accessor.js";
|
|
22
|
-
import { beginAppRouterScrollIntent, clearAppRouterScrollIntent, consumeAppRouterScrollIntent, getPendingAppRouterScrollIntent } from "./app-router-scroll-state.js";
|
|
23
25
|
import { UnrecognizedActionError, unstable_isUnrecognizedActionError } from "./unrecognized-action-error.js";
|
|
24
26
|
import * as React$1 from "react";
|
|
25
27
|
//#region src/shims/navigation.ts
|
|
@@ -30,39 +32,6 @@ import * as React$1 from "react";
|
|
|
30
32
|
* Server-side: reads from a request context set by the RSC handler.
|
|
31
33
|
* Client-side: reads from browser Location API and provides navigation.
|
|
32
34
|
*/
|
|
33
|
-
const _LAYOUT_SEGMENT_CTX_KEY = Symbol.for("vinext.layoutSegmentContext");
|
|
34
|
-
const _SERVER_INSERTED_HTML_CTX_KEY = Symbol.for("vinext.serverInsertedHTMLContext");
|
|
35
|
-
const _BFCACHE_ID_MAP_CTX_KEY = Symbol.for("vinext.bfcacheIdMapContext");
|
|
36
|
-
const _BFCACHE_SEGMENT_ID_CTX_KEY = Symbol.for("vinext.bfcacheSegmentIdContext");
|
|
37
|
-
function getServerInsertedHTMLContext() {
|
|
38
|
-
if (typeof React$1.createContext !== "function") return null;
|
|
39
|
-
const globalState = globalThis;
|
|
40
|
-
if (!globalState[_SERVER_INSERTED_HTML_CTX_KEY]) globalState[_SERVER_INSERTED_HTML_CTX_KEY] = React$1.createContext(null);
|
|
41
|
-
return globalState[_SERVER_INSERTED_HTML_CTX_KEY] ?? null;
|
|
42
|
-
}
|
|
43
|
-
const ServerInsertedHTMLContext = getServerInsertedHTMLContext();
|
|
44
|
-
/**
|
|
45
|
-
* Get or create the layout segment context.
|
|
46
|
-
* Returns null in the RSC environment (createContext unavailable).
|
|
47
|
-
*/
|
|
48
|
-
function getLayoutSegmentContext() {
|
|
49
|
-
if (typeof React$1.createContext !== "function") return null;
|
|
50
|
-
const globalState = globalThis;
|
|
51
|
-
if (!globalState[_LAYOUT_SEGMENT_CTX_KEY]) globalState[_LAYOUT_SEGMENT_CTX_KEY] = React$1.createContext({ children: [] });
|
|
52
|
-
return globalState[_LAYOUT_SEGMENT_CTX_KEY] ?? null;
|
|
53
|
-
}
|
|
54
|
-
function getBfcacheIdMapContext() {
|
|
55
|
-
if (typeof React$1.createContext !== "function") return null;
|
|
56
|
-
const globalState = globalThis;
|
|
57
|
-
if (!globalState[_BFCACHE_ID_MAP_CTX_KEY]) globalState[_BFCACHE_ID_MAP_CTX_KEY] = React$1.createContext(null);
|
|
58
|
-
return globalState[_BFCACHE_ID_MAP_CTX_KEY] ?? null;
|
|
59
|
-
}
|
|
60
|
-
function getBfcacheSegmentIdContext() {
|
|
61
|
-
if (typeof React$1.createContext !== "function") return null;
|
|
62
|
-
const globalState = globalThis;
|
|
63
|
-
if (!globalState[_BFCACHE_SEGMENT_ID_CTX_KEY]) globalState[_BFCACHE_SEGMENT_ID_CTX_KEY] = React$1.createContext(null);
|
|
64
|
-
return globalState[_BFCACHE_SEGMENT_ID_CTX_KEY] ?? null;
|
|
65
|
-
}
|
|
66
35
|
/**
|
|
67
36
|
* Read the child segments for a parallel route below the current layout.
|
|
68
37
|
* Returns [] if no context is available (RSC environment, outside React tree)
|
|
@@ -80,77 +49,7 @@ function useChildSegments(parallelRoutesKey = "children") {
|
|
|
80
49
|
const _READONLY_SEARCH_PARAMS = Symbol("vinext.navigation.readonlySearchParams");
|
|
81
50
|
const _READONLY_SEARCH_PARAMS_SOURCE = Symbol("vinext.navigation.readonlySearchParamsSource");
|
|
82
51
|
const _READONLY_SEARCH_PARAMS_SOURCE_KEY = Symbol("vinext.navigation.readonlySearchParamsSourceKey");
|
|
83
|
-
const GLOBAL_ACCESSORS_KEY = Symbol.for("vinext.navigation.globalAccessors");
|
|
84
|
-
const _GLOBAL_ACCESSORS_KEY = GLOBAL_ACCESSORS_KEY;
|
|
85
|
-
const _GLOBAL_HYDRATION_CONTEXT_KEY = Symbol.for("vinext.navigation.clientHydrationContext");
|
|
86
|
-
function _getGlobalAccessors() {
|
|
87
|
-
return globalThis[_GLOBAL_ACCESSORS_KEY];
|
|
88
|
-
}
|
|
89
|
-
function _getClientHydrationContext() {
|
|
90
|
-
const globalState = globalThis;
|
|
91
|
-
if (Object.prototype.hasOwnProperty.call(globalState, _GLOBAL_HYDRATION_CONTEXT_KEY)) return globalState[_GLOBAL_HYDRATION_CONTEXT_KEY] ?? null;
|
|
92
|
-
}
|
|
93
|
-
function _setClientHydrationContext(ctx) {
|
|
94
|
-
globalThis[_GLOBAL_HYDRATION_CONTEXT_KEY] = ctx;
|
|
95
|
-
}
|
|
96
|
-
function clearClientHydrationContext() {
|
|
97
|
-
if (typeof window !== "undefined") _setClientHydrationContext(null);
|
|
98
|
-
}
|
|
99
|
-
let _serverContext = null;
|
|
100
|
-
let _serverInsertedHTMLCallbacks = [];
|
|
101
|
-
let _getServerContext = () => {
|
|
102
|
-
if (typeof window !== "undefined") {
|
|
103
|
-
const hydrationContext = _getClientHydrationContext();
|
|
104
|
-
return hydrationContext !== void 0 ? hydrationContext : _serverContext;
|
|
105
|
-
}
|
|
106
|
-
const g = _getGlobalAccessors();
|
|
107
|
-
return g ? g.getServerContext() : _serverContext;
|
|
108
|
-
};
|
|
109
|
-
let _setServerContext = (ctx) => {
|
|
110
|
-
if (typeof window !== "undefined") {
|
|
111
|
-
_serverContext = ctx;
|
|
112
|
-
_setClientHydrationContext(ctx);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const g = _getGlobalAccessors();
|
|
116
|
-
if (g) g.setServerContext(ctx);
|
|
117
|
-
else _serverContext = ctx;
|
|
118
|
-
};
|
|
119
|
-
let _getInsertedHTMLCallbacks = () => {
|
|
120
|
-
const g = _getGlobalAccessors();
|
|
121
|
-
return g ? g.getInsertedHTMLCallbacks() : _serverInsertedHTMLCallbacks;
|
|
122
|
-
};
|
|
123
|
-
let _clearInsertedHTMLCallbacks = () => {
|
|
124
|
-
const g = _getGlobalAccessors();
|
|
125
|
-
if (g) g.clearInsertedHTMLCallbacks();
|
|
126
|
-
else _serverInsertedHTMLCallbacks = [];
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* Register ALS-backed state accessors. Called by navigation-state.ts on import.
|
|
130
|
-
* @internal
|
|
131
|
-
*/
|
|
132
|
-
function _registerStateAccessors(accessors) {
|
|
133
|
-
_getServerContext = accessors.getServerContext;
|
|
134
|
-
_setServerContext = accessors.setServerContext;
|
|
135
|
-
_getInsertedHTMLCallbacks = accessors.getInsertedHTMLCallbacks;
|
|
136
|
-
_clearInsertedHTMLCallbacks = accessors.clearInsertedHTMLCallbacks;
|
|
137
|
-
}
|
|
138
52
|
const PAGES_NAVIGATION_NOTIFY_KEY = Symbol.for("vinext.navigation.pagesNavigationNotify");
|
|
139
|
-
/**
|
|
140
|
-
* Get the navigation context for the current SSR/RSC render.
|
|
141
|
-
* Reads from AsyncLocalStorage when available (concurrent-safe),
|
|
142
|
-
* otherwise falls back to module-level state.
|
|
143
|
-
*/
|
|
144
|
-
function getNavigationContext() {
|
|
145
|
-
return _getServerContext();
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Set the navigation context for the current SSR/RSC render.
|
|
149
|
-
* Called by the framework entry before rendering each request.
|
|
150
|
-
*/
|
|
151
|
-
function setNavigationContext(ctx) {
|
|
152
|
-
_setServerContext(ctx);
|
|
153
|
-
}
|
|
154
53
|
const isServer = typeof window === "undefined";
|
|
155
54
|
/** basePath from next.config.js, injected by the plugin at build time */
|
|
156
55
|
const __basePath = process.env.__NEXT_ROUTER_BASEPATH ?? "";
|
|
@@ -625,7 +524,7 @@ let _cachedEmptyClientSearchParams = null;
|
|
|
625
524
|
* be visible until the next commit.
|
|
626
525
|
*/
|
|
627
526
|
function getSearchParamsSnapshot() {
|
|
628
|
-
if (
|
|
527
|
+
if (getNavigationContext()) return getServerSearchParamsSnapshot();
|
|
629
528
|
const pagesCtx = getPagesNavigationContext();
|
|
630
529
|
if (pagesCtx) return getReadonlyPagesSearchParams(pagesCtx.searchParams);
|
|
631
530
|
const cached = getClientNavigationState()?.cachedReadonlySearchParams;
|
|
@@ -651,7 +550,7 @@ function syncCommittedUrlStateFromLocation() {
|
|
|
651
550
|
return changed;
|
|
652
551
|
}
|
|
653
552
|
function getServerSearchParamsSnapshot() {
|
|
654
|
-
const ctx =
|
|
553
|
+
const ctx = getNavigationContext();
|
|
655
554
|
if (!ctx) {
|
|
656
555
|
const pagesCtx = getPagesNavigationContext();
|
|
657
556
|
if (pagesCtx) return getReadonlyPagesSearchParams(pagesCtx.searchParams);
|
|
@@ -776,14 +675,14 @@ function clearPendingPathname(navId) {
|
|
|
776
675
|
}
|
|
777
676
|
function getClientParamsSnapshot() {
|
|
778
677
|
const state = getClientNavigationState();
|
|
779
|
-
const ctx =
|
|
678
|
+
const ctx = getNavigationContext();
|
|
780
679
|
if (ctx) return ctx.params;
|
|
781
680
|
const pagesCtx = getPagesNavigationContext();
|
|
782
681
|
if (pagesCtx) return pagesCtx.params;
|
|
783
682
|
return state?.clientParams ?? _EMPTY_PARAMS;
|
|
784
683
|
}
|
|
785
684
|
function getServerParamsSnapshot() {
|
|
786
|
-
const ctx =
|
|
685
|
+
const ctx = getNavigationContext();
|
|
787
686
|
if (ctx) return ctx.params;
|
|
788
687
|
const pagesCtx = getPagesNavigationContext();
|
|
789
688
|
if (pagesCtx) return pagesCtx.params;
|
|
@@ -804,14 +703,14 @@ function subscribeToNavigation(cb) {
|
|
|
804
703
|
function usePathname() {
|
|
805
704
|
if (isServer) {
|
|
806
705
|
markPprFallbackShellDynamicBoundary();
|
|
807
|
-
const ctx =
|
|
706
|
+
const ctx = getNavigationContext();
|
|
808
707
|
if (ctx) return ctx.pathname;
|
|
809
708
|
const pagesCtx = getPagesNavigationContext();
|
|
810
709
|
return pagesCtx ? pagesCtx.pathname : "/";
|
|
811
710
|
}
|
|
812
711
|
const renderSnapshot = useClientNavigationRenderSnapshot();
|
|
813
712
|
const pathname = React$1.useSyncExternalStore(subscribeToNavigation, getPathnameSnapshot, () => {
|
|
814
|
-
const ctx =
|
|
713
|
+
const ctx = getNavigationContext();
|
|
815
714
|
if (ctx) return ctx.pathname;
|
|
816
715
|
const pagesCtx = getPagesNavigationContext();
|
|
817
716
|
return pagesCtx ? pagesCtx.pathname : "/";
|
|
@@ -1084,6 +983,7 @@ const _appRouter = {
|
|
|
1084
983
|
push(href, options) {
|
|
1085
984
|
assertSafeNavigationUrl(href);
|
|
1086
985
|
if (isServer) return;
|
|
986
|
+
getNavigationRuntime()?.functions.notifyLinkNavigationStart?.();
|
|
1087
987
|
const releaseNavigation = trackScheduledAppRouterNavigation();
|
|
1088
988
|
try {
|
|
1089
989
|
React$1.startTransition(() => {
|
|
@@ -1098,6 +998,7 @@ const _appRouter = {
|
|
|
1098
998
|
replace(href, options) {
|
|
1099
999
|
assertSafeNavigationUrl(href);
|
|
1100
1000
|
if (isServer) return;
|
|
1001
|
+
getNavigationRuntime()?.functions.notifyLinkNavigationStart?.();
|
|
1101
1002
|
const releaseNavigation = trackScheduledAppRouterNavigation();
|
|
1102
1003
|
try {
|
|
1103
1004
|
React$1.startTransition(() => {
|
|
@@ -1270,337 +1171,7 @@ function useSelectedLayoutSegments(parallelRoutesKey) {
|
|
|
1270
1171
|
*/
|
|
1271
1172
|
function useServerInsertedHTML(callback) {
|
|
1272
1173
|
if (typeof document !== "undefined") return;
|
|
1273
|
-
|
|
1274
|
-
}
|
|
1275
|
-
/**
|
|
1276
|
-
* Flush all collected useServerInsertedHTML callbacks.
|
|
1277
|
-
* Returns an array of results (React elements or strings).
|
|
1278
|
-
* Clears the callback list so the next render starts fresh.
|
|
1279
|
-
*
|
|
1280
|
-
* Called by the SSR entry after renderToReadableStream completes.
|
|
1281
|
-
*/
|
|
1282
|
-
function flushServerInsertedHTML() {
|
|
1283
|
-
const callbacks = _getInsertedHTMLCallbacks();
|
|
1284
|
-
const results = [];
|
|
1285
|
-
for (const cb of callbacks) try {
|
|
1286
|
-
const result = cb();
|
|
1287
|
-
if (result != null) results.push(result);
|
|
1288
|
-
} catch {}
|
|
1289
|
-
callbacks.length = 0;
|
|
1290
|
-
return results;
|
|
1291
|
-
}
|
|
1292
|
-
/**
|
|
1293
|
-
* Render collected useServerInsertedHTML callbacks without unregistering them.
|
|
1294
|
-
*
|
|
1295
|
-
* Streaming SSR needs to invoke the same style-registry callbacks after each
|
|
1296
|
-
* Fizz flush. Libraries such as styled-components and Emotion clear their own
|
|
1297
|
-
* per-flush buffers inside the callback; the registration itself must survive
|
|
1298
|
-
* until the request stream is closed.
|
|
1299
|
-
*/
|
|
1300
|
-
function renderServerInsertedHTML() {
|
|
1301
|
-
const callbacks = _getInsertedHTMLCallbacks();
|
|
1302
|
-
const results = [];
|
|
1303
|
-
for (const cb of callbacks) try {
|
|
1304
|
-
const result = cb();
|
|
1305
|
-
if (result != null) results.push(result);
|
|
1306
|
-
} catch {}
|
|
1307
|
-
return results;
|
|
1308
|
-
}
|
|
1309
|
-
/**
|
|
1310
|
-
* Clear all collected useServerInsertedHTML callbacks without flushing.
|
|
1311
|
-
* Used for cleanup between requests.
|
|
1312
|
-
*/
|
|
1313
|
-
function clearServerInsertedHTML() {
|
|
1314
|
-
_clearInsertedHTMLCallbacks();
|
|
1315
|
-
}
|
|
1316
|
-
/**
|
|
1317
|
-
* HTTP Access Fallback error code — shared prefix for notFound/forbidden/unauthorized.
|
|
1318
|
-
* Matches Next.js 16's unified error handling approach.
|
|
1319
|
-
*/
|
|
1320
|
-
const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
|
|
1321
|
-
/**
|
|
1322
|
-
* Check if an error is an HTTP Access Fallback error (notFound, forbidden, unauthorized).
|
|
1323
|
-
*/
|
|
1324
|
-
function isHTTPAccessFallbackError(error) {
|
|
1325
|
-
if (error && typeof error === "object" && "digest" in error) {
|
|
1326
|
-
const digest = String(error.digest);
|
|
1327
|
-
return digest === "NEXT_NOT_FOUND" || digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`);
|
|
1328
|
-
}
|
|
1329
|
-
return false;
|
|
1330
|
-
}
|
|
1331
|
-
/**
|
|
1332
|
-
* Extract the HTTP status code from an HTTP Access Fallback error.
|
|
1333
|
-
* Returns 404 for legacy NEXT_NOT_FOUND errors.
|
|
1334
|
-
*/
|
|
1335
|
-
function getAccessFallbackHTTPStatus(error) {
|
|
1336
|
-
if (error && typeof error === "object" && "digest" in error) {
|
|
1337
|
-
const digest = String(error.digest);
|
|
1338
|
-
if (digest === "NEXT_NOT_FOUND") return 404;
|
|
1339
|
-
if (digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`)) return parseInt(digest.split(";")[1], 10);
|
|
1340
|
-
}
|
|
1341
|
-
return 404;
|
|
1342
|
-
}
|
|
1343
|
-
/**
|
|
1344
|
-
* Enum matching Next.js RedirectType for type-safe redirect calls.
|
|
1345
|
-
*/
|
|
1346
|
-
let RedirectType = /* @__PURE__ */ function(RedirectType) {
|
|
1347
|
-
RedirectType["push"] = "push";
|
|
1348
|
-
RedirectType["replace"] = "replace";
|
|
1349
|
-
return RedirectType;
|
|
1350
|
-
}({});
|
|
1351
|
-
/**
|
|
1352
|
-
* Internal error class used by redirect/notFound/forbidden/unauthorized.
|
|
1353
|
-
* The `digest` field is the serialised control-flow signal read by the
|
|
1354
|
-
* framework's error boundary and server-side request handlers.
|
|
1355
|
-
*/
|
|
1356
|
-
var VinextNavigationError = class extends Error {
|
|
1357
|
-
digest;
|
|
1358
|
-
constructor(message, digest) {
|
|
1359
|
-
super(message);
|
|
1360
|
-
this.digest = digest;
|
|
1361
|
-
}
|
|
1362
|
-
};
|
|
1363
|
-
/**
|
|
1364
|
-
* Throw a redirect. Caught by the framework to send a redirect response.
|
|
1365
|
-
*
|
|
1366
|
-
* When `type` is omitted, the digest carries an empty sentinel so the
|
|
1367
|
-
* catch site can resolve the default based on context:
|
|
1368
|
-
* - Server Action context → "push" (Back button works after form submission)
|
|
1369
|
-
* - SSR render context → "replace"
|
|
1370
|
-
*
|
|
1371
|
-
* This matches Next.js behavior where `redirect()` checks
|
|
1372
|
-
* `actionAsyncStorage.getStore()?.isAction` at call time.
|
|
1373
|
-
*
|
|
1374
|
-
* @see https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect.ts
|
|
1375
|
-
*/
|
|
1376
|
-
function redirect(url, type) {
|
|
1377
|
-
throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type ?? ""};${encodeURIComponent(url)}`);
|
|
1378
|
-
}
|
|
1379
|
-
/**
|
|
1380
|
-
* Trigger a permanent redirect (308).
|
|
1381
|
-
*
|
|
1382
|
-
* Accepts an optional `type` parameter matching Next.js's signature.
|
|
1383
|
-
* Defaults to "replace" (not context-dependent like `redirect()`).
|
|
1384
|
-
*
|
|
1385
|
-
* @see https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect.ts
|
|
1386
|
-
*/
|
|
1387
|
-
function permanentRedirect(url, type = "replace") {
|
|
1388
|
-
throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type};${encodeURIComponent(url)};308`);
|
|
1389
|
-
}
|
|
1390
|
-
/**
|
|
1391
|
-
* Trigger a not-found response (404). Caught by the framework.
|
|
1392
|
-
*/
|
|
1393
|
-
function notFound() {
|
|
1394
|
-
throw new VinextNavigationError("NEXT_NOT_FOUND", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);
|
|
1395
|
-
}
|
|
1396
|
-
/**
|
|
1397
|
-
* Trigger a forbidden response (403). Caught by the framework.
|
|
1398
|
-
* In Next.js, this is gated behind experimental.authInterrupts — we
|
|
1399
|
-
* support it unconditionally for maximum compatibility.
|
|
1400
|
-
*/
|
|
1401
|
-
function forbidden() {
|
|
1402
|
-
throw new VinextNavigationError("NEXT_FORBIDDEN", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);
|
|
1403
|
-
}
|
|
1404
|
-
/**
|
|
1405
|
-
* Trigger an unauthorized response (401). Caught by the framework.
|
|
1406
|
-
* In Next.js, this is gated behind experimental.authInterrupts — we
|
|
1407
|
-
* support it unconditionally for maximum compatibility.
|
|
1408
|
-
*/
|
|
1409
|
-
function unauthorized() {
|
|
1410
|
-
throw new VinextNavigationError("NEXT_UNAUTHORIZED", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Check whether an error was produced by `redirect()` or `permanentRedirect()`.
|
|
1414
|
-
*
|
|
1415
|
-
* **Note on vinext public surface:** Next.js does NOT expose `isRedirectError`
|
|
1416
|
-
* from `next/navigation` — it's an internal predicate. vinext exposes it for
|
|
1417
|
-
* symmetry with the already-public `isHTTPAccessFallbackError` and because
|
|
1418
|
-
* `unstable_rethrow` consumers benefit from being able to narrow types.
|
|
1419
|
-
* Treat it as a vinext-only extension.
|
|
1420
|
-
*
|
|
1421
|
-
* **Divergence from Next.js:** Next.js's internal `isRedirectError` performs
|
|
1422
|
-
* full 4-segment validation — it splits the digest on `;`, checks `type` ∈
|
|
1423
|
-
* {push, replace}, requires a non-empty destination, and validates the
|
|
1424
|
-
* status code (303, 307, 308). See:
|
|
1425
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect-error.ts
|
|
1426
|
-
*
|
|
1427
|
-
* vinext instead uses a simple prefix check (`startsWith("NEXT_REDIRECT;")`).
|
|
1428
|
-
* Reasons:
|
|
1429
|
-
* 1. vinext emits two digest shapes — 3-part for `redirect()`
|
|
1430
|
-
* (`NEXT_REDIRECT;{type};{encoded-url}`) and 4-part for
|
|
1431
|
-
* `permanentRedirect()` (`NEXT_REDIRECT;{type};{encoded-url};308`).
|
|
1432
|
-
* Strict validation would have to special-case both, and Next.js's
|
|
1433
|
-
* validator (tuned to its 5-part canary digests) rejects them.
|
|
1434
|
-
* 2. The `type` field is sometimes empty in vinext's redirect digests
|
|
1435
|
-
* (context-dependent resolution; see `redirect()` above), which the
|
|
1436
|
-
* strict check disallows.
|
|
1437
|
-
*
|
|
1438
|
-
* **Consequence:** A malformed digest such as `"NEXT_REDIRECT;garbage"`
|
|
1439
|
-
* returns `true` here, whereas Next.js would return `false`. In practice,
|
|
1440
|
-
* the only callers of this predicate are vinext-internal code paths
|
|
1441
|
-
* (`unstable_rethrow`, `unstable_catchError`, the redirect error boundary)
|
|
1442
|
-
* that see digests vinext itself emits — so the divergence does not surface
|
|
1443
|
-
* in normal use. Maintainers extending the prefix logic should keep this
|
|
1444
|
-
* predicate in lockstep with the corresponding `decode*` helpers in
|
|
1445
|
-
* `shims/error-boundary.tsx`.
|
|
1446
|
-
*/
|
|
1447
|
-
function isRedirectError(error) {
|
|
1448
|
-
if (!error || typeof error !== "object") return false;
|
|
1449
|
-
if (!("digest" in error)) return false;
|
|
1450
|
-
if (typeof error.digest !== "string") return false;
|
|
1451
|
-
return error.digest.startsWith("NEXT_REDIRECT;");
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Parse a redirect error digest into its URL and type components.
|
|
1455
|
-
*
|
|
1456
|
-
* Supports two formats:
|
|
1457
|
-
* - vinext's 3-part: `NEXT_REDIRECT;{type};{encoded-url}`
|
|
1458
|
-
* - Next.js's 5-part: `NEXT_REDIRECT;{type};{url};{status};{isClient}`
|
|
1459
|
-
*
|
|
1460
|
-
* The URL segment is always percent-encoded on the write side
|
|
1461
|
-
* (encodeURIComponent is used), so re-joining with ";" for the 5-part
|
|
1462
|
-
* format is defensive — it correctly handles any unencoded ";" that
|
|
1463
|
-
* might appear in an externally-sourced digest.
|
|
1464
|
-
*
|
|
1465
|
-
* Returns null for malformed digests that have an empty URL segment, or
|
|
1466
|
-
* when the URL contains invalid percent-encoding.
|
|
1467
|
-
*/
|
|
1468
|
-
function decodeRedirectError(digest) {
|
|
1469
|
-
if (!digest.startsWith("NEXT_REDIRECT;")) return null;
|
|
1470
|
-
const parts = digest.split(";");
|
|
1471
|
-
const encodedTarget = parts.length >= 5 ? parts.slice(2, -2).join(";") : parts[2];
|
|
1472
|
-
if (!encodedTarget) return null;
|
|
1473
|
-
let url;
|
|
1474
|
-
try {
|
|
1475
|
-
url = decodeURIComponent(encodedTarget);
|
|
1476
|
-
} catch {
|
|
1477
|
-
return null;
|
|
1478
|
-
}
|
|
1479
|
-
const type = parts[1] === "push" ? "push" : "replace";
|
|
1480
|
-
return {
|
|
1481
|
-
url,
|
|
1482
|
-
type
|
|
1483
|
-
};
|
|
1484
|
-
}
|
|
1485
|
-
/**
|
|
1486
|
-
* Returns true if the error is a Next.js navigation signal — either a redirect
|
|
1487
|
-
* or an HTTP access fallback (notFound / forbidden / unauthorized).
|
|
1488
|
-
*
|
|
1489
|
-
* **Note on vinext public surface:** Like `isRedirectError`, Next.js does NOT
|
|
1490
|
-
* expose this from `next/navigation`. vinext exposes it for symmetry — treat
|
|
1491
|
-
* it as a vinext-only extension.
|
|
1492
|
-
*
|
|
1493
|
-
* Ported from Next.js:
|
|
1494
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/is-next-router-error.ts
|
|
1495
|
-
*/
|
|
1496
|
-
function isNextRouterError(error) {
|
|
1497
|
-
return isRedirectError(error) || isHTTPAccessFallbackError(error);
|
|
1498
|
-
}
|
|
1499
|
-
const _BAILOUT_TO_CSR_DIGEST = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
|
|
1500
|
-
/**
|
|
1501
|
-
* Error thrown to bail out of server rendering and fall back to client-side
|
|
1502
|
-
* rendering. Used by `next/dynamic` with `ssr: false`.
|
|
1503
|
-
*
|
|
1504
|
-
* vinext does not yet emit this error itself — it's exposed so user code and
|
|
1505
|
-
* third-party libraries that mimic `next/dynamic`'s bailout semantics can
|
|
1506
|
-
* construct an error with the canonical digest that `unstable_rethrow`
|
|
1507
|
-
* recognises.
|
|
1508
|
-
*
|
|
1509
|
-
* Ported 1:1 from Next.js:
|
|
1510
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/lazy-dynamic/bailout-to-csr.ts
|
|
1511
|
-
*/
|
|
1512
|
-
var BailoutToCSRError = class extends Error {
|
|
1513
|
-
digest = _BAILOUT_TO_CSR_DIGEST;
|
|
1514
|
-
reason;
|
|
1515
|
-
constructor(reason) {
|
|
1516
|
-
super(`Bail out to client-side rendering: ${reason}`);
|
|
1517
|
-
this.reason = reason;
|
|
1518
|
-
}
|
|
1519
|
-
};
|
|
1520
|
-
/**
|
|
1521
|
-
* Returns true if the error is a `BailoutToCSRError`. Matches Next.js's
|
|
1522
|
-
* digest-based predicate, so any error from a foreign module instance of
|
|
1523
|
-
* the class (or constructed manually with the canonical digest) is also
|
|
1524
|
-
* detected.
|
|
1525
|
-
*
|
|
1526
|
-
* **Note on vinext public surface:** Next.js does NOT expose this from
|
|
1527
|
-
* `next/navigation`. vinext exposes it for symmetry with `isRedirectError`
|
|
1528
|
-
* — treat it as a vinext-only extension. The matching producer
|
|
1529
|
-
* (`BailoutToCSRError`) is the public detection contract; Next.js exposes
|
|
1530
|
-
* neither.
|
|
1531
|
-
*
|
|
1532
|
-
* Ported from Next.js:
|
|
1533
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/lazy-dynamic/bailout-to-csr.ts
|
|
1534
|
-
*/
|
|
1535
|
-
function isBailoutToCSRError(error) {
|
|
1536
|
-
if (!error || typeof error !== "object" || !("digest" in error)) return false;
|
|
1537
|
-
return error.digest === _BAILOUT_TO_CSR_DIGEST;
|
|
1538
|
-
}
|
|
1539
|
-
const _DYNAMIC_SERVER_USAGE_DIGEST = "DYNAMIC_SERVER_USAGE";
|
|
1540
|
-
/**
|
|
1541
|
-
* Error thrown when dynamic server APIs (`cookies()`, `headers()`, etc.) are
|
|
1542
|
-
* used inside a static/prerender context. Carries the `DYNAMIC_SERVER_USAGE`
|
|
1543
|
-
* digest so `unstable_rethrow` can recognise and propagate it.
|
|
1544
|
-
*
|
|
1545
|
-
* vinext does not construct this error itself — exposed for the same
|
|
1546
|
-
* "stable detection contract" reason as `BailoutToCSRError` above.
|
|
1547
|
-
*
|
|
1548
|
-
* Ported 1:1 from Next.js:
|
|
1549
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/hooks-server-context.ts
|
|
1550
|
-
*/
|
|
1551
|
-
var DynamicServerError = class extends Error {
|
|
1552
|
-
digest = _DYNAMIC_SERVER_USAGE_DIGEST;
|
|
1553
|
-
description;
|
|
1554
|
-
constructor(description) {
|
|
1555
|
-
super(`Dynamic server usage: ${description}`);
|
|
1556
|
-
this.description = description;
|
|
1557
|
-
}
|
|
1558
|
-
};
|
|
1559
|
-
/**
|
|
1560
|
-
* Returns true if the error is a `DynamicServerError` (or any error with the
|
|
1561
|
-
* canonical `DYNAMIC_SERVER_USAGE` digest).
|
|
1562
|
-
*
|
|
1563
|
-
* **Note on vinext public surface:** Next.js does NOT expose this from
|
|
1564
|
-
* `next/navigation`. vinext exposes it for symmetry — treat it as a
|
|
1565
|
-
* vinext-only extension.
|
|
1566
|
-
*
|
|
1567
|
-
* Ported from Next.js:
|
|
1568
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/hooks-server-context.ts
|
|
1569
|
-
*/
|
|
1570
|
-
function isDynamicServerError(error) {
|
|
1571
|
-
if (!error || typeof error !== "object" || !("digest" in error)) return false;
|
|
1572
|
-
return error.digest === _DYNAMIC_SERVER_USAGE_DIGEST;
|
|
1573
|
-
}
|
|
1574
|
-
/**
|
|
1575
|
-
* Rethrow internal Next.js errors so they're handled by the framework.
|
|
1576
|
-
*
|
|
1577
|
-
* When wrapping an API that uses errors for control flow (redirect, notFound,
|
|
1578
|
-
* cookies in static render, `next/dynamic` SSR bailout, etc.), call this
|
|
1579
|
-
* inside `catch` blocks before doing your own error handling. If the error
|
|
1580
|
-
* is a Next.js internal error, it's rethrown; otherwise this is a no-op
|
|
1581
|
-
* (apart from recursing through `error.cause`).
|
|
1582
|
-
*
|
|
1583
|
-
* Recognises (matches Next.js's browser build + the subset of the server
|
|
1584
|
-
* build that vinext can realistically encounter):
|
|
1585
|
-
* - `isNextRouterError`: redirect / notFound / forbidden / unauthorized
|
|
1586
|
-
* - `isBailoutToCSRError`: `next/dynamic` `ssr: false` bailout
|
|
1587
|
-
* - `isDynamicServerError`: dynamic API used in static render
|
|
1588
|
-
*
|
|
1589
|
-
* vinext does not yet recognise four additional server-only Next.js
|
|
1590
|
-
* categories — `isDynamicPostpone`, `isPostpone`,
|
|
1591
|
-
* `isHangingPromiseRejectionError`, `isPrerenderInterruptedError` — because
|
|
1592
|
-
* they signal PPR / prerender-controller events that vinext's render
|
|
1593
|
-
* pipeline does not generate. User code cannot construct these in normal
|
|
1594
|
-
* use; they will be added if/when vinext grows PPR support.
|
|
1595
|
-
*
|
|
1596
|
-
* Ported from Next.js:
|
|
1597
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/unstable-rethrow.ts
|
|
1598
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/unstable-rethrow.server.ts
|
|
1599
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/unstable-rethrow.browser.ts
|
|
1600
|
-
*/
|
|
1601
|
-
function unstable_rethrow(error) {
|
|
1602
|
-
if (isNextRouterError(error) || isBailoutToCSRError(error) || isDynamicServerError(error)) throw error;
|
|
1603
|
-
if (error instanceof Error && "cause" in error) unstable_rethrow(error.cause);
|
|
1174
|
+
registerServerInsertedHTMLCallback(callback);
|
|
1604
1175
|
}
|
|
1605
1176
|
if (!isServer) {
|
|
1606
1177
|
const state = getClientNavigationState();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { GLOBAL_ACCESSORS_KEY, NavigationContext, SegmentMap, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, getLayoutSegmentContext, getNavigationContext, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
3
|
+
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";
|
|
4
4
|
//#region src/shims/navigation.react-server.d.ts
|
|
5
5
|
declare function usePathname(): never;
|
|
6
6
|
declare function useSearchParams(): never;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, getLayoutSegmentContext, getNavigationContext, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
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
|
+
import "./navigation-server.js";
|
|
1
4
|
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
2
|
-
import { BailoutToCSRError, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getLayoutSegmentContext, getNavigationContext, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, renderServerInsertedHTML, setNavigationContext, unauthorized, unstable_rethrow } from "./navigation.js";
|
|
3
5
|
import { throwClientHookError } from "./client-hook-error.js";
|
|
4
6
|
//#region src/shims/navigation.react-server.ts
|
|
5
7
|
function usePathname() {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CacheLifeConfig, CacheState } from "./cache-request-state.js";
|
|
2
2
|
import { ExecutionContextLike } from "./request-context.js";
|
|
3
|
-
import {
|
|
4
|
-
import { NavigationContext } from "./navigation.js";
|
|
3
|
+
import { NavigationContext } from "./navigation-context-state.js";
|
|
5
4
|
import { RootParamsState } from "./root-params.js";
|
|
6
5
|
import { FetchCacheState } from "./fetch-cache.js";
|
|
7
6
|
import { HeadersAccessPhase, HeadersContext, VinextHeadersShimState } from "./headers.js";
|
|
8
7
|
import { RouterState, SSRContext } from "./router-state.js";
|
|
8
|
+
import { PrivateCacheState } from "./cache-runtime.js";
|
|
9
9
|
import { HeadState } from "./head-state.js";
|
|
10
10
|
import { I18nState } from "./i18n-state.js";
|
|
11
11
|
import { NavigationState } from "./navigation-state.js";
|
package/dist/shims/router.d.ts
CHANGED
|
@@ -34,12 +34,15 @@ type NextRouter = {
|
|
|
34
34
|
type UrlObject = {
|
|
35
35
|
pathname?: string;
|
|
36
36
|
query?: UrlQuery;
|
|
37
|
+
search?: string;
|
|
38
|
+
hash?: string;
|
|
37
39
|
};
|
|
38
40
|
type TransitionOptions = {
|
|
39
41
|
_h?: 1;
|
|
40
42
|
shallow?: boolean;
|
|
41
43
|
scroll?: boolean;
|
|
42
44
|
locale?: string | false;
|
|
45
|
+
_vinextInterpolateDynamicRoute?: boolean;
|
|
43
46
|
};
|
|
44
47
|
type RouterEvents = {
|
|
45
48
|
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
@@ -50,7 +53,7 @@ type RouterEvents = {
|
|
|
50
53
|
* Apply locale prefix to a URL for client-side navigation.
|
|
51
54
|
* Same logic as Link's applyLocaleToHref but reads from window globals.
|
|
52
55
|
*/
|
|
53
|
-
declare function applyNavigationLocale(url: string, locale?: string): string;
|
|
56
|
+
declare function applyNavigationLocale(url: string, locale?: string, replaceExistingLocale?: boolean): string;
|
|
54
57
|
/** Check if a URL is external (any URL scheme per RFC 3986, or protocol-relative) */
|
|
55
58
|
declare function isExternalUrl(url: string): boolean;
|
|
56
59
|
/** Check if a href is only a hash change relative to the current URL */
|
|
@@ -110,6 +113,7 @@ type PagesNavigationContextShape = {
|
|
|
110
113
|
declare function getPagesNavigationContext(): PagesNavigationContextShape | null;
|
|
111
114
|
declare function getPagesNavigationIsReadyFromSerializedState(routePattern: string | undefined, searchString: string, nextData?: VinextNextData): boolean;
|
|
112
115
|
declare function markPagesRouterReady(): boolean;
|
|
116
|
+
declare function initializePagesRouterReadyFromNextData(nextData: VinextNextData): void;
|
|
113
117
|
/**
|
|
114
118
|
* useRouter hook - Pages Router compatible.
|
|
115
119
|
*
|
|
@@ -187,4 +191,4 @@ declare const RouterMethods: {
|
|
|
187
191
|
};
|
|
188
192
|
declare const Router: typeof RouterMethods & Omit<NextRouter, keyof typeof RouterMethods>;
|
|
189
193
|
//#endregion
|
|
190
|
-
export { ExcludeRouterProps, NextRouter, WithRouterProps, markPagesRouterReady as _markPagesRouterReady, _registerRouterStateAccessors, applyNavigationLocale, Router as default, getPagesNavigationContext, getPagesNavigationIsReadyFromSerializedState, isExternalUrl, isHashOnlyChange, setSSRContext, useRouter, withRouter, wrapWithRouterContext };
|
|
194
|
+
export { ExcludeRouterProps, NextRouter, WithRouterProps, initializePagesRouterReadyFromNextData as _initializePagesRouterReadyFromNextData, markPagesRouterReady as _markPagesRouterReady, _registerRouterStateAccessors, applyNavigationLocale, Router as default, getPagesNavigationContext, getPagesNavigationIsReadyFromSerializedState, isExternalUrl, isHashOnlyChange, setSSRContext, useRouter, withRouter, wrapWithRouterContext };
|