vinext 1.0.0-beta.12 → 1.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -12
- package/dist/build/action-owner-manifest.js +23 -5
- package/dist/build/lifecycle.d.ts +42 -0
- package/dist/build/lifecycle.js +246 -0
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +0 -3
- package/dist/build/pages-client-assets-module.js +1 -13
- package/dist/build/precompress.js +1 -1
- package/dist/build/prerender-paths.d.ts +1 -1
- package/dist/build/prerender-paths.js +6 -6
- package/dist/build/prerender-server-pool.js +1 -1
- package/dist/build/prerender.d.ts +1 -1
- package/dist/build/prerender.js +5 -5
- package/dist/build/preview-credentials.d.ts +1 -1
- package/dist/build/preview-credentials.js +2 -2
- package/dist/build/report.js +1 -1
- package/dist/build/run-prerender.d.ts +2 -2
- package/dist/build/run-prerender.js +5 -5
- package/dist/build/standalone.js +2 -2
- package/dist/cli-args.d.ts +5 -13
- package/dist/cli-args.js +2 -45
- package/dist/cli-dev-config.d.ts +6 -2
- package/dist/cli-dev-config.js +160 -3
- package/dist/cli.js +104 -439
- package/dist/config/config-matchers.js +1 -1
- package/dist/config/next-config.d.ts +2 -2
- package/dist/config/next-config.js +5 -5
- package/dist/config/prerender.d.ts +3 -0
- package/dist/config/prerender.js +8 -2
- package/dist/entries/app-browser-entry.js +1 -1
- package/dist/entries/app-rsc-entry.js +1 -1
- package/dist/entries/pages-client-entry.d.ts +1 -0
- package/dist/entries/pages-client-entry.js +17 -2
- package/dist/index.d.ts +6 -8
- package/dist/index.js +262 -101
- package/dist/init-cloudflare.d.ts +3 -2
- package/dist/init-cloudflare.js +117 -5
- package/dist/init-platform.d.ts +2 -0
- package/dist/init-platform.js +9 -3
- package/dist/init.d.ts +7 -5
- package/dist/init.js +41 -22
- package/dist/plugins/dynamic-preload-metadata.js +1 -1
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- package/dist/plugins/fonts.js +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +1 -1
- package/dist/plugins/import-meta-url.js +1 -1
- package/dist/plugins/instrumentation-client.js +1 -1
- package/dist/plugins/og-assets.js +32 -13
- package/dist/plugins/og-harfbuzz.d.ts +24 -0
- package/dist/plugins/og-harfbuzz.js +260 -0
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/require-condition-resolution.js +2 -2
- package/dist/plugins/require-context.js +2 -2
- package/dist/plugins/typeof-window.js +1 -1
- package/dist/plugins/use-cache-callable.d.ts +0 -2
- package/dist/plugins/use-cache-callable.js +8 -16
- package/dist/plugins/worker-image-imports.js +1 -1
- package/dist/routing/app-route-graph.js +1 -1
- package/dist/routing/app-router.js +1 -1
- package/dist/routing/pages-router.js +1 -1
- package/dist/server/app-action-forwarding.js +1 -1
- package/dist/server/app-browser-error.js +1 -1
- package/dist/server/app-elements-wire.js +2 -2
- package/dist/server/app-middleware.js +1 -1
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-dispatch.js +1 -1
- package/dist/server/app-page-element-builder.js +3 -2
- package/dist/server/app-page-probe.js +3 -3
- package/dist/server/app-request-stage-independent-entry.js +2 -2
- package/dist/server/app-route-handler-dispatch.js +1 -1
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-router-entry.js +2 -2
- package/dist/server/app-rsc-handler.d.ts +1 -1
- package/dist/server/app-rsc-handler.js +4 -4
- package/dist/server/app-rsc-response-stage.js +1 -1
- package/dist/server/app-rsc-route-matching.js +1 -1
- package/dist/server/app-server-action-execution.js +4 -4
- package/dist/server/artifact-compatibility.js +1 -1
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/dev-lockfile.d.ts +1 -1
- package/dist/server/dev-lockfile.js +4 -1
- package/dist/server/dev-server.d.ts +1 -1
- package/dist/server/dev-server.js +28 -6
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/isr-cache.js +1 -1
- package/dist/server/metadata-route-response.js +8 -0
- package/dist/server/middleware-runtime.js +3 -3
- package/dist/server/pages-data-route.js +1 -1
- package/dist/server/pages-dev-hydration.d.ts +6 -0
- package/dist/server/pages-dev-hydration.js +19 -7
- package/dist/server/pages-page-data.js +2 -2
- package/dist/server/pages-page-handler.js +1 -1
- package/dist/server/pages-page-response.js +1 -1
- package/dist/server/pages-request-pipeline.js +3 -3
- package/dist/server/pages-request-stage-entry.js +3 -3
- package/dist/server/pages-revalidate.js +1 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.js +7 -7
- package/dist/server/request-pipeline.js +2 -2
- package/dist/server/socket-error-backstop.js +1 -1
- package/dist/shims/cache-callable-runtime.d.ts +38 -0
- package/dist/shims/cache-callable-runtime.js +162 -11
- package/dist/shims/cache-runtime.d.ts +6 -8
- package/dist/shims/cache-runtime.js +82 -22
- package/dist/shims/font-local.js +1 -1
- package/dist/shims/form.js +1 -1
- package/dist/shims/headers.js +2 -2
- package/dist/shims/internal/app-page-props-cache-key.d.ts +29 -0
- package/dist/shims/internal/app-page-props-cache-key.js +53 -1
- package/dist/shims/internal/format-url-object.d.ts +7 -0
- package/dist/shims/internal/format-url-object.js +53 -0
- package/dist/shims/internal/normalize-router-href.d.ts +15 -0
- package/dist/shims/internal/normalize-router-href.js +41 -0
- package/dist/shims/internal/pages-data-target.d.ts +4 -1
- package/dist/shims/internal/pages-data-target.js +28 -35
- package/dist/shims/internal/route-pattern-for-warning.d.ts +2 -2
- package/dist/shims/internal/route-pattern-for-warning.js +3 -3
- package/dist/shims/link.js +31 -92
- package/dist/shims/metadata.js +5 -4
- package/dist/shims/navigation.js +2 -2
- package/dist/shims/router-state.js +1 -1
- package/dist/shims/router.d.ts +8 -7
- package/dist/shims/router.js +312 -148
- package/dist/shims/server.js +3 -3
- package/dist/utils/built-asset-url.js +1 -1
- package/dist/utils/project.d.ts +1 -11
- package/dist/utils/project.js +19 -28
- package/dist/utils/react-version.d.ts +3 -1
- package/dist/utils/react-version.js +19 -1
- package/dist/utils/vite-cli-invocation.d.ts +21 -0
- package/dist/utils/vite-cli-invocation.js +144 -0
- package/package.json +10 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UrlObject } from "node:url";
|
|
2
|
+
//#region src/shims/internal/format-url-object.d.ts
|
|
3
|
+
/** Format Node's public UrlObject shape with the semantics used by Next.js. */
|
|
4
|
+
export declare function formatUrlObject(url: UrlObject): string;
|
|
5
|
+
/** Format a Pages Router UrlObject and surface Next.js's development diagnostics. */
|
|
6
|
+
export declare function formatUrlObjectWithValidation(url: UrlObject): string;
|
|
7
|
+
//#endregion
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { urlQueryToSearchParams } from "../../utils/query.js";
|
|
2
|
+
//#region src/shims/internal/format-url-object.ts
|
|
3
|
+
const slashedProtocols = /https?|ftp|gopher|file/;
|
|
4
|
+
const urlObjectKeys = /* @__PURE__ */ new Set([
|
|
5
|
+
"auth",
|
|
6
|
+
"hash",
|
|
7
|
+
"host",
|
|
8
|
+
"hostname",
|
|
9
|
+
"href",
|
|
10
|
+
"path",
|
|
11
|
+
"pathname",
|
|
12
|
+
"port",
|
|
13
|
+
"protocol",
|
|
14
|
+
"query",
|
|
15
|
+
"search",
|
|
16
|
+
"slashes"
|
|
17
|
+
]);
|
|
18
|
+
/** Format Node's public UrlObject shape with the semantics used by Next.js. */
|
|
19
|
+
function formatUrlObject(url) {
|
|
20
|
+
let { auth, hostname } = url;
|
|
21
|
+
let protocol = url.protocol || "";
|
|
22
|
+
let pathname = url.pathname || "";
|
|
23
|
+
let hash = url.hash || "";
|
|
24
|
+
let query = url.query || "";
|
|
25
|
+
let host = false;
|
|
26
|
+
auth = auth ? `${encodeURIComponent(auth).replace(/%3A/i, ":")}@` : "";
|
|
27
|
+
if (url.host) host = auth + url.host;
|
|
28
|
+
else if (hostname) {
|
|
29
|
+
host = auth + (hostname.includes(":") ? `[${hostname}]` : hostname);
|
|
30
|
+
if (url.port) host += `:${url.port}`;
|
|
31
|
+
}
|
|
32
|
+
if (query && typeof query === "object") query = String(urlQueryToSearchParams(query));
|
|
33
|
+
let search = url.search || query && `?${query}` || "";
|
|
34
|
+
if (protocol && !protocol.endsWith(":")) protocol += ":";
|
|
35
|
+
if (url.slashes || (!protocol || slashedProtocols.test(protocol)) && host !== false) {
|
|
36
|
+
host = `//${host || ""}`;
|
|
37
|
+
if (pathname && !pathname.startsWith("/")) pathname = `/${pathname}`;
|
|
38
|
+
} else if (!host) host = "";
|
|
39
|
+
if (hash && !hash.startsWith("#")) hash = `#${hash}`;
|
|
40
|
+
if (search && !search.startsWith("?")) search = `?${search}`;
|
|
41
|
+
pathname = pathname.replace(/[?#]/g, encodeURIComponent);
|
|
42
|
+
search = search.replace("#", "%23");
|
|
43
|
+
return `${protocol}${host}${pathname}${search}${hash}`;
|
|
44
|
+
}
|
|
45
|
+
/** Format a Pages Router UrlObject and surface Next.js's development diagnostics. */
|
|
46
|
+
function formatUrlObjectWithValidation(url) {
|
|
47
|
+
if (process.env.NODE_ENV === "development") {
|
|
48
|
+
for (const key of Object.keys(url)) if (!urlObjectKeys.has(key)) console.warn(`Unknown key passed via urlObject into url.format: ${key}`);
|
|
49
|
+
}
|
|
50
|
+
return formatUrlObject(url);
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { formatUrlObject, formatUrlObjectWithValidation };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/shims/internal/normalize-router-href.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Warn about and normalize repeated path separators like Next.js `resolveHref`.
|
|
4
|
+
* The protocol separator is preserved and query strings are left untouched.
|
|
5
|
+
*
|
|
6
|
+
* Ported from Next.js: packages/next/src/client/resolve-href.ts
|
|
7
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/resolve-href.ts
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizeRouterHref(href: string, routePathname: string): string;
|
|
10
|
+
/** Resolve a Pages Router href against the route state used by Next.js Link. */
|
|
11
|
+
export declare function resolvePagesRouterHref(href: string, router: {
|
|
12
|
+
pathname: string;
|
|
13
|
+
asPath: string;
|
|
14
|
+
}, basePath: string): string;
|
|
15
|
+
//#endregion
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { hasBasePath } from "../../utils/base-path.js";
|
|
2
|
+
import { getWindowOrigin, isAbsoluteUrl } from "../url-utils.js";
|
|
3
|
+
//#region src/shims/internal/normalize-router-href.ts
|
|
4
|
+
/**
|
|
5
|
+
* Warn about and normalize repeated path separators like Next.js `resolveHref`.
|
|
6
|
+
* The protocol separator is preserved and query strings are left untouched.
|
|
7
|
+
*
|
|
8
|
+
* Ported from Next.js: packages/next/src/client/resolve-href.ts
|
|
9
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/resolve-href.ts
|
|
10
|
+
*/
|
|
11
|
+
function normalizeRouterHref(href, routePathname) {
|
|
12
|
+
const protocol = href.match(/^[a-z][a-z0-9+.-]*:\/\//i)?.[0] ?? "";
|
|
13
|
+
const withoutProtocol = protocol ? href.slice(protocol.length) : href;
|
|
14
|
+
if (!/(\/\/|\\)/.test(withoutProtocol.split("?", 1)[0] ?? "")) return href;
|
|
15
|
+
console.error(`Invalid href '${href}' passed to next/router in page: '${routePathname}'. Repeated forward-slashes (//) or backslashes \\ are not valid in the href.`);
|
|
16
|
+
const [pathname, ...query] = withoutProtocol.split("?");
|
|
17
|
+
return protocol + pathname.replace(/\\/g, "/").replace(/\/\/+/g, "/") + (query[0] ? `?${query.join("?")}` : "");
|
|
18
|
+
}
|
|
19
|
+
/** Resolve a Pages Router href against the route state used by Next.js Link. */
|
|
20
|
+
function resolvePagesRouterHref(href, router, basePath) {
|
|
21
|
+
const normalized = normalizeRouterHref(href, router.pathname);
|
|
22
|
+
if (isAbsoluteUrl(normalized)) {
|
|
23
|
+
const origin = getWindowOrigin();
|
|
24
|
+
if (!origin) return normalized;
|
|
25
|
+
try {
|
|
26
|
+
const target = new URL(normalized, origin);
|
|
27
|
+
if (target.origin !== origin || basePath !== "" && !hasBasePath(target.pathname, basePath)) return normalized;
|
|
28
|
+
} catch {
|
|
29
|
+
return normalized;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const base = new URL(normalized.startsWith("#") || normalized.startsWith("?") ? router.asPath : router.pathname, "http://n");
|
|
34
|
+
const resolved = new URL(normalized, base);
|
|
35
|
+
return resolved.origin === base.origin ? resolved.href.slice(resolved.origin.length) : resolved.href;
|
|
36
|
+
} catch {
|
|
37
|
+
return normalized;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { normalizeRouterHref, resolvePagesRouterHref };
|
|
@@ -35,8 +35,11 @@ export type PagesDataTarget = {
|
|
|
35
35
|
};
|
|
36
36
|
type PagesDataNavigationTargetOptions = {
|
|
37
37
|
locale?: string | false;
|
|
38
|
+
/** Force page identity while deriving params and data URLs from browserUrl. */
|
|
39
|
+
routePattern?: string;
|
|
38
40
|
};
|
|
39
|
-
export declare function
|
|
41
|
+
export declare function matchesPagesMiddlewarePath(pathname: string): boolean;
|
|
42
|
+
export declare function getPagesMiddlewareDataHref(browserUrl: string, basePath: string, options?: PagesDataNavigationTargetOptions, routeUrl?: string): string | null;
|
|
40
43
|
/**
|
|
41
44
|
* Decide whether the JSON data-endpoint navigation path is usable for this
|
|
42
45
|
* browser URL. We require:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { removeTrailingSlash, stripBasePath } from "../../utils/base-path.js";
|
|
2
|
-
import { getLocalePathPrefix } from "../../utils/domain-locale.js";
|
|
3
1
|
import { isUnknownRecord } from "../../utils/record.js";
|
|
2
|
+
import { stripBasePath } from "../../utils/base-path.js";
|
|
3
|
+
import { getLocalePathPrefix } from "../../utils/domain-locale.js";
|
|
4
4
|
import { buildPagesDataHref, matchPagesPattern } from "./pages-data-url.js";
|
|
5
5
|
import { NEXT_DEPLOYMENT_ID_HEADER, getDeploymentId } from "../../utils/deployment-id.js";
|
|
6
6
|
import { fetchStaticPagesData, fetchUncachedPagesData } from "./pages-data-fetch-dedup.js";
|
|
@@ -22,10 +22,9 @@ function hasVinextMiddleware(nextData) {
|
|
|
22
22
|
}
|
|
23
23
|
function isClientMiddlewareMatcherObject(value) {
|
|
24
24
|
if (!isUnknownRecord(value)) return false;
|
|
25
|
-
if (typeof value.
|
|
25
|
+
if (typeof value.regexp !== "string") return false;
|
|
26
|
+
if (value.flags !== void 0 && typeof value.flags !== "string") return false;
|
|
26
27
|
if (value.locale !== void 0 && value.locale !== false) return false;
|
|
27
|
-
if (value.has !== void 0 && !Array.isArray(value.has)) return false;
|
|
28
|
-
if (value.missing !== void 0 && !Array.isArray(value.missing)) return false;
|
|
29
28
|
return true;
|
|
30
29
|
}
|
|
31
30
|
function stripLocaleForMiddlewareMatcher(pathname) {
|
|
@@ -35,40 +34,28 @@ function stripLocaleForMiddlewareMatcher(pathname) {
|
|
|
35
34
|
if (!firstSegment || !locales.includes(firstSegment)) return pathname;
|
|
36
35
|
return "/" + pathname.split("/").slice(2).join("/");
|
|
37
36
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
let pathIndex = 0;
|
|
44
|
-
for (const sourcePart of sourceParts) {
|
|
45
|
-
if (sourcePart.startsWith(":")) {
|
|
46
|
-
if (sourcePart.endsWith("*")) return true;
|
|
47
|
-
if (sourcePart.endsWith("+")) return pathIndex < pathParts.length;
|
|
48
|
-
if (pathIndex >= pathParts.length) return false;
|
|
49
|
-
pathIndex++;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (pathParts[pathIndex] !== sourcePart) return false;
|
|
53
|
-
pathIndex++;
|
|
54
|
-
}
|
|
55
|
-
return pathIndex === pathParts.length;
|
|
37
|
+
function localeAwareMiddlewarePathname(pathname) {
|
|
38
|
+
const locales = window.__VINEXT_LOCALES__;
|
|
39
|
+
const defaultLocale = window.__VINEXT_DEFAULT_LOCALE__;
|
|
40
|
+
if (!locales?.includes(defaultLocale ?? "") || getLocalePathPrefix(pathname, locales)) return pathname;
|
|
41
|
+
return `/${defaultLocale}${pathname === "/" ? "" : pathname}`;
|
|
56
42
|
}
|
|
57
|
-
function
|
|
43
|
+
function matchesPagesMiddlewarePath(pathname) {
|
|
44
|
+
const matcher = window.__VINEXT_MIDDLEWARE_MATCHER__;
|
|
58
45
|
if (matcher === void 0) return true;
|
|
59
|
-
if (typeof matcher === "string") return clientMiddlewareSourceMatches(stripLocaleForMiddlewareMatcher(pathname), matcher);
|
|
60
46
|
if (!Array.isArray(matcher)) return true;
|
|
61
47
|
for (const item of matcher) {
|
|
62
|
-
if (typeof item === "string") {
|
|
63
|
-
if (clientMiddlewareSourceMatches(stripLocaleForMiddlewareMatcher(pathname), item)) return true;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
48
|
if (!isClientMiddlewareMatcherObject(item)) return true;
|
|
67
|
-
|
|
49
|
+
const candidate = item.locale === false ? localeAwareMiddlewarePathname(pathname) : stripLocaleForMiddlewareMatcher(pathname);
|
|
50
|
+
try {
|
|
51
|
+
if (new RegExp(item.regexp, item.flags).test(candidate)) return true;
|
|
52
|
+
} catch {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
68
55
|
}
|
|
69
56
|
return false;
|
|
70
57
|
}
|
|
71
|
-
function getPagesMiddlewareDataHref(browserUrl, basePath, options = {}) {
|
|
58
|
+
function getPagesMiddlewareDataHref(browserUrl, basePath, options = {}, routeUrl = browserUrl) {
|
|
72
59
|
const nextData = window.__NEXT_DATA__;
|
|
73
60
|
if (!nextData || !hasVinextMiddleware(nextData)) return null;
|
|
74
61
|
const buildId = nextData.buildId;
|
|
@@ -80,13 +67,19 @@ function getPagesMiddlewareDataHref(browserUrl, basePath, options = {}) {
|
|
|
80
67
|
return null;
|
|
81
68
|
}
|
|
82
69
|
if (parsed.origin !== window.location.origin) return null;
|
|
70
|
+
let routeSearch = parsed.search;
|
|
71
|
+
if (routeUrl !== browserUrl) try {
|
|
72
|
+
routeSearch = new URL(routeUrl, window.location.href).search;
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
83
76
|
const pathname = stripBasePath(parsed.pathname, basePath);
|
|
84
|
-
if (!
|
|
77
|
+
if (!matchesPagesMiddlewarePath(pathname)) return null;
|
|
85
78
|
const pathnameLocale = getLocalePathPrefix(pathname, window.__VINEXT_LOCALES__);
|
|
86
79
|
const explicitLocale = options.locale === false ? window.__VINEXT_DEFAULT_LOCALE__ : options.locale;
|
|
87
80
|
const currentLocale = pathnameLocale ?? explicitLocale ?? window.__VINEXT_LOCALE__;
|
|
88
81
|
const dataPathname = pathnameLocale || !currentLocale || !window.__VINEXT_LOCALES__?.includes(currentLocale) ? pathname : `/${currentLocale}${pathname === "/" ? "" : pathname}`;
|
|
89
|
-
return buildPagesDataHref(basePath, buildId, dataPathname,
|
|
82
|
+
return buildPagesDataHref(basePath, buildId, dataPathname, routeSearch);
|
|
90
83
|
}
|
|
91
84
|
/**
|
|
92
85
|
* Decide whether the JSON data-endpoint navigation path is usable for this
|
|
@@ -128,7 +121,7 @@ function resolvePagesDataNavigationTarget(browserUrl, basePath, options = {}) {
|
|
|
128
121
|
const pagePath = stripBasePath(parsed.pathname, basePath);
|
|
129
122
|
const locale = getLocalePathPrefix(pagePath, window.__VINEXT_LOCALES__);
|
|
130
123
|
const pathForMatch = locale ? pagePath.slice(locale.length + 1) || "/" : pagePath;
|
|
131
|
-
const match = matchPagesPattern(pathForMatch, patterns);
|
|
124
|
+
const match = matchPagesPattern(pathForMatch, options.routePattern ? [options.routePattern] : patterns);
|
|
132
125
|
if (!match) return null;
|
|
133
126
|
const loader = loaders[match.pattern];
|
|
134
127
|
if (!loader) return null;
|
|
@@ -195,4 +188,4 @@ function prefetchMiddlewareRewriteLoader(response) {
|
|
|
195
188
|
if (target) target.loader().catch(() => {});
|
|
196
189
|
}
|
|
197
190
|
//#endregion
|
|
198
|
-
export { getPagesMiddlewareDataHref, prefetchPagesData, resolvePagesDataNavigationTarget };
|
|
191
|
+
export { getPagesMiddlewareDataHref, matchesPagesMiddlewarePath, prefetchPagesData, resolvePagesDataNavigationTarget };
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* `installWindowNext()` side effect into every consumer of the Link shim
|
|
14
14
|
* (including the App Router client bundle), clobbering `window.next.router`.
|
|
15
15
|
*
|
|
16
|
-
* On the client
|
|
17
|
-
* back to `window.location.pathname`, then to `"/"`.
|
|
16
|
+
* On the client, Pages Router exposes the pattern through `__NEXT_DATA__.page`.
|
|
17
|
+
* App Router falls back to `window.location.pathname`, then to `"/"`.
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* Register the server-side route-pattern accessor. Called once by the
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* `installWindowNext()` side effect into every consumer of the Link shim
|
|
14
14
|
* (including the App Router client bundle), clobbering `window.next.router`.
|
|
15
15
|
*
|
|
16
|
-
* On the client
|
|
17
|
-
* back to `window.location.pathname`, then to `"/"`.
|
|
16
|
+
* On the client, Pages Router exposes the pattern through `__NEXT_DATA__.page`.
|
|
17
|
+
* App Router falls back to `window.location.pathname`, then to `"/"`.
|
|
18
18
|
*/
|
|
19
19
|
const ROUTE_PATTERN_FOR_WARNING_ACCESSOR_KEY = Symbol.for("vinext.router.routePatternForWarningAccessor");
|
|
20
20
|
/**
|
|
@@ -34,7 +34,7 @@ function getCurrentRoutePathnameForWarning() {
|
|
|
34
34
|
} catch {}
|
|
35
35
|
return "/";
|
|
36
36
|
}
|
|
37
|
-
return window.location?.pathname ?? "/";
|
|
37
|
+
return window.__NEXT_DATA__?.page ?? window.location?.pathname ?? "/";
|
|
38
38
|
}
|
|
39
39
|
//#endregion
|
|
40
40
|
export { getCurrentRoutePathnameForWarning, registerRoutePatternForWarningAccessor };
|
package/dist/shims/link.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
2
3
|
import { isDangerousScheme, reportBlockedDangerousNavigation } from "./url-safety.js";
|
|
3
4
|
import { addLocalePrefix, getDomainLocaleUrl } from "../utils/domain-locale.js";
|
|
4
5
|
import { RouterContext } from "./internal/router-context.js";
|
|
5
6
|
import { getPagesMiddlewareDataHref, prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.js";
|
|
6
7
|
import { markAppRouteDetectedOnPrefetch } from "./internal/app-route-detection.js";
|
|
7
8
|
import { isAbsoluteOrProtocolRelativeUrl, normalizePathTrailingSlash, toCanonicalBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
8
|
-
import { appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
|
|
9
9
|
import { interpolateDynamicRouteHref, resolveDynamicRouteHref } from "./internal/interpolate-as.js";
|
|
10
|
-
import {
|
|
10
|
+
import { formatUrlObject, formatUrlObjectWithValidation } from "./internal/format-url-object.js";
|
|
11
|
+
import { normalizeRouterHref, resolvePagesRouterHref } from "./internal/normalize-router-href.js";
|
|
11
12
|
import { getCurrentRoutePathnameForWarning } from "./internal/route-pattern-for-warning.js";
|
|
12
|
-
import {
|
|
13
|
+
import { getCurrentBrowserLocale } from "./client-locale.js";
|
|
13
14
|
import { getNavigationRuntime, hasAppNavigationRuntime, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
|
|
14
15
|
import { navigatePagesRouterLinkWithFallback, resolvePagesRouterQueryOnlyHref } from "../client/pages-router-link-navigation.js";
|
|
15
16
|
import { scheduleAppPrefetchFetch } from "./internal/app-prefetch-fetch-queue.js";
|
|
@@ -65,15 +66,15 @@ const __basePath = process.env.__NEXT_ROUTER_BASEPATH ?? "";
|
|
|
65
66
|
/** trailingSlash from next.config.js, injected by the plugin at build time */
|
|
66
67
|
const __trailingSlash = process.env.__VINEXT_TRAILING_SLASH === "true";
|
|
67
68
|
const __prefetchInlining = process.env.__VINEXT_PREFETCH_INLINING === "true";
|
|
68
|
-
function resolveHref(href) {
|
|
69
|
+
function resolveHref(href, validate = false) {
|
|
69
70
|
if (typeof href === "string") return href;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
71
|
+
return validate ? formatUrlObjectWithValidation(href) : formatUrlObject(href);
|
|
72
|
+
}
|
|
73
|
+
function resolvePagesLinkValue(value, pagesRouter, routePathnameForWarning) {
|
|
74
|
+
const formatted = resolveHref(value, pagesRouter !== null);
|
|
75
|
+
if (pagesRouter === null) return formatted;
|
|
76
|
+
if (typeof pagesRouter.pathname === "string" && typeof pagesRouter.asPath === "string" && !formatted.startsWith("?") && !formatted.startsWith("#")) return resolvePagesRouterHref(formatted, pagesRouter, __basePath);
|
|
77
|
+
return normalizeRouterHref(formatted, routePathnameForWarning);
|
|
77
78
|
}
|
|
78
79
|
function resolvePagesQueryOnlyHref(href) {
|
|
79
80
|
if (!HAS_PAGES_ROUTER) return href;
|
|
@@ -95,52 +96,6 @@ function applyPagesNavigationFallback(href, replace) {
|
|
|
95
96
|
else window.history.pushState({}, "", href);
|
|
96
97
|
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
97
98
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Collapse repeated forward-slashes (and convert backslashes to forward-slashes)
|
|
100
|
-
* in the path portion of a URL, preserving any query string.
|
|
101
|
-
*
|
|
102
|
-
* Ported from Next.js: packages/next/src/shared/lib/utils/normalize-repeated-slashes.ts
|
|
103
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/utils/normalize-repeated-slashes.ts
|
|
104
|
-
*/
|
|
105
|
-
function normalizeRepeatedSlashes(url) {
|
|
106
|
-
const urlParts = url.split("?");
|
|
107
|
-
const urlNoQueryString = urlParts.shift() ?? "";
|
|
108
|
-
const queryString = urlParts.join("?");
|
|
109
|
-
return urlNoQueryString.replace(/\\/g, "/").replace(/\/\/+/g, "/") + (queryString ? `?${queryString}` : "");
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Emit Next.js's "Invalid href" `console.error` when `href` contains repeated
|
|
113
|
-
* forward slashes or backslashes in its path portion, and return the
|
|
114
|
-
* normalized URL (with `\\` converted to `/` and runs of `/` collapsed). If
|
|
115
|
-
* the href is already well-formed, the original string is returned unchanged.
|
|
116
|
-
*
|
|
117
|
-
* Ported from Next.js: packages/next/src/client/resolve-href.ts
|
|
118
|
-
* https://github.com/vercel/next.js/blob/canary/packages/next/src/client/resolve-href.ts
|
|
119
|
-
*
|
|
120
|
-
* Matches the message asserted by:
|
|
121
|
-
* test/e2e/repeated-forward-slashes-error/repeated-forward-slashes-error.test.ts
|
|
122
|
-
*
|
|
123
|
-
* Note: Next.js fires this warning unconditionally on every call to
|
|
124
|
-
* `resolveHref`. We mirror that behaviour (no dedup) for exact parity.
|
|
125
|
-
*
|
|
126
|
-
* Note: Next.js uses `router.pathname` (the route pattern, e.g.
|
|
127
|
-
* `/posts/[id]`) for the "in page" segment of the message. The Next.js
|
|
128
|
-
* compat test asserts this exact text (`in page: '/my/path/[name]'`), so we
|
|
129
|
-
* source it from the current render's route pattern via
|
|
130
|
-
* `getCurrentRoutePathnameForWarning()`: the Pages Router SSR context's route
|
|
131
|
-
* pattern on the server, `window.location.pathname` on the client, falling
|
|
132
|
-
* back to `"/"`.
|
|
133
|
-
*/
|
|
134
|
-
function warnAndNormalizeRepeatedSlashesInHref(urlAsString) {
|
|
135
|
-
if (urlAsString.startsWith("//")) return urlAsString;
|
|
136
|
-
const urlProtoMatch = urlAsString.match(/^[a-z][a-z0-9+.-]*:\/\//i);
|
|
137
|
-
const urlAsStringNoProto = urlProtoMatch ? urlAsString.slice(urlProtoMatch[0].length) : urlAsString;
|
|
138
|
-
if (!(urlAsStringNoProto.split("?", 1)[0] || "").match(/(\/\/|\\)/)) return urlAsString;
|
|
139
|
-
const pathname = getCurrentRoutePathnameForWarning();
|
|
140
|
-
console.error(`Invalid href '${urlAsString}' passed to next/router in page: '${pathname}'. Repeated forward-slashes (//) or backslashes \\ are not valid in the href.`);
|
|
141
|
-
const normalizedNoProto = normalizeRepeatedSlashes(urlAsStringNoProto);
|
|
142
|
-
return (urlProtoMatch ? urlProtoMatch[0] : "") + normalizedNoProto;
|
|
143
|
-
}
|
|
144
99
|
function resolveLinkPrefetchMode(prefetchProp, isDangerous) {
|
|
145
100
|
if (isDangerous || prefetchProp === false) return "disabled";
|
|
146
101
|
if (prefetchProp === true) return "full";
|
|
@@ -335,7 +290,7 @@ function prefetchUrl(href, mode, priority = "low", pagesRouteHref, locale) {
|
|
|
335
290
|
} else if (HAS_PAGES_ROUTER && window.__NEXT_DATA__) {
|
|
336
291
|
const dataTarget = resolvePagesDataNavigationTarget(fullRouteHref, __basePath, { locale });
|
|
337
292
|
if (dataTarget) {
|
|
338
|
-
const middlewareDataHref = fullRouteHref === fullHref ? dataTarget.middlewareDataHref : getPagesMiddlewareDataHref(fullHref, __basePath, { locale }) ?? void 0;
|
|
293
|
+
const middlewareDataHref = fullRouteHref === fullHref ? dataTarget.middlewareDataHref : getPagesMiddlewareDataHref(fullHref, __basePath, { locale }, fullRouteHref) ?? void 0;
|
|
339
294
|
prefetchPagesData({
|
|
340
295
|
...dataTarget,
|
|
341
296
|
middlewareDataHref
|
|
@@ -497,50 +452,34 @@ function applyLocaleToHref(href, locale) {
|
|
|
497
452
|
}
|
|
498
453
|
return addLocalePrefix(href, resolvedLocale, defaultLocale);
|
|
499
454
|
}
|
|
500
|
-
/**
|
|
501
|
-
* For the `<Link href="/blog/[slug]" as="/blog/test-post">` case, project the
|
|
502
|
-
* bracket-pattern href + the resolved `as` back into a concrete route URL the
|
|
503
|
-
* Pages Router can fetch (`/blog/test-post`). Returns null when:
|
|
504
|
-
* - `href` has no bracket params (already concrete; the existing forwarding
|
|
505
|
-
* path works as-is)
|
|
506
|
-
* - interpolation fails because a required param could not be resolved
|
|
507
|
-
* (caller falls back to `as`, matching pre-PR behavior)
|
|
508
|
-
*
|
|
509
|
-
* The query for interpolation is the href's own query — `as` is the matcher
|
|
510
|
-
* input rather than the source of param values. For string hrefs the search
|
|
511
|
-
* portion is parsed into the query record; for object hrefs we take
|
|
512
|
-
* `href.query` directly.
|
|
513
|
-
*/
|
|
455
|
+
/** Resolve a dynamic route pattern to the concrete URL used for prefetching. */
|
|
514
456
|
function resolveConcreteRouteHref(href, as) {
|
|
515
457
|
if (typeof as !== "string") return null;
|
|
516
|
-
|
|
517
|
-
return interpolateDynamicRouteHref(hrefStr, as, typeof href === "string" || !href.query || typeof href.query === "string" ? void 0 : href.query)?.href || null;
|
|
458
|
+
return interpolateDynamicRouteHref(href, as)?.href || null;
|
|
518
459
|
}
|
|
519
460
|
const Link = forwardRef(function Link({ href, as, replace = false, prefetch: prefetchProp, scroll = true, shallow = false, children: childrenProp, onClick, onMouseEnter, onTouchStart, onNavigate, unstable_dynamicOnHover = false, legacyBehavior = false, passHref = false, transitionTypes: _transitionTypes, ...rest }, forwardedRef) {
|
|
520
461
|
const pagesRouter = useContext(RouterContext);
|
|
521
|
-
const
|
|
522
|
-
const hrefStr =
|
|
462
|
+
const routePathnameForWarning = getCurrentRoutePathnameForWarning();
|
|
463
|
+
const hrefStr = resolvePagesLinkValue(href, pagesRouter, routePathnameForWarning);
|
|
464
|
+
const asHref = as === void 0 ? void 0 : resolvePagesLinkValue(as, pagesRouter, routePathnameForWarning);
|
|
523
465
|
const { locale, ...restWithoutLocale } = rest;
|
|
524
466
|
let children = childrenProp;
|
|
525
467
|
if (legacyBehavior && (typeof childrenProp === "string" || typeof childrenProp === "number")) children = React.createElement("a", null, childrenProp);
|
|
526
468
|
const hrefForImplicitInterpolation = isAbsoluteOrProtocolRelativeUrl(hrefStr) ? hrefStr.startsWith("//") ? null : toSameOriginAppPath(hrefStr, __basePath) : hrefStr;
|
|
527
469
|
const implicitDynamicRouteHref = HAS_PAGES_ROUTER && pagesRouter !== null && asHref === void 0 && hrefForImplicitInterpolation !== null ? resolveDynamicRouteHref(hrefForImplicitInterpolation) : null;
|
|
528
|
-
const
|
|
529
|
-
...implicitDynamicRouteHref,
|
|
530
|
-
href: hrefStr
|
|
531
|
-
} : null;
|
|
532
|
-
const pagesAsHref = asHref ?? dynamicRouteHref?.as;
|
|
470
|
+
const pagesAsHref = asHref ?? implicitDynamicRouteHref?.as;
|
|
533
471
|
const unresolvedHref = pagesAsHref ?? hrefStr;
|
|
534
|
-
const
|
|
535
|
-
const concreteRouteHref = HAS_PAGES_ROUTER ? resolveConcreteRouteHref(
|
|
536
|
-
const routeHrefRaw =
|
|
472
|
+
const resolvedHref = unresolvedHref.startsWith("#") && !getNavigationRuntime()?.functions.navigate ? resolvePagesQueryOnlyHref(unresolvedHref) : unresolvedHref;
|
|
473
|
+
const concreteRouteHref = HAS_PAGES_ROUTER ? resolveConcreteRouteHref(hrefForImplicitInterpolation ?? hrefStr, pagesAsHref) : null;
|
|
474
|
+
const routeHrefRaw = hrefStr;
|
|
537
475
|
const prefetchRouteHrefRaw = concreteRouteHref ?? routeHrefRaw;
|
|
538
|
-
const hasPagesHrefAsPair = HAS_PAGES_ROUTER &&
|
|
539
|
-
const
|
|
540
|
-
const
|
|
476
|
+
const hasPagesHrefAsPair = HAS_PAGES_ROUTER && pagesAsHref !== void 0 && pagesAsHref !== routeHrefRaw;
|
|
477
|
+
const isDangerous = isDangerousScheme(resolvedHref);
|
|
478
|
+
const isRouteDangerous = isDangerousScheme(prefetchRouteHrefRaw);
|
|
479
|
+
const isPrefetchDangerous = isDangerous || pagesRouter !== null && isRouteDangerous;
|
|
541
480
|
const localizedHref = applyLocaleToHref(isDangerous ? "/" : resolvedHref, locale);
|
|
542
481
|
const normalizedHref = normalizePathTrailingSlash(localizedHref, __trailingSlash);
|
|
543
|
-
const normalizedRouteHref = hasPagesHrefAsPair ? normalizePathTrailingSlash(applyLocaleToHref(
|
|
482
|
+
const normalizedRouteHref = hasPagesHrefAsPair ? normalizePathTrailingSlash(applyLocaleToHref(isRouteDangerous ? "/" : prefetchRouteHrefRaw, locale), __trailingSlash) : normalizedHref;
|
|
544
483
|
const fullHref = normalizePathTrailingSlash(withBasePath(normalizedHref, __basePath), __trailingSlash);
|
|
545
484
|
const [pending, setPending] = useState(false);
|
|
546
485
|
const mountedRef = useRef(true);
|
|
@@ -562,11 +501,11 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
562
501
|
const prefetchRouterMode = getLinkPrefetchRouterMode();
|
|
563
502
|
const isShallowPagesLink = prefetchRouterMode === "pages" && shallow;
|
|
564
503
|
const effectivePrefetchProp = isShallowPagesLink ? false : prefetchProp;
|
|
565
|
-
const prefetchMode = resolveLinkPrefetchMode(effectivePrefetchProp,
|
|
504
|
+
const prefetchMode = resolveLinkPrefetchMode(effectivePrefetchProp, isPrefetchDangerous);
|
|
566
505
|
const shouldViewportPrefetch = canLinkPrefetch({
|
|
567
506
|
nodeEnv: process.env.NODE_ENV,
|
|
568
507
|
prefetch: effectivePrefetchProp,
|
|
569
|
-
isDangerous
|
|
508
|
+
isDangerous: isPrefetchDangerous
|
|
570
509
|
});
|
|
571
510
|
const setRefs = useCallback((node) => {
|
|
572
511
|
internalRef.current = node;
|
|
@@ -620,7 +559,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
620
559
|
if (isShallowPagesLink || !canLinkIntentPrefetch({
|
|
621
560
|
nodeEnv: process.env.NODE_ENV,
|
|
622
561
|
prefetch: effectivePrefetchProp,
|
|
623
|
-
isDangerous,
|
|
562
|
+
isDangerous: isPrefetchDangerous,
|
|
624
563
|
routerMode: prefetchRouterMode
|
|
625
564
|
})) return;
|
|
626
565
|
const intentMode = unstable_dynamicOnHover ? "full-after-shell" : prefetchMode;
|
|
@@ -632,7 +571,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
632
571
|
prefetchUrl(normalizedHref, intentMode, "high", normalizedRouteHref === normalizedHref ? void 0 : normalizedRouteHref, locale);
|
|
633
572
|
}, [
|
|
634
573
|
effectivePrefetchProp,
|
|
635
|
-
|
|
574
|
+
isPrefetchDangerous,
|
|
636
575
|
isShallowPagesLink,
|
|
637
576
|
prefetchMode,
|
|
638
577
|
prefetchRouterMode,
|
package/dist/shims/metadata.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isAbsoluteOrProtocolRelativeUrl } from "./url-utils.js";
|
|
2
2
|
import { makeThenableParams } from "./thenable-params.js";
|
|
3
|
+
import { withUseCachePageMarker } from "./internal/app-page-props-cache-key.js";
|
|
3
4
|
import React from "react";
|
|
4
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
5
6
|
//#region src/shims/metadata.tsx
|
|
@@ -18,10 +19,10 @@ const USE_CACHE_ACCEPTS_SECOND_ARGUMENT_SYMBOL = Symbol.for("vinext.useCacheAcce
|
|
|
18
19
|
async function resolveModuleViewport(mod, params = {}, searchParams, parent = Promise.resolve(mergeViewport([])), searchParamsObserver) {
|
|
19
20
|
if (typeof mod.generateViewport === "function") {
|
|
20
21
|
const asyncParams = makeThenableParams(params);
|
|
21
|
-
const props = searchParams === void 0 ? { params: asyncParams } : {
|
|
22
|
+
const props = searchParams === void 0 ? { params: asyncParams } : withUseCachePageMarker(mod.generateViewport, {
|
|
22
23
|
params: asyncParams,
|
|
23
24
|
searchParams: makeThenableParams(searchParams, searchParamsObserver)
|
|
24
|
-
};
|
|
25
|
+
});
|
|
25
26
|
return await mod.generateViewport(props, parent);
|
|
26
27
|
}
|
|
27
28
|
if (mod.viewport && typeof mod.viewport === "object") return mod.viewport;
|
|
@@ -267,10 +268,10 @@ async function resolveModuleMetadata(mod, params = {}, searchParams, parent = Pr
|
|
|
267
268
|
if (typeof mod.generateMetadata === "function") {
|
|
268
269
|
const generateMetadata = mod.generateMetadata;
|
|
269
270
|
const asyncParams = makeThenableParams(params);
|
|
270
|
-
const props = searchParams === void 0 ? { params: asyncParams } : {
|
|
271
|
+
const props = searchParams === void 0 ? { params: asyncParams } : withUseCachePageMarker(generateMetadata, {
|
|
271
272
|
params: asyncParams,
|
|
272
273
|
searchParams: makeThenableParams(searchParams, searchParamsObserver)
|
|
273
|
-
};
|
|
274
|
+
});
|
|
274
275
|
const isUseCacheFunction = Reflect.get(generateMetadata, USE_CACHE_FUNCTION_SYMBOL) === true;
|
|
275
276
|
const acceptsSecondArgument = Reflect.get(generateMetadata, USE_CACHE_ACCEPTS_SECOND_ARGUMENT_SYMBOL);
|
|
276
277
|
return await (!isUseCacheFunction || (typeof acceptsSecondArgument === "boolean" ? acceptsSecondArgument : generateMetadata.length >= 2) ? generateMetadata(props, parent) : generateMetadata(props));
|
package/dist/shims/navigation.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
2
|
+
import { isExternalUrl } from "../utils/external-url.js";
|
|
1
3
|
import { stripBasePath } from "../utils/base-path.js";
|
|
2
4
|
import { NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_RSC_RENDER_MODE_HEADER } from "../server/app-rsc-vary.js";
|
|
3
5
|
import { NEXT_ROUTER_STALE_TIME_HEADER, VINEXT_DYNAMIC_STALE_TIME_HEADER, VINEXT_PARAMS_HEADER, VINEXT_RENDERED_PATH_AND_SEARCH_HEADER, VINEXT_RSC_COMPLETION_METADATA_HEADER, VINEXT_STALE_TIME_PENDING_HEADER } from "../server/headers.js";
|
|
4
6
|
import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
5
|
-
import { isExternalUrl } from "../utils/external-url.js";
|
|
6
7
|
import { APP_RSC_RENDER_MODE_PREFETCH_DYNAMIC_SHELL, APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "../server/app-rsc-render-mode.js";
|
|
7
8
|
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
8
9
|
import "../server/app-elements.js";
|
|
@@ -11,7 +12,6 @@ import { AppRouterContext } from "./internal/app-router-context.js";
|
|
|
11
12
|
import { resolveDirectHybridClientRouteOwner } from "./internal/hybrid-client-route-owner-direct.js";
|
|
12
13
|
import { isHashOnlyBrowserUrlChange, toCanonicalBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
13
14
|
import { retryScrollTo, scrollToHashTarget, scrollToHashTargetOnNextFrame } from "./hash-scroll.js";
|
|
14
|
-
import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
15
15
|
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
16
16
|
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";
|
|
17
17
|
import { clearAppNavigationFailureTarget, stageAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getOrCreateAls } from "./internal/als-registry.js";
|
|
2
2
|
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
3
|
-
import { _registerRouterStateAccessors } from "./router.js";
|
|
4
3
|
import { registerRoutePatternForWarningAccessor } from "./internal/route-pattern-for-warning.js";
|
|
4
|
+
import { _registerRouterStateAccessors } from "./router.js";
|
|
5
5
|
//#region src/shims/router-state.ts
|
|
6
6
|
/**
|
|
7
7
|
* Server-only Pages Router state backed by AsyncLocalStorage.
|
package/dist/shims/router.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ type BeforePopStateCallback = (state: {
|
|
|
11
11
|
as: string;
|
|
12
12
|
options: TransitionOptions;
|
|
13
13
|
}) => boolean;
|
|
14
|
+
type UrlObject$1 = UrlObject;
|
|
15
|
+
type Url = string | UrlObject$1;
|
|
14
16
|
export type NextRouter = {
|
|
15
17
|
/** Current pathname */
|
|
16
18
|
pathname: string;
|
|
@@ -39,9 +41,9 @@ export type NextRouter = {
|
|
|
39
41
|
/** Whether this is a fallback page */
|
|
40
42
|
isFallback: boolean;
|
|
41
43
|
/** Navigate to a new URL */
|
|
42
|
-
push(url:
|
|
44
|
+
push(url: Url, as?: Url, options?: TransitionOptions): Promise<boolean>;
|
|
43
45
|
/** Replace current URL */
|
|
44
|
-
replace(url:
|
|
46
|
+
replace(url: Url, as?: Url, options?: TransitionOptions): Promise<boolean>;
|
|
45
47
|
/** Go back */
|
|
46
48
|
back(): void;
|
|
47
49
|
/** Go forward */
|
|
@@ -55,7 +57,6 @@ export type NextRouter = {
|
|
|
55
57
|
/** Listen for route changes */
|
|
56
58
|
events: RouterEvents;
|
|
57
59
|
};
|
|
58
|
-
type UrlObject$1 = UrlObject;
|
|
59
60
|
type TransitionOptions = {
|
|
60
61
|
_h?: 1;
|
|
61
62
|
shallow?: boolean;
|
|
@@ -200,8 +201,8 @@ declare const RouterMethods: {
|
|
|
200
201
|
/** See `_components` comment above for the dual role this map plays. */
|
|
201
202
|
components: PagesRouterComponentsMap;
|
|
202
203
|
sdc: Record<string, Promise<Response>>;
|
|
203
|
-
push: (url:
|
|
204
|
-
replace: (url:
|
|
204
|
+
push: (url: Url, as?: Url, options?: TransitionOptions) => Promise<boolean>;
|
|
205
|
+
replace: (url: Url, as?: Url, options?: TransitionOptions) => Promise<boolean>;
|
|
205
206
|
back: () => void;
|
|
206
207
|
forward: () => void;
|
|
207
208
|
reload: () => void;
|
|
@@ -234,8 +235,8 @@ export declare class Router {
|
|
|
234
235
|
get events(): RouterEvents;
|
|
235
236
|
get components(): PagesRouterComponentsMap;
|
|
236
237
|
get sdc(): Record<string, Promise<Response>>;
|
|
237
|
-
push(url:
|
|
238
|
-
replace(url:
|
|
238
|
+
push(url: Url, as?: Url, options?: TransitionOptions): Promise<boolean>;
|
|
239
|
+
replace(url: Url, as?: Url, options?: TransitionOptions): Promise<boolean>;
|
|
239
240
|
reload(): void;
|
|
240
241
|
back(): void;
|
|
241
242
|
forward(): void;
|