@qzsy/vinext 0.1.12 → 0.1.81
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 +19 -5
- package/dist/build/inject-pregenerated-paths.d.ts +4 -0
- package/dist/build/inject-pregenerated-paths.js +18 -0
- package/dist/build/pages-client-assets-module.d.ts +11 -0
- package/dist/build/pages-client-assets-module.js +27 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +11 -4
- package/dist/build/report.d.ts +2 -1
- package/dist/build/report.js +2 -1
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +9 -0
- package/dist/build/standalone.js +2 -0
- package/dist/check.d.ts +18 -0
- package/dist/check.js +77 -19
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +64 -28
- package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay-store.js +1 -1
- package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay.js +2 -2
- package/dist/cloudflare/deploy-config.d.ts +51 -0
- package/dist/cloudflare/deploy-config.js +153 -0
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/cloudflare/project.d.ts +41 -0
- package/dist/cloudflare/project.js +243 -0
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/config/config-matchers.js +14 -10
- package/dist/config/next-config.d.ts +6 -3
- package/dist/config/next-config.js +47 -1
- package/dist/config/server-external-packages.d.ts +4 -0
- package/dist/config/server-external-packages.js +91 -0
- package/dist/deploy.d.ts +2 -122
- package/dist/deploy.js +20 -793
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +70 -12
- package/dist/entries/app-rsc-manifest.js +8 -0
- package/dist/entries/pages-client-entry.d.ts +1 -0
- package/dist/entries/pages-client-entry.js +2 -1
- package/dist/entries/pages-server-entry.js +6 -2
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +50 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +160 -160
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +1000 -0
- package/dist/init-platform.d.ts +38 -0
- package/dist/init-platform.js +150 -0
- package/dist/init.d.ts +14 -37
- package/dist/init.js +205 -95
- package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
- package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
- package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.js +3 -0
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/middleware-server-only.d.ts +8 -6
- package/dist/plugins/middleware-server-only.js +8 -7
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/typeof-window.d.ts +1 -1
- package/dist/plugins/typeof-window.js +28 -56
- package/dist/routing/app-route-graph.d.ts +13 -2
- package/dist/routing/app-route-graph.js +116 -32
- package/dist/routing/app-router.d.ts +5 -0
- package/dist/routing/app-router.js +5 -0
- package/dist/routing/file-matcher.d.ts +8 -0
- package/dist/routing/file-matcher.js +10 -1
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/app-browser-action-result.d.ts +2 -1
- package/dist/server/app-browser-action-result.js +5 -1
- package/dist/server/app-browser-entry.js +17 -12
- package/dist/server/app-browser-history-controller.d.ts +2 -1
- package/dist/server/app-browser-history-controller.js +6 -2
- package/dist/server/app-browser-interception-context.d.ts +1 -0
- package/dist/server/app-browser-interception-context.js +4 -2
- package/dist/server/app-browser-navigation-controller.js +1 -0
- package/dist/server/app-browser-server-action-client.js +2 -3
- package/dist/server/app-browser-state.d.ts +1 -0
- package/dist/server/app-browser-state.js +3 -2
- package/dist/server/app-fallback-renderer.d.ts +3 -2
- package/dist/server/app-fallback-renderer.js +12 -7
- package/dist/server/app-middleware.d.ts +2 -3
- package/dist/server/app-middleware.js +3 -2
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -0
- package/dist/server/app-page-boundary-render.js +12 -3
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +10 -3
- package/dist/server/app-page-cache-render.d.ts +1 -0
- package/dist/server/app-page-cache-render.js +8 -4
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +4 -1
- package/dist/server/app-page-dispatch.d.ts +11 -3
- package/dist/server/app-page-dispatch.js +55 -15
- package/dist/server/app-page-element-builder.d.ts +5 -1
- package/dist/server/app-page-element-builder.js +57 -20
- package/dist/server/app-page-head.d.ts +12 -0
- package/dist/server/app-page-head.js +42 -19
- package/dist/server/app-page-params.d.ts +2 -1
- package/dist/server/app-page-params.js +8 -1
- package/dist/server/app-page-probe.d.ts +1 -0
- package/dist/server/app-page-probe.js +6 -1
- package/dist/server/app-page-render-identity.d.ts +1 -0
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render.d.ts +4 -1
- package/dist/server/app-page-render.js +8 -3
- package/dist/server/app-page-request.d.ts +22 -1
- package/dist/server/app-page-request.js +89 -13
- package/dist/server/app-page-route-wiring.d.ts +6 -1
- package/dist/server/app-page-route-wiring.js +31 -15
- package/dist/server/app-page-search-params-observation.d.ts +4 -2
- package/dist/server/app-page-search-params-observation.js +11 -7
- package/dist/server/app-page-segment-state.js +2 -0
- package/dist/server/app-route-handler-dispatch.js +1 -0
- package/dist/server/app-route-handler-execution.js +7 -2
- package/dist/server/app-route-handler-response.js +1 -0
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-module-loader.d.ts +2 -0
- package/dist/server/app-route-module-loader.js +1 -0
- package/dist/server/app-router-entry.d.ts +12 -0
- package/dist/server/app-router-entry.js +22 -8
- package/dist/server/app-router-image-optimization.d.ts +37 -0
- package/dist/server/app-router-image-optimization.js +40 -0
- package/dist/server/app-rsc-errors.js +7 -1
- package/dist/server/app-rsc-handler.js +27 -14
- package/dist/server/app-rsc-route-matching.d.ts +7 -0
- package/dist/server/app-rsc-route-matching.js +36 -3
- package/dist/server/app-segment-config.d.ts +12 -0
- package/dist/server/app-segment-config.js +91 -5
- package/dist/server/app-server-action-execution.d.ts +5 -0
- package/dist/server/app-server-action-execution.js +106 -33
- package/dist/server/app-ssr-entry.js +12 -1
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +1 -0
- package/dist/server/client-trace-metadata.js +26 -0
- package/dist/server/default-global-not-found-module.d.ts +14 -0
- package/dist/server/default-global-not-found-module.js +14 -0
- package/dist/server/dev-response-headers.d.ts +19 -0
- package/dist/server/dev-response-headers.js +78 -0
- package/dist/server/dev-server.js +8 -15
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/headers.d.ts +7 -15
- package/dist/server/headers.js +6 -15
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +2 -2
- package/dist/server/middleware-runtime.js +6 -1
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +14 -3
- package/dist/server/pages-asset-tags.d.ts +4 -6
- package/dist/server/pages-asset-tags.js +12 -12
- package/dist/server/pages-client-assets.d.ts +12 -0
- package/dist/server/pages-client-assets.js +10 -0
- package/dist/server/pages-page-data.d.ts +23 -1
- package/dist/server/pages-page-data.js +43 -24
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +10 -4
- package/dist/server/pages-request-pipeline.d.ts +2 -0
- package/dist/server/pages-request-pipeline.js +25 -1
- package/dist/server/prerender-manifest.d.ts +3 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.d.ts +1 -1
- package/dist/server/prod-server.js +47 -25
- package/dist/server/request-log.d.ts +5 -14
- package/dist/server/request-log.js +7 -1
- package/dist/server/request-pipeline.js +1 -0
- package/dist/server/seed-cache.js +4 -4
- package/dist/server/server-action-logger.d.ts +39 -0
- package/dist/server/server-action-logger.js +104 -0
- package/dist/server/worker-utils.d.ts +2 -1
- package/dist/server/worker-utils.js +7 -1
- package/dist/shims/app-router-scroll-state.d.ts +1 -0
- package/dist/shims/app-router-scroll-state.js +1 -0
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/cache.js +19 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/error-boundary.d.ts +19 -1
- package/dist/shims/error-boundary.js +11 -1
- package/dist/shims/form.d.ts +3 -1
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +9 -1
- package/dist/shims/headers.js +31 -6
- package/dist/shims/image-optimization-url.d.ts +4 -0
- package/dist/shims/image-optimization-url.js +33 -1
- package/dist/shims/image.js +46 -13
- package/dist/shims/internal/app-route-detection.d.ts +2 -17
- package/dist/shims/internal/app-route-detection.js +4 -17
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -5
- package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/link.js +23 -16
- package/dist/shims/metadata.d.ts +3 -2
- package/dist/shims/metadata.js +8 -4
- package/dist/shims/navigation.js +4 -2
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +2 -5
- package/dist/shims/router.js +41 -22
- package/dist/shims/server.js +3 -2
- package/dist/typegen.js +6 -5
- package/dist/utils/client-runtime-metadata.d.ts +2 -18
- package/dist/utils/client-runtime-metadata.js +31 -22
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
- package/dist/utils/domain-locale.d.ts +6 -3
- package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
- package/dist/{server → utils}/middleware-request-headers.js +2 -2
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +1 -1
- package/dist/utils/project.d.ts +9 -1
- package/dist/utils/project.js +21 -4
- package/dist/utils/protocol-headers.d.ts +17 -0
- package/dist/utils/protocol-headers.js +17 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/package.json +29 -23
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import { removeTrailingSlash, stripBasePath } from "../../utils/base-path.js";
|
|
2
2
|
import { getLocalePathPrefix } from "../../utils/domain-locale.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getPagesRouterComponentsMap } from "./pages-router-components.js";
|
|
4
4
|
//#region src/shims/internal/app-route-detection.ts
|
|
5
|
-
const _COMPONENTS_KEY = Symbol.for("vinext.pagesRouter.components");
|
|
6
|
-
/**
|
|
7
|
-
* Get-or-create the Pages Router `components` map. Returns the same object
|
|
8
|
-
* on every call so `router.components` and `window.next.router.components`
|
|
9
|
-
* have referential identity.
|
|
10
|
-
*/
|
|
11
|
-
function getPagesRouterComponentsMap() {
|
|
12
|
-
const globalState = globalThis;
|
|
13
|
-
let components = globalState[_COMPONENTS_KEY];
|
|
14
|
-
if (!components) {
|
|
15
|
-
components = {};
|
|
16
|
-
globalState[_COMPONENTS_KEY] = components;
|
|
17
|
-
}
|
|
18
|
-
return components;
|
|
19
|
-
}
|
|
20
5
|
/**
|
|
21
6
|
* Resolve a prefetch href to a same-origin pathname (basePath-stripped),
|
|
22
7
|
* suitable as the key used by Next.js for `router.components[urlPathname]`.
|
|
@@ -50,8 +35,10 @@ function resolveSameOriginPathname(href, basePath) {
|
|
|
50
35
|
* first (e.g. `link.tsx` normalises to match `trailingSlash` config before
|
|
51
36
|
* calling, while `router.prefetch()` passes the raw user-supplied URL).
|
|
52
37
|
*/
|
|
53
|
-
function markAppRouteDetectedOnPrefetch(href, basePath) {
|
|
38
|
+
async function markAppRouteDetectedOnPrefetch(href, basePath) {
|
|
54
39
|
if (typeof window === "undefined") return;
|
|
40
|
+
if (!window.__VINEXT_LINK_PREFETCH_ROUTES__?.length) return;
|
|
41
|
+
const { resolveHybridClientRouteOwner } = await import("./hybrid-client-route-owner.js");
|
|
55
42
|
if (resolveHybridClientRouteOwner(href, basePath) !== "app") return;
|
|
56
43
|
const rawPathname = resolveSameOriginPathname(href, basePath);
|
|
57
44
|
if (rawPathname === null) return;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { VinextLinkPrefetchRoute, VinextPagesLinkPrefetchRoute } from "../../client/vinext-next-data.js";
|
|
2
|
+
|
|
3
|
+
//#region src/shims/internal/hybrid-client-route-owner-direct.d.ts
|
|
4
|
+
type HybridClientOwner = "app" | "document" | "pages";
|
|
5
|
+
type HybridClientRouteMatches = {
|
|
6
|
+
appMatch: VinextLinkPrefetchRoute | null;
|
|
7
|
+
pagesMatch: VinextPagesLinkPrefetchRoute | null;
|
|
8
|
+
};
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
__VINEXT_LINK_PREFETCH_ROUTES__?: VinextLinkPrefetchRoute[];
|
|
12
|
+
__VINEXT_PAGES_LINK_PREFETCH_ROUTES__?: VinextPagesLinkPrefetchRoute[];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
declare function resolveSameOriginPathname(href: string, basePath: string): string | null;
|
|
16
|
+
declare function matchDirectHybridClientRoutes(href: string, basePath: string): HybridClientRouteMatches;
|
|
17
|
+
declare function resolveMatchedHybridClientRouteOwner({
|
|
18
|
+
appMatch,
|
|
19
|
+
pagesMatch
|
|
20
|
+
}: HybridClientRouteMatches): HybridClientOwner | null;
|
|
21
|
+
declare function resolveDirectHybridClientRouteOwner(href: string, basePath: string): HybridClientOwner | null;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { HybridClientOwner, matchDirectHybridClientRoutes, resolveDirectHybridClientRouteOwner, resolveMatchedHybridClientRouteOwner, resolveSameOriginPathname };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { compareHybridRoutePatterns } from "../../routing/utils.js";
|
|
2
|
+
import { stripBasePath } from "../../utils/base-path.js";
|
|
3
|
+
import { createRouteTrieCache, matchRouteWithTrie } from "../../routing/route-matching.js";
|
|
4
|
+
import { getLocalePathPrefix } from "../../utils/domain-locale.js";
|
|
5
|
+
//#region src/shims/internal/hybrid-client-route-owner-direct.ts
|
|
6
|
+
const appRouteTrieCache = createRouteTrieCache();
|
|
7
|
+
const pagesRouteTrieCache = createRouteTrieCache();
|
|
8
|
+
function patternFromParts(parts) {
|
|
9
|
+
return "/" + parts.join("/");
|
|
10
|
+
}
|
|
11
|
+
function resolveSameOriginPathname(href, basePath) {
|
|
12
|
+
if (typeof window === "undefined") return null;
|
|
13
|
+
let url;
|
|
14
|
+
try {
|
|
15
|
+
url = new URL(href, window.location.href);
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (url.origin !== window.location.origin) return null;
|
|
20
|
+
const pathname = stripBasePath(url.pathname, basePath);
|
|
21
|
+
const locale = getLocalePathPrefix(pathname, window.__VINEXT_LOCALES__);
|
|
22
|
+
if (!locale) return pathname;
|
|
23
|
+
const localePrefixLength = locale.length + 1;
|
|
24
|
+
return pathname.length === localePrefixLength ? "/" : pathname.slice(localePrefixLength);
|
|
25
|
+
}
|
|
26
|
+
function matchDirectHybridClientRoutes(href, basePath) {
|
|
27
|
+
const pathname = resolveSameOriginPathname(href, basePath);
|
|
28
|
+
if (pathname === null) return {
|
|
29
|
+
appMatch: null,
|
|
30
|
+
pagesMatch: null
|
|
31
|
+
};
|
|
32
|
+
const appRoutes = window.__VINEXT_LINK_PREFETCH_ROUTES__;
|
|
33
|
+
const pagesRoutes = window.__VINEXT_PAGES_LINK_PREFETCH_ROUTES__;
|
|
34
|
+
return {
|
|
35
|
+
appMatch: appRoutes ? matchRouteWithTrie(pathname, appRoutes, appRouteTrieCache)?.route ?? null : null,
|
|
36
|
+
pagesMatch: pagesRoutes ? matchRouteWithTrie(pathname, pagesRoutes, pagesRouteTrieCache)?.route ?? null : null
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function resolveMatchedHybridClientRouteOwner({ appMatch, pagesMatch }) {
|
|
40
|
+
if (appMatch === null && pagesMatch === null) return null;
|
|
41
|
+
if (pagesMatch === null) return appMatch.documentOnly ? "document" : "app";
|
|
42
|
+
if (appMatch === null) return pagesMatch.documentOnly ? "document" : "pages";
|
|
43
|
+
const owner = compareHybridRoutePatterns(patternFromParts(pagesMatch.patternParts), pagesMatch.isDynamic, patternFromParts(appMatch.patternParts), appMatch.isDynamic);
|
|
44
|
+
return (owner === "app" ? appMatch : pagesMatch).documentOnly ? "document" : owner;
|
|
45
|
+
}
|
|
46
|
+
function resolveDirectHybridClientRouteOwner(href, basePath) {
|
|
47
|
+
if (typeof window === "undefined") return null;
|
|
48
|
+
return resolveMatchedHybridClientRouteOwner(matchDirectHybridClientRoutes(href, basePath));
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { matchDirectHybridClientRoutes, resolveDirectHybridClientRouteOwner, resolveMatchedHybridClientRouteOwner, resolveSameOriginPathname };
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { NextRewrite } from "../../config/next-config.js";
|
|
2
|
-
import {
|
|
2
|
+
import { HybridClientOwner } from "./hybrid-client-route-owner-direct.js";
|
|
3
3
|
|
|
4
4
|
//#region src/shims/internal/hybrid-client-route-owner.d.ts
|
|
5
|
-
type HybridClientOwner = "app" | "document" | "pages";
|
|
6
5
|
declare global {
|
|
7
6
|
interface Window {
|
|
8
|
-
__VINEXT_LINK_PREFETCH_ROUTES__?: VinextLinkPrefetchRoute[];
|
|
9
|
-
__VINEXT_PAGES_LINK_PREFETCH_ROUTES__?: VinextPagesLinkPrefetchRoute[];
|
|
10
7
|
__VINEXT_CLIENT_REWRITES__?: {
|
|
11
8
|
afterFiles: NextRewrite[];
|
|
12
9
|
beforeFiles: NextRewrite[];
|
|
@@ -28,4 +25,4 @@ declare global {
|
|
|
28
25
|
*/
|
|
29
26
|
declare function resolveHybridClientRouteOwner(href: string, basePath: string): HybridClientOwner | null;
|
|
30
27
|
//#endregion
|
|
31
|
-
export { HybridClientOwner, resolveHybridClientRouteOwner };
|
|
28
|
+
export { type HybridClientOwner, resolveHybridClientRouteOwner };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { compareHybridRoutePatterns } from "../../routing/utils.js";
|
|
2
|
-
import { stripBasePath } from "../../utils/base-path.js";
|
|
3
|
-
import { createRouteTrieCache, matchRouteWithTrie } from "../../routing/route-matching.js";
|
|
4
1
|
import { isExternalUrl, matchRewrite, parseCookies } from "../../config/config-matchers.js";
|
|
5
|
-
import {
|
|
2
|
+
import { matchDirectHybridClientRoutes, resolveMatchedHybridClientRouteOwner, resolveSameOriginPathname } from "./hybrid-client-route-owner-direct.js";
|
|
6
3
|
import { mergeRewriteQuery } from "../../utils/query.js";
|
|
7
4
|
//#region src/shims/internal/hybrid-client-route-owner.ts
|
|
8
5
|
/**
|
|
@@ -52,45 +49,6 @@ function resolveClientRewrite(href, basePath, rewrites, continueAfterMatch = fal
|
|
|
52
49
|
kind: "rewrite"
|
|
53
50
|
} : null;
|
|
54
51
|
}
|
|
55
|
-
const appRouteTrieCache = createRouteTrieCache();
|
|
56
|
-
const pagesRouteTrieCache = createRouteTrieCache();
|
|
57
|
-
/**
|
|
58
|
-
* Build a `/`-joined pattern from a manifest's `patternParts`. Mirrors the
|
|
59
|
-
* server-side route-graph shape (`{ pattern: string }`) so the
|
|
60
|
-
* `compareHybridRoutePatterns` segment-rank comparator can score both Pages
|
|
61
|
-
* and App patterns. The
|
|
62
|
-
* `patternParts` array never includes an empty string for the static `/`
|
|
63
|
-
* route (the App catch-all handles the bare path), so the simple join is
|
|
64
|
-
* safe for everything the route trie actually matches.
|
|
65
|
-
*/
|
|
66
|
-
function patternFromParts(parts) {
|
|
67
|
-
return "/" + parts.join("/");
|
|
68
|
-
}
|
|
69
|
-
function resolveSameOriginPathname(href, basePath) {
|
|
70
|
-
if (typeof window === "undefined") return null;
|
|
71
|
-
let url;
|
|
72
|
-
try {
|
|
73
|
-
url = new URL(href, window.location.href);
|
|
74
|
-
} catch {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
if (url.origin !== window.location.origin) return null;
|
|
78
|
-
const pathname = stripBasePath(url.pathname, basePath);
|
|
79
|
-
const locale = getLocalePathPrefix(pathname, window.__VINEXT_LOCALES__);
|
|
80
|
-
if (!locale) return pathname;
|
|
81
|
-
const localePrefixLength = locale.length + 1;
|
|
82
|
-
return pathname.length === localePrefixLength ? "/" : pathname.slice(localePrefixLength);
|
|
83
|
-
}
|
|
84
|
-
function matchAppRoute(href, basePath, routes) {
|
|
85
|
-
const pathname = resolveSameOriginPathname(href, basePath);
|
|
86
|
-
if (pathname === null) return null;
|
|
87
|
-
return matchRouteWithTrie(pathname, routes, appRouteTrieCache)?.route ?? null;
|
|
88
|
-
}
|
|
89
|
-
function matchPagesRoute(href, basePath, routes) {
|
|
90
|
-
const pathname = resolveSameOriginPathname(href, basePath);
|
|
91
|
-
if (pathname === null) return null;
|
|
92
|
-
return matchRouteWithTrie(pathname, routes, pagesRouteTrieCache)?.route ?? null;
|
|
93
|
-
}
|
|
94
52
|
/**
|
|
95
53
|
* Decide which router should own a soft-navigated URL. Returns:
|
|
96
54
|
* - "app" → the App Router runtime handles the navigation (RSC fetch).
|
|
@@ -105,39 +63,30 @@ function matchPagesRoute(href, basePath, routes) {
|
|
|
105
63
|
*/
|
|
106
64
|
function resolveHybridClientRouteOwner(href, basePath) {
|
|
107
65
|
if (typeof window === "undefined") return null;
|
|
108
|
-
const appRoutes = window.__VINEXT_LINK_PREFETCH_ROUTES__;
|
|
109
|
-
const pagesRoutes = window.__VINEXT_PAGES_LINK_PREFETCH_ROUTES__;
|
|
110
66
|
const rewrites = window.__VINEXT_CLIENT_REWRITES__;
|
|
111
67
|
if (rewrites) {
|
|
112
68
|
const beforeFilesRewrite = resolveClientRewrite(href, basePath, rewrites.beforeFiles, true);
|
|
113
69
|
if (beforeFilesRewrite?.kind === "document") return "document";
|
|
114
70
|
if (beforeFilesRewrite?.kind === "rewrite") href = beforeFilesRewrite.href;
|
|
115
71
|
}
|
|
116
|
-
let
|
|
117
|
-
|
|
118
|
-
if (rewrites && (appMatch === null || appMatch.isDynamic) && (pagesMatch === null || pagesMatch.isDynamic)) for (const rewrite of rewrites.afterFiles) {
|
|
72
|
+
let matches = matchDirectHybridClientRoutes(href, basePath);
|
|
73
|
+
if (rewrites && (matches.appMatch === null || matches.appMatch.isDynamic) && (matches.pagesMatch === null || matches.pagesMatch.isDynamic)) for (const rewrite of rewrites.afterFiles) {
|
|
119
74
|
const afterFilesRewrite = resolveClientRewrite(href, basePath, [rewrite]);
|
|
120
75
|
if (afterFilesRewrite?.kind === "document") return "document";
|
|
121
76
|
if (afterFilesRewrite?.kind !== "rewrite") continue;
|
|
122
77
|
href = afterFilesRewrite.href;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (appMatch || pagesMatch) break;
|
|
78
|
+
matches = matchDirectHybridClientRoutes(href, basePath);
|
|
79
|
+
if (matches.appMatch || matches.pagesMatch) break;
|
|
126
80
|
}
|
|
127
|
-
if (rewrites && appMatch === null && pagesMatch === null) for (const rewrite of rewrites.fallback) {
|
|
81
|
+
if (rewrites && matches.appMatch === null && matches.pagesMatch === null) for (const rewrite of rewrites.fallback) {
|
|
128
82
|
const fallbackRewrite = resolveClientRewrite(href, basePath, [rewrite]);
|
|
129
83
|
if (fallbackRewrite?.kind === "document") return "document";
|
|
130
84
|
if (fallbackRewrite?.kind !== "rewrite") continue;
|
|
131
85
|
href = fallbackRewrite.href;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (appMatch || pagesMatch) break;
|
|
86
|
+
matches = matchDirectHybridClientRoutes(href, basePath);
|
|
87
|
+
if (matches.appMatch || matches.pagesMatch) break;
|
|
135
88
|
}
|
|
136
|
-
|
|
137
|
-
if (pagesMatch === null) return appMatch.documentOnly ? "document" : "app";
|
|
138
|
-
if (appMatch === null) return pagesMatch.documentOnly ? "document" : "pages";
|
|
139
|
-
const owner = compareHybridRoutePatterns(patternFromParts(pagesMatch.patternParts), pagesMatch.isDynamic, patternFromParts(appMatch.patternParts), appMatch.isDynamic);
|
|
140
|
-
return (owner === "app" ? appMatch : pagesMatch).documentOnly ? "document" : owner;
|
|
89
|
+
return resolveMatchedHybridClientRouteOwner(matches);
|
|
141
90
|
}
|
|
142
91
|
//#endregion
|
|
143
92
|
export { resolveHybridClientRouteOwner };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/shims/internal/pages-router-components.d.ts
|
|
2
|
+
type PagesRouterComponentsMap = Record<string, {
|
|
3
|
+
__appRouter: true;
|
|
4
|
+
} | Record<string, unknown>>;
|
|
5
|
+
declare function getPagesRouterComponentsMap(): PagesRouterComponentsMap;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { PagesRouterComponentsMap, getPagesRouterComponentsMap };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/shims/internal/pages-router-components.ts
|
|
2
|
+
const COMPONENTS_KEY = Symbol.for("vinext.pagesRouter.components");
|
|
3
|
+
function getPagesRouterComponentsMap() {
|
|
4
|
+
const globalState = globalThis;
|
|
5
|
+
let components = globalState[COMPONENTS_KEY];
|
|
6
|
+
if (!components) {
|
|
7
|
+
components = {};
|
|
8
|
+
globalState[COMPONENTS_KEY] = components;
|
|
9
|
+
}
|
|
10
|
+
return components;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { getPagesRouterComponentsMap };
|
package/dist/shims/link.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { stripBasePath } from "../utils/base-path.js";
|
|
3
3
|
import { createRouteTrieCache, matchRouteWithTrie } from "../routing/route-matching.js";
|
|
4
|
-
import { VINEXT_MOUNTED_SLOTS_HEADER } from "../server/headers.js";
|
|
5
4
|
import { isDangerousScheme, reportBlockedDangerousNavigation } from "./url-safety.js";
|
|
6
|
-
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
7
|
-
import { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "../server/app-rsc-render-mode.js";
|
|
8
|
-
import "../server/app-elements.js";
|
|
9
5
|
import { addLocalePrefix, getDomainLocaleUrl } from "../utils/domain-locale.js";
|
|
10
6
|
import { prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.js";
|
|
11
|
-
import { appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
|
|
12
|
-
import { resolveHybridClientRouteOwner } from "./internal/hybrid-client-route-owner.js";
|
|
13
7
|
import { markAppRouteDetectedOnPrefetch } from "./internal/app-route-detection.js";
|
|
14
8
|
import { isAbsoluteOrProtocolRelativeUrl, normalizePathTrailingSlash, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
9
|
+
import { appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
|
|
15
10
|
import { interpolateDynamicRouteHref } from "./internal/interpolate-as.js";
|
|
16
11
|
import { getCurrentBrowserLocale } from "./client-locale.js";
|
|
17
12
|
import { getCurrentRoutePathnameForWarning } from "./internal/route-pattern-for-warning.js";
|
|
18
|
-
import {
|
|
13
|
+
import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
19
14
|
import { getNavigationRuntime, hasAppNavigationRuntime, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
|
|
20
15
|
import { navigatePagesRouterLinkWithFallback, resolvePagesRouterQueryOnlyHref } from "../client/pages-router-link-navigation.js";
|
|
21
|
-
import { getMountedSlotsHeader, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, navigateClientSide, prefetchRscResponse } from "./navigation.js";
|
|
22
16
|
import { getI18nContext } from "./i18n-context.js";
|
|
23
17
|
import { canLinkIntentPrefetch, canLinkPrefetch, getLinkPrefetchHref } from "./link-prefetch.js";
|
|
24
18
|
import { clearLinkForCurrentNavigation, notifyLinkNavigationStart, setLinkForCurrentNavigation } from "./internal/link-status-registry.js";
|
|
@@ -211,6 +205,17 @@ function prefetchUrl(href, mode, priority = "low") {
|
|
|
211
205
|
} : window.requestIdleCallback ?? ((fn) => setTimeout(fn, 100)))(() => {
|
|
212
206
|
(async () => {
|
|
213
207
|
if (hasAppNavigationRuntime()) {
|
|
208
|
+
if (isBotUserAgent(window.navigator?.userAgent ?? "")) return;
|
|
209
|
+
const [navigation, { AppElementsWire }, rscCacheBusting, { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL }, { VINEXT_MOUNTED_SLOTS_HEADER }, { resolveHybridClientRouteOwner }] = await Promise.all([
|
|
210
|
+
import("./navigation.js"),
|
|
211
|
+
import("../server/app-elements.js"),
|
|
212
|
+
import("../server/app-rsc-cache-busting.js"),
|
|
213
|
+
import("../server/app-rsc-render-mode.js"),
|
|
214
|
+
import("../server/headers.js"),
|
|
215
|
+
import("./internal/hybrid-client-route-owner.js")
|
|
216
|
+
]);
|
|
217
|
+
const { getPrefetchInterceptionContext, getPrefetchCache, getPrefetchedUrls, getMountedSlotsHeader, hasPrefetchCacheEntryForNavigation, prefetchRscResponse } = navigation;
|
|
218
|
+
const { createRscRequestHeaders, createRscRequestUrl } = rscCacheBusting;
|
|
214
219
|
const hybridOwner = resolveHybridClientRouteOwner(prefetchHref, __basePath);
|
|
215
220
|
if (hybridOwner === "pages" || hybridOwner === "document") return;
|
|
216
221
|
const autoPrefetch = mode === "auto" ? resolveAutoAppRoutePrefetch(prefetchHref) : {
|
|
@@ -272,7 +277,7 @@ function prefetchUrl(href, mode, priority = "low") {
|
|
|
272
277
|
const dataTarget = resolvePagesDataNavigationTarget(fullHref, __basePath);
|
|
273
278
|
if (dataTarget) prefetchPagesData(dataTarget);
|
|
274
279
|
else {
|
|
275
|
-
markAppRouteDetectedOnPrefetch(fullHref, __basePath);
|
|
280
|
+
await markAppRouteDetectedOnPrefetch(fullHref, __basePath);
|
|
276
281
|
const link = document.createElement("link");
|
|
277
282
|
link.rel = "prefetch";
|
|
278
283
|
link.href = fullHref;
|
|
@@ -285,8 +290,10 @@ function prefetchUrl(href, mode, priority = "low") {
|
|
|
285
290
|
});
|
|
286
291
|
});
|
|
287
292
|
}
|
|
288
|
-
function promotePrefetchEntriesForNavigation(href) {
|
|
293
|
+
async function promotePrefetchEntriesForNavigation(href) {
|
|
289
294
|
if (typeof window === "undefined") return;
|
|
295
|
+
if (!hasAppNavigationRuntime()) return;
|
|
296
|
+
const [{ getPrefetchCache }, { stripRscCacheBustingSearchParam, stripRscSuffix }] = await Promise.all([import("./navigation.js"), import("../server/app-rsc-cache-busting.js")]);
|
|
290
297
|
let target;
|
|
291
298
|
try {
|
|
292
299
|
target = new URL(toBrowserNavigationHref(href, window.location.href, __basePath), window.location.href);
|
|
@@ -553,12 +560,14 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
553
560
|
onNavigate(navEvent);
|
|
554
561
|
if (navEvent.defaultPrevented) return;
|
|
555
562
|
} catch {}
|
|
556
|
-
|
|
563
|
+
const hybridOwner = HAS_PAGES_ROUTER && hasAppNavigationRuntime ? (await import("./internal/hybrid-client-route-owner.js")).resolveHybridClientRouteOwner(navigateHref, __basePath) : null;
|
|
564
|
+
if (HAS_PAGES_ROUTER && hasAppNavigationRuntime && ["pages", "document"].includes(hybridOwner ?? "")) {
|
|
557
565
|
if (replace) window.location.replace(absoluteFullHref);
|
|
558
566
|
else window.location.assign(absoluteFullHref);
|
|
559
567
|
return;
|
|
560
568
|
}
|
|
561
569
|
if (hasAppNavigationRuntime) {
|
|
570
|
+
const { navigateClientSide } = await import("./navigation.js");
|
|
562
571
|
const setter = setPendingRef.current;
|
|
563
572
|
if (setter) setLinkForCurrentNavigation(setter);
|
|
564
573
|
setPending(true);
|
|
@@ -573,7 +582,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
573
582
|
const Router = window.next?.appDir === true ? void 0 : window.next?.router;
|
|
574
583
|
await navigatePagesRouterLinkWithFallback({
|
|
575
584
|
router: Router && "reload" in Router ? Router : void 0,
|
|
576
|
-
loadRouter: async () => (await import("next
|
|
585
|
+
loadRouter: async () => (await import("D:\\projects\\vinext\\node_modules\\.pnpm\\next@16.2.7_@opentelemetry+_a27effa3fabbfbd07255229e73bfb661\\node_modules\\next\\router.js")).default,
|
|
577
586
|
navigation: {
|
|
578
587
|
href: pagesHrefForLink,
|
|
579
588
|
as: pagesAsForLink,
|
|
@@ -651,7 +660,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
651
660
|
onClick: (event) => {
|
|
652
661
|
if (childOnClick) childOnClick(event);
|
|
653
662
|
if (event.defaultPrevented) return;
|
|
654
|
-
handleClick(event, { skipLinkOnClick: true });
|
|
663
|
+
return handleClick(event, { skipLinkOnClick: true });
|
|
655
664
|
},
|
|
656
665
|
onMouseEnter: (event) => {
|
|
657
666
|
if (childOnMouseEnter) childOnMouseEnter(event);
|
|
@@ -673,9 +682,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
673
682
|
children: /* @__PURE__ */ jsx("a", {
|
|
674
683
|
ref: setRefs,
|
|
675
684
|
href: fullHref,
|
|
676
|
-
onClick:
|
|
677
|
-
handleClick(event);
|
|
678
|
-
},
|
|
685
|
+
onClick: handleClick,
|
|
679
686
|
onMouseEnter: handleMouseEnter,
|
|
680
687
|
onTouchStart: handleTouchStart,
|
|
681
688
|
...anchorProps,
|
package/dist/shims/metadata.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ThenableParamsObserver } from "./thenable-params.js";
|
|
1
2
|
import React from "react";
|
|
2
3
|
|
|
3
4
|
//#region src/shims/metadata.d.ts
|
|
@@ -18,7 +19,7 @@ type Viewport = {
|
|
|
18
19
|
* Resolve viewport config from a module. Handles both static `viewport` export
|
|
19
20
|
* and async `generateViewport()` function.
|
|
20
21
|
*/
|
|
21
|
-
declare function resolveModuleViewport(mod: Record<string, unknown>, params: Record<string, string | string[]
|
|
22
|
+
declare function resolveModuleViewport(mod: Record<string, unknown>, params: Record<string, string | string[]>, searchParams?: Record<string, string | string[]>, searchParamsObserver?: ThenableParamsObserver): Promise<Viewport | null>;
|
|
22
23
|
/**
|
|
23
24
|
* Merge viewport configs from multiple sources (layouts + page).
|
|
24
25
|
* Later entries override earlier ones.
|
|
@@ -267,7 +268,7 @@ declare function mergeMetadataEntries(entries: readonly MetadataMergeEntry[]): M
|
|
|
267
268
|
* resolution approach. If not provided, defaults to a promise that resolves
|
|
268
269
|
* to an empty object (so `await parent` never throws).
|
|
269
270
|
*/
|
|
270
|
-
declare function resolveModuleMetadata(mod: Record<string, unknown>, params?: Record<string, string | string[]>, searchParams?: Record<string, string | string[]>, parent?: Promise<Metadata
|
|
271
|
+
declare function resolveModuleMetadata(mod: Record<string, unknown>, params?: Record<string, string | string[]>, searchParams?: Record<string, string | string[]>, parent?: Promise<Metadata>, searchParamsObserver?: ThenableParamsObserver): Promise<Metadata | null>;
|
|
271
272
|
type MetadataHeadProps = {
|
|
272
273
|
metadata: Metadata;
|
|
273
274
|
pathname?: string;
|
package/dist/shims/metadata.js
CHANGED
|
@@ -13,10 +13,14 @@ import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
|
13
13
|
* Resolve viewport config from a module. Handles both static `viewport` export
|
|
14
14
|
* and async `generateViewport()` function.
|
|
15
15
|
*/
|
|
16
|
-
async function resolveModuleViewport(mod, params) {
|
|
16
|
+
async function resolveModuleViewport(mod, params, searchParams, searchParamsObserver) {
|
|
17
17
|
if (typeof mod.generateViewport === "function") {
|
|
18
18
|
const asyncParams = makeThenableParams(params);
|
|
19
|
-
|
|
19
|
+
const props = searchParams === void 0 ? { params: asyncParams } : {
|
|
20
|
+
params: asyncParams,
|
|
21
|
+
searchParams: makeThenableParams(searchParams, searchParamsObserver)
|
|
22
|
+
};
|
|
23
|
+
return await mod.generateViewport(props);
|
|
20
24
|
}
|
|
21
25
|
if (mod.viewport && typeof mod.viewport === "object") return mod.viewport;
|
|
22
26
|
return null;
|
|
@@ -213,12 +217,12 @@ function mergeMetadataEntries(entries) {
|
|
|
213
217
|
* resolution approach. If not provided, defaults to a promise that resolves
|
|
214
218
|
* to an empty object (so `await parent` never throws).
|
|
215
219
|
*/
|
|
216
|
-
async function resolveModuleMetadata(mod, params = {}, searchParams, parent = Promise.resolve({})) {
|
|
220
|
+
async function resolveModuleMetadata(mod, params = {}, searchParams, parent = Promise.resolve({}), searchParamsObserver) {
|
|
217
221
|
if (typeof mod.generateMetadata === "function") {
|
|
218
222
|
const asyncParams = makeThenableParams(params);
|
|
219
223
|
const props = searchParams === void 0 ? { params: asyncParams } : {
|
|
220
224
|
params: asyncParams,
|
|
221
|
-
searchParams: makeThenableParams(searchParams)
|
|
225
|
+
searchParams: makeThenableParams(searchParams, searchParamsObserver)
|
|
222
226
|
};
|
|
223
227
|
return await (mod.generateMetadata.length >= 2 ? mod.generateMetadata(props, parent) : mod.generateMetadata(props));
|
|
224
228
|
}
|
package/dist/shims/navigation.js
CHANGED
|
@@ -5,11 +5,11 @@ import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
|
5
5
|
import "../server/app-elements.js";
|
|
6
6
|
import { markPprFallbackShellDynamicBoundary } from "./ppr-fallback-shell.js";
|
|
7
7
|
import { AppRouterContext } from "./internal/app-router-context.js";
|
|
8
|
-
import { resolveHybridClientRouteOwner } from "./internal/hybrid-client-route-owner.js";
|
|
9
8
|
import { isAbsoluteOrProtocolRelativeUrl, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
10
9
|
import { retryScrollTo, scrollToHashTarget } from "./hash-scroll.js";
|
|
11
10
|
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
12
11
|
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";
|
|
12
|
+
import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
13
13
|
import { clearAppNavigationFailureTarget, stageAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
|
|
14
14
|
import { beginAppRouterScrollIntent, clearAppRouterScrollIntent, consumeAppRouterScrollIntent, getPendingAppRouterScrollIntent } from "./app-router-scroll-state.js";
|
|
15
15
|
import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam } from "../server/app-rsc-cache-busting.js";
|
|
@@ -22,6 +22,7 @@ import { hasPendingAppRouterPageRedirect } from "../server/app-browser-mpa-navig
|
|
|
22
22
|
import { navigationPlanner } from "../server/navigation-planner.js";
|
|
23
23
|
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
24
24
|
import { getPagesNavigationContext } from "./internal/pages-router-accessor.js";
|
|
25
|
+
import { resolveHybridClientRouteOwner } from "./internal/hybrid-client-route-owner.js";
|
|
25
26
|
import { UnrecognizedActionError, unstable_isUnrecognizedActionError } from "./unrecognized-action-error.js";
|
|
26
27
|
import * as React$1 from "react";
|
|
27
28
|
//#region src/shims/navigation.ts
|
|
@@ -41,7 +42,7 @@ function useChildSegments(parallelRoutesKey = "children") {
|
|
|
41
42
|
const ctx = getLayoutSegmentContext();
|
|
42
43
|
if (!ctx) return [];
|
|
43
44
|
try {
|
|
44
|
-
return React$1.useContext(ctx)[parallelRoutesKey] ?? [];
|
|
45
|
+
return (React$1.useContext(ctx)[parallelRoutesKey] ?? []).filter((segment) => !segment.startsWith("__PAGE__"));
|
|
45
46
|
} catch {
|
|
46
47
|
return [];
|
|
47
48
|
}
|
|
@@ -1033,6 +1034,7 @@ const _appRouter = {
|
|
|
1033
1034
|
prefetch(href, options) {
|
|
1034
1035
|
assertSafeNavigationUrl(href);
|
|
1035
1036
|
if (isServer) return;
|
|
1037
|
+
if (isBotUserAgent(window.navigator?.userAgent ?? "")) return;
|
|
1036
1038
|
try {
|
|
1037
1039
|
new URL(withBasePath(href, __basePath), window.location.href);
|
|
1038
1040
|
} catch {
|
|
@@ -3,10 +3,24 @@ type RootParams = Record<string, string | string[] | undefined>;
|
|
|
3
3
|
type RootParamsState = {
|
|
4
4
|
rootParams: RootParams | null;
|
|
5
5
|
};
|
|
6
|
+
type RootParamsUsage = {
|
|
7
|
+
kind: "route";
|
|
8
|
+
} | {
|
|
9
|
+
kind: "server-action";
|
|
10
|
+
} | {
|
|
11
|
+
kind: "route-handler";
|
|
12
|
+
routePattern: string;
|
|
13
|
+
};
|
|
14
|
+
type RootParamsUsageController = {
|
|
15
|
+
transitionToRender(): void;
|
|
16
|
+
};
|
|
6
17
|
declare function pickRootParams(params: RootParams, rootParamNames: readonly string[] | null | undefined): RootParams;
|
|
7
18
|
declare function setRootParams(params: RootParams | null): void;
|
|
8
19
|
declare function getRootParam(name: string): Promise<string | string[] | undefined>;
|
|
20
|
+
declare function runWithRootParamsUsage<T>(usage: RootParamsUsage, fn: () => Promise<T>, controller?: RootParamsUsageController): Promise<T>;
|
|
21
|
+
declare function runWithRootParamsUsage<T>(usage: RootParamsUsage, fn: () => T | Promise<T>, controller?: RootParamsUsageController): T | Promise<T>;
|
|
22
|
+
declare function createRootParamsUsageController(): RootParamsUsageController;
|
|
9
23
|
declare function runWithRootParamsScope<T>(params: RootParams, fn: () => Promise<T>): Promise<T>;
|
|
10
24
|
declare function runWithRootParamsScope<T>(params: RootParams, fn: () => T | Promise<T>): T | Promise<T>;
|
|
11
25
|
//#endregion
|
|
12
|
-
export { RootParams, RootParamsState, getRootParam, pickRootParams, runWithRootParamsScope, setRootParams };
|
|
26
|
+
export { RootParams, RootParamsState, RootParamsUsage, RootParamsUsageController, createRootParamsUsageController, getRootParam, pickRootParams, runWithRootParamsScope, runWithRootParamsUsage, setRootParams };
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { getOrCreateAls } from "./internal/als-registry.js";
|
|
2
2
|
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
3
3
|
//#region src/shims/root-params.ts
|
|
4
|
+
function createRootParamsUsageError(message) {
|
|
5
|
+
return new Error(message);
|
|
6
|
+
}
|
|
4
7
|
const _FALLBACK_KEY = Symbol.for("vinext.rootParams.fallback");
|
|
5
8
|
const _g = globalThis;
|
|
6
9
|
const _als = getOrCreateAls("vinext.rootParams.als");
|
|
10
|
+
const _usageAls = getOrCreateAls("vinext.rootParams.usage.als");
|
|
7
11
|
const _fallbackState = _g[_FALLBACK_KEY] ??= { rootParams: null };
|
|
8
12
|
function getState() {
|
|
9
13
|
if (isInsideUnifiedScope()) return getRequestContext();
|
|
@@ -18,8 +22,24 @@ function setRootParams(params) {
|
|
|
18
22
|
getState().rootParams = params;
|
|
19
23
|
}
|
|
20
24
|
function getRootParam(name) {
|
|
25
|
+
const usage = _usageAls.getStore();
|
|
26
|
+
if (usage?.kind === "server-action" && usage.phase === "active") throw createRootParamsUsageError(`\`import('next/root-params').${name}()\` was used inside a Server Action. This is not supported. Functions from 'next/root-params' can only be called in the context of a route.`);
|
|
27
|
+
if (usage?.kind === "route-handler" && usage.phase === "active") throw createRootParamsUsageError(`Route ${usage.routePattern} used \`import('next/root-params').${name}()\` inside a Route Handler. Support for this API in Route Handlers is planned for a future version of Next.js.`);
|
|
21
28
|
return Promise.resolve(getState().rootParams?.[name]);
|
|
22
29
|
}
|
|
30
|
+
function runWithRootParamsUsage(usage, fn, controller) {
|
|
31
|
+
const state = {
|
|
32
|
+
...usage,
|
|
33
|
+
phase: "active"
|
|
34
|
+
};
|
|
35
|
+
if (controller) controller.transitionToRender = () => {
|
|
36
|
+
if (usage.kind === "server-action") state.phase = "render";
|
|
37
|
+
};
|
|
38
|
+
return _usageAls.run(state, fn);
|
|
39
|
+
}
|
|
40
|
+
function createRootParamsUsageController() {
|
|
41
|
+
return { transitionToRender() {} };
|
|
42
|
+
}
|
|
23
43
|
function runWithRootParamsScope(params, fn) {
|
|
24
44
|
if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((ctx) => {
|
|
25
45
|
ctx.rootParams = params;
|
|
@@ -27,4 +47,4 @@ function runWithRootParamsScope(params, fn) {
|
|
|
27
47
|
else return _als.run({ rootParams: params }, fn);
|
|
28
48
|
}
|
|
29
49
|
//#endregion
|
|
30
|
-
export { getRootParam, pickRootParams, runWithRootParamsScope, setRootParams };
|
|
50
|
+
export { createRootParamsUsageController, getRootParam, pickRootParams, runWithRootParamsScope, runWithRootParamsUsage, setRootParams };
|
package/dist/shims/router.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { VinextNextData } from "../client/vinext-next-data.js";
|
|
2
|
+
import { PagesRouterComponentsMap } from "./internal/pages-router-components.js";
|
|
2
3
|
import { UrlQuery } from "../utils/query.js";
|
|
3
4
|
import { ComponentType, ReactElement } from "react";
|
|
4
5
|
|
|
@@ -174,11 +175,7 @@ type ExcludeRouterProps<P> = Pick<P, Exclude<keyof P, keyof WithRouterProps>>;
|
|
|
174
175
|
*/
|
|
175
176
|
declare function withRouter<P extends WithRouterProps>(ComposedComponent: ComponentType<P>): ComponentType<ExcludeRouterProps<P>>;
|
|
176
177
|
declare const RouterMethods: {
|
|
177
|
-
/** See `_components` comment above for the dual role this map plays. */components:
|
|
178
|
-
[x: string]: {
|
|
179
|
-
__appRouter: true;
|
|
180
|
-
} | Record<string, unknown>;
|
|
181
|
-
};
|
|
178
|
+
/** See `_components` comment above for the dual role this map plays. */components: PagesRouterComponentsMap;
|
|
182
179
|
push: (url: string | UrlObject, as?: string, options?: TransitionOptions) => Promise<boolean>;
|
|
183
180
|
replace: (url: string | UrlObject, as?: string, options?: TransitionOptions) => Promise<boolean>;
|
|
184
181
|
back: () => void;
|