vinext 0.1.7 → 0.2.0
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 +51 -30
- package/dist/build/inject-pregenerated-paths.d.ts +4 -0
- package/dist/build/inject-pregenerated-paths.js +18 -0
- package/dist/build/layout-classification.js +1 -1
- package/dist/build/nitro-route-rules.js +1 -1
- 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 +13 -6
- package/dist/build/report.d.ts +13 -2
- package/dist/build/report.js +99 -2
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +10 -1
- package/dist/build/standalone.js +2 -0
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.d.ts +18 -0
- package/dist/check.js +77 -19
- package/dist/cli-args.d.ts +1 -2
- package/dist/cli-args.js +1 -1
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +113 -97
- 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/client/navigation-runtime.d.ts +2 -0
- package/dist/client/navigation-runtime.js +3 -1
- package/dist/client/window-next.d.ts +2 -1
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- 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/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/config/server-external-packages.d.ts +4 -0
- package/dist/config/server-external-packages.js +91 -0
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +89 -15
- package/dist/entries/app-rsc-manifest.js +10 -0
- package/dist/entries/pages-client-entry.d.ts +3 -0
- package/dist/entries/pages-client-entry.js +16 -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 +59 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +211 -118
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +839 -0
- package/dist/init-platform.d.ts +40 -0
- package/dist/init-platform.js +195 -0
- package/dist/init.d.ts +16 -38
- package/dist/init.js +208 -97
- 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/packages/cloudflare/src/deploy-config.js +150 -0
- package/dist/packages/cloudflare/src/deploy-help.js +55 -0
- package/dist/packages/cloudflare/src/deploy.js +276 -0
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +18 -15
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.d.ts +27 -1
- package/dist/plugins/ast-utils.js +32 -1
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- 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 +29 -4
- package/dist/routing/app-route-graph.js +182 -40
- 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/api-handler.js +9 -14
- package/dist/server/app-browser-action-result.d.ts +4 -1
- package/dist/server/app-browser-action-result.js +8 -1
- package/dist/server/app-browser-entry.js +194 -190
- 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.d.ts +2 -0
- package/dist/server/app-browser-navigation-controller.js +60 -31
- package/dist/server/app-browser-server-action-client.d.ts +32 -0
- package/dist/server/app-browser-server-action-client.js +127 -0
- package/dist/server/app-browser-state.d.ts +11 -1
- package/dist/server/app-browser-state.js +25 -8
- package/dist/server/app-browser-visible-commit.d.ts +6 -1
- package/dist/server/app-browser-visible-commit.js +43 -25
- package/dist/server/app-elements-wire.d.ts +9 -2
- package/dist/server/app-elements-wire.js +8 -1
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +4 -3
- package/dist/server/app-fallback-renderer.d.ts +5 -2
- package/dist/server/app-fallback-renderer.js +15 -7
- package/dist/server/app-hydration-cache-publication.d.ts +11 -0
- package/dist/server/app-hydration-cache-publication.js +43 -0
- package/dist/server/app-middleware.d.ts +4 -3
- package/dist/server/app-middleware.js +8 -3
- package/dist/server/app-optimistic-routing.js +11 -4
- package/dist/server/app-page-boundary-render.d.ts +3 -0
- package/dist/server/app-page-boundary-render.js +14 -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 +5 -2
- package/dist/server/app-page-dispatch.d.ts +33 -4
- package/dist/server/app-page-dispatch.js +63 -90
- package/dist/server/app-page-element-builder.d.ts +9 -2
- package/dist/server/app-page-element-builder.js +114 -23
- package/dist/server/app-page-head.d.ts +16 -1
- package/dist/server/app-page-head.js +44 -22
- package/dist/server/app-page-params.d.ts +2 -1
- package/dist/server/app-page-params.js +8 -1
- package/dist/server/app-page-ppr-runtime.d.ts +7 -0
- package/dist/server/app-page-ppr-runtime.js +70 -0
- 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 +26 -3
- package/dist/server/app-page-request.d.ts +22 -1
- package/dist/server/app-page-request.js +92 -15
- package/dist/server/app-page-route-wiring.d.ts +14 -2
- package/dist/server/app-page-route-wiring.js +61 -25
- 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.d.ts +2 -1
- package/dist/server/app-page-segment-state.js +3 -1
- package/dist/server/app-page-stream.d.ts +5 -0
- package/dist/server/app-page-stream.js +3 -1
- package/dist/server/app-ppr-fallback-shell-render.d.ts +4 -3
- 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.js +16 -8
- package/dist/server/app-rsc-errors.js +7 -1
- package/dist/server/app-rsc-handler.d.ts +3 -1
- package/dist/server/app-rsc-handler.js +67 -39
- package/dist/server/app-rsc-request-normalization.d.ts +3 -2
- package/dist/server/app-rsc-request-normalization.js +6 -3
- 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 +94 -33
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +19 -8
- package/dist/server/app-ssr-stream.d.ts +7 -3
- package/dist/server/app-ssr-stream.js +10 -6
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +1 -0
- package/dist/server/app-visited-response-cache.d.ts +6 -0
- package/dist/server/app-visited-response-cache.js +3 -1
- 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-route-files.js +4 -0
- package/dist/server/dev-server.js +19 -18
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/fetch-handler.d.ts +2 -0
- package/dist/server/fetch-handler.js +18 -0
- package/dist/server/headers.d.ts +5 -15
- package/dist/server/headers.js +4 -15
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/implicit-tags.js +1 -1
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +2 -2
- package/dist/server/metadata-routes.d.ts +3 -1
- package/dist/server/metadata-routes.js +12 -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-api-route.js +2 -2
- 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-node-compat.d.ts +8 -1
- package/dist/server/pages-node-compat.js +32 -4
- package/dist/server/pages-page-data.d.ts +24 -1
- package/dist/server/pages-page-data.js +45 -24
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +19 -12
- package/dist/server/pages-page-response.d.ts +7 -0
- package/dist/server/pages-page-response.js +4 -1
- package/dist/server/pages-request-pipeline.d.ts +2 -0
- package/dist/server/pages-request-pipeline.js +25 -1
- package/dist/server/pages-router-entry.d.ts +30 -0
- package/dist/server/pages-router-entry.js +108 -0
- 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 +48 -26
- package/dist/server/request-pipeline.js +1 -0
- package/dist/server/seed-cache.js +4 -4
- 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.js +75 -14
- 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 -15
- package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +9 -5
- package/dist/shims/internal/pages-data-fetch-dedup.js +73 -14
- package/dist/shims/internal/pages-data-target.d.ts +10 -9
- package/dist/shims/internal/pages-data-target.js +91 -12
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/layout-segment-context.d.ts +4 -1
- package/dist/shims/layout-segment-context.js +18 -4
- package/dist/shims/link.js +70 -37
- package/dist/shims/metadata.d.ts +3 -2
- package/dist/shims/metadata.js +8 -4
- package/dist/shims/navigation.d.ts +5 -1
- package/dist/shims/navigation.js +45 -10
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +5 -7
- package/dist/shims/router.js +374 -94
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- 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 +52 -2
- package/dist/utils/project.js +230 -5
- 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 +53 -4
- package/dist/deploy.d.ts +0 -190
- package/dist/deploy.js +0 -1033
- 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,19 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { VinextLinkPrefetchRoute, VinextPagesLinkPrefetchRoute } from "../../client/vinext-next-data.js";
|
|
1
|
+
import { HybridClientOwner } from "./hybrid-client-route-owner-direct.js";
|
|
3
2
|
|
|
4
3
|
//#region src/shims/internal/hybrid-client-route-owner.d.ts
|
|
5
|
-
type HybridClientOwner = "app" | "document" | "pages";
|
|
6
|
-
declare global {
|
|
7
|
-
interface Window {
|
|
8
|
-
__VINEXT_LINK_PREFETCH_ROUTES__?: VinextLinkPrefetchRoute[];
|
|
9
|
-
__VINEXT_PAGES_LINK_PREFETCH_ROUTES__?: VinextPagesLinkPrefetchRoute[];
|
|
10
|
-
__VINEXT_CLIENT_REWRITES__?: {
|
|
11
|
-
afterFiles: NextRewrite[];
|
|
12
|
-
beforeFiles: NextRewrite[];
|
|
13
|
-
fallback: NextRewrite[];
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
4
|
/**
|
|
18
5
|
* Decide which router should own a soft-navigated URL. Returns:
|
|
19
6
|
* - "app" → the App Router runtime handles the navigation (RSC fetch).
|
|
@@ -28,4 +15,4 @@ declare global {
|
|
|
28
15
|
*/
|
|
29
16
|
declare function resolveHybridClientRouteOwner(href: string, basePath: string): HybridClientOwner | null;
|
|
30
17
|
//#endregion
|
|
31
|
-
export { HybridClientOwner, resolveHybridClientRouteOwner };
|
|
18
|
+
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 };
|
|
@@ -24,14 +24,18 @@
|
|
|
24
24
|
* directly by anyone, which keeps subsequent clones legal even after one
|
|
25
25
|
* caller has consumed its copy.
|
|
26
26
|
*
|
|
27
|
-
* - Each caller owns one waiter. Cancelling a waiter
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* - Each caller owns one waiter. Cancelling a waiter rejects only that caller;
|
|
28
|
+
* the shared request continues and self-evicts when it settles. This mirrors
|
|
29
|
+
* Next.js: a superseded data request may still reach the server, but its
|
|
30
|
+
* result is ignored by the cancelled navigation.
|
|
31
31
|
*
|
|
32
32
|
* - The map is module-scoped (one per realm). The Pages Router runs in the
|
|
33
33
|
* browser only, so a single `Map` is sufficient.
|
|
34
34
|
*/
|
|
35
|
+
declare function getPagesStaticDataCache(): Record<string, Promise<Response>>;
|
|
36
|
+
declare function fetchCachedPagesData(dataHref: string, init?: RequestInit): Promise<Response>;
|
|
37
|
+
declare function fetchStaticPagesData(dataHref: string, init?: RequestInit): Promise<Response>;
|
|
38
|
+
declare function evictPagesDataCache(dataHref: string): void;
|
|
35
39
|
/**
|
|
36
40
|
* Dedupe a `fetch()` against the `_next/data` endpoint. Multiple concurrent
|
|
37
41
|
* callers for the same resolved URL and deployment ID share one underlying
|
|
@@ -51,4 +55,4 @@ declare function dedupedPagesDataFetch(dataHref: string, init?: RequestInit): Pr
|
|
|
51
55
|
*/
|
|
52
56
|
declare function clearPagesDataInflight(): void;
|
|
53
57
|
//#endregion
|
|
54
|
-
export { clearPagesDataInflight, dedupedPagesDataFetch };
|
|
58
|
+
export { clearPagesDataInflight, dedupedPagesDataFetch, evictPagesDataCache, fetchCachedPagesData, fetchStaticPagesData, getPagesStaticDataCache };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../../utils/deployment-id.js";
|
|
1
|
+
import { getDeploymentId } from "../../utils/deployment-id.js";
|
|
2
2
|
//#region src/shims/internal/pages-data-fetch-dedup.ts
|
|
3
3
|
/**
|
|
4
4
|
* In-flight request dedup for the Pages Router `/_next/data/<id>/<page>.json`
|
|
@@ -25,16 +25,77 @@ import "../../utils/deployment-id.js";
|
|
|
25
25
|
* directly by anyone, which keeps subsequent clones legal even after one
|
|
26
26
|
* caller has consumed its copy.
|
|
27
27
|
*
|
|
28
|
-
* - Each caller owns one waiter. Cancelling a waiter
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
28
|
+
* - Each caller owns one waiter. Cancelling a waiter rejects only that caller;
|
|
29
|
+
* the shared request continues and self-evicts when it settles. This mirrors
|
|
30
|
+
* Next.js: a superseded data request may still reach the server, but its
|
|
31
|
+
* result is ignored by the cancelled navigation.
|
|
32
32
|
*
|
|
33
33
|
* - The map is module-scoped (one per realm). The Pages Router runs in the
|
|
34
34
|
* browser only, so a single `Map` is sufficient.
|
|
35
35
|
*/
|
|
36
36
|
/** Inflight fetch entries keyed by the resolved data request identity. */
|
|
37
37
|
const inflight = /* @__PURE__ */ new Map();
|
|
38
|
+
const staticDataCache = Object.create(null);
|
|
39
|
+
const staticDataSources = /* @__PURE__ */ new Map();
|
|
40
|
+
function getStaticDataKey(dataHref) {
|
|
41
|
+
if (typeof window === "undefined") return dataHref;
|
|
42
|
+
try {
|
|
43
|
+
return new URL(dataHref, window.location.href).href;
|
|
44
|
+
} catch {
|
|
45
|
+
return dataHref;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function cloneStaticResponse(cached, signal) {
|
|
49
|
+
if (signal?.aborted) return Promise.reject(new DOMException("Aborted", "AbortError"));
|
|
50
|
+
if (!signal) return cached.then((response) => response.clone());
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const abort = () => reject(new DOMException("Aborted", "AbortError"));
|
|
53
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
54
|
+
cached.then((response) => {
|
|
55
|
+
signal.removeEventListener("abort", abort);
|
|
56
|
+
resolve(response.clone());
|
|
57
|
+
}, (error) => {
|
|
58
|
+
signal.removeEventListener("abort", abort);
|
|
59
|
+
reject(error);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function getPagesStaticDataCache() {
|
|
64
|
+
return staticDataCache;
|
|
65
|
+
}
|
|
66
|
+
function fetchCachedPagesData(dataHref, init) {
|
|
67
|
+
const key = getStaticDataKey(dataHref);
|
|
68
|
+
let cached = staticDataSources.get(key);
|
|
69
|
+
if (cached === void 0) {
|
|
70
|
+
const { signal: _signal, ...sharedInit } = init ?? {};
|
|
71
|
+
cached = dedupedPagesDataFetch(dataHref, sharedInit).then((response) => {
|
|
72
|
+
const expectedDeploymentId = getDeploymentId() ?? null;
|
|
73
|
+
const responseDeploymentId = response.headers.get("x-nextjs-deployment-id");
|
|
74
|
+
if (!response.ok || response.headers.get("x-middleware-cache") === "no-cache" || responseDeploymentId !== null && responseDeploymentId !== expectedDeploymentId) {
|
|
75
|
+
delete staticDataCache[key];
|
|
76
|
+
staticDataSources.delete(key);
|
|
77
|
+
}
|
|
78
|
+
return response;
|
|
79
|
+
}).catch((error) => {
|
|
80
|
+
delete staticDataCache[key];
|
|
81
|
+
staticDataSources.delete(key);
|
|
82
|
+
throw error;
|
|
83
|
+
});
|
|
84
|
+
staticDataSources.set(key, cached);
|
|
85
|
+
const publicCached = cached.then((response) => response.clone());
|
|
86
|
+
publicCached.catch(() => {});
|
|
87
|
+
staticDataCache[key] = publicCached;
|
|
88
|
+
}
|
|
89
|
+
return cloneStaticResponse(cached, init?.signal ?? void 0);
|
|
90
|
+
}
|
|
91
|
+
function fetchStaticPagesData(dataHref, init) {
|
|
92
|
+
return fetchCachedPagesData(dataHref, init);
|
|
93
|
+
}
|
|
94
|
+
function evictPagesDataCache(dataHref) {
|
|
95
|
+
const key = getStaticDataKey(dataHref);
|
|
96
|
+
delete staticDataCache[key];
|
|
97
|
+
staticDataSources.delete(key);
|
|
98
|
+
}
|
|
38
99
|
function getInflightKey(dataHref, init) {
|
|
39
100
|
let resolvedHref = dataHref;
|
|
40
101
|
if (typeof window !== "undefined") try {
|
|
@@ -47,27 +108,23 @@ function cloneSharedResponse(key, entry, signal) {
|
|
|
47
108
|
entry.waiters += 1;
|
|
48
109
|
return new Promise((resolve, reject) => {
|
|
49
110
|
let released = false;
|
|
50
|
-
const release = (
|
|
111
|
+
const release = () => {
|
|
51
112
|
if (released) return;
|
|
52
113
|
released = true;
|
|
53
114
|
entry.waiters -= 1;
|
|
54
|
-
if (cancelled && entry.waiters === 0 && !entry.settled) {
|
|
55
|
-
if (inflight.get(key) === entry) inflight.delete(key);
|
|
56
|
-
entry.controller.abort();
|
|
57
|
-
}
|
|
58
115
|
};
|
|
59
116
|
const abort = () => {
|
|
60
|
-
release(
|
|
117
|
+
release();
|
|
61
118
|
reject(new DOMException("Aborted", "AbortError"));
|
|
62
119
|
};
|
|
63
120
|
signal?.addEventListener("abort", abort, { once: true });
|
|
64
121
|
entry.promise.then((response) => {
|
|
65
122
|
signal?.removeEventListener("abort", abort);
|
|
66
|
-
release(
|
|
123
|
+
release();
|
|
67
124
|
resolve(response.clone());
|
|
68
125
|
}, (error) => {
|
|
69
126
|
signal?.removeEventListener("abort", abort);
|
|
70
|
-
release(
|
|
127
|
+
release();
|
|
71
128
|
reject(error);
|
|
72
129
|
});
|
|
73
130
|
});
|
|
@@ -116,6 +173,8 @@ function dedupedPagesDataFetch(dataHref, init) {
|
|
|
116
173
|
function clearPagesDataInflight() {
|
|
117
174
|
for (const entry of inflight.values()) entry.controller.abort();
|
|
118
175
|
inflight.clear();
|
|
176
|
+
staticDataSources.clear();
|
|
177
|
+
for (const key of Object.keys(staticDataCache)) delete staticDataCache[key];
|
|
119
178
|
}
|
|
120
179
|
//#endregion
|
|
121
|
-
export { clearPagesDataInflight, dedupedPagesDataFetch };
|
|
180
|
+
export { clearPagesDataInflight, dedupedPagesDataFetch, evictPagesDataCache, fetchCachedPagesData, fetchStaticPagesData, getPagesStaticDataCache };
|
|
@@ -6,7 +6,9 @@ type PagesDataTarget = {
|
|
|
6
6
|
loader: () => Promise<{
|
|
7
7
|
default?: unknown;
|
|
8
8
|
[key: string]: unknown;
|
|
9
|
-
}>; /**
|
|
9
|
+
}>; /** Next.js data-fetch mode for this route. Plain pages are component-only. */
|
|
10
|
+
dataKind: "none" | "server" | "static"; /** Middleware-effect data URL to prefetch when the static matcher includes this route. */
|
|
11
|
+
middlewareDataHref?: string; /** Current buildId snapshot, used by the data URL and consistency checks. */
|
|
10
12
|
buildId: string; /** Locale-prefixed (server-routable) page path. */
|
|
11
13
|
pagePath: string; /** URL search string including the leading `?`. */
|
|
12
14
|
search: string;
|
|
@@ -18,6 +20,7 @@ type PagesDataTarget = {
|
|
|
18
20
|
*/
|
|
19
21
|
locale: string | undefined;
|
|
20
22
|
};
|
|
23
|
+
declare function getPagesMiddlewareDataHref(browserUrl: string, basePath: string): string | null;
|
|
21
24
|
/**
|
|
22
25
|
* Decide whether the JSON data-endpoint navigation path is usable for this
|
|
23
26
|
* browser URL. We require:
|
|
@@ -43,14 +46,12 @@ type PagesDataTarget = {
|
|
|
43
46
|
*/
|
|
44
47
|
declare function resolvePagesDataNavigationTarget(browserUrl: string, basePath: string): PagesDataTarget | null;
|
|
45
48
|
/**
|
|
46
|
-
*
|
|
47
|
-
* warm by the time the user clicks.
|
|
49
|
+
* Kick off the code-split loader and, for SSG pages, prefetch the data JSON so
|
|
50
|
+
* the chunk and payload are warm by the time the user clicks.
|
|
48
51
|
*
|
|
49
|
-
* Used by both `Router.prefetch()` and `<Link>` hover/viewport prefetch.
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* request is shared with a racing navigation; after it settles, the browser's
|
|
53
|
-
* normal HTTP cache remains responsible for reuse.
|
|
52
|
+
* Used by both `Router.prefetch()` and `<Link>` hover/viewport prefetch.
|
|
53
|
+
* Matches Next.js Pages Router prefetch: non-SSG routes only warm the page
|
|
54
|
+
* chunk, while `getStaticProps` routes also fetch `/_next/data`.
|
|
54
55
|
*
|
|
55
56
|
* loader's returned Promise is intentionally discarded — `import()` caches the
|
|
56
57
|
* result, so a subsequent navigation re-invocation hits the cache without
|
|
@@ -59,4 +60,4 @@ declare function resolvePagesDataNavigationTarget(browserUrl: string, basePath:
|
|
|
59
60
|
*/
|
|
60
61
|
declare function prefetchPagesData(target: PagesDataTarget): void;
|
|
61
62
|
//#endregion
|
|
62
|
-
export { PagesDataTarget, prefetchPagesData, resolvePagesDataNavigationTarget };
|
|
63
|
+
export { PagesDataTarget, getPagesMiddlewareDataHref, prefetchPagesData, resolvePagesDataNavigationTarget };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { stripBasePath } from "../../utils/base-path.js";
|
|
1
|
+
import { removeTrailingSlash, stripBasePath } from "../../utils/base-path.js";
|
|
2
|
+
import { isUnknownRecord } from "../../utils/record.js";
|
|
2
3
|
import { getLocalePathPrefix } from "../../utils/domain-locale.js";
|
|
3
4
|
import { buildPagesDataHref, matchPagesPattern } from "./pages-data-url.js";
|
|
4
5
|
import { NEXT_DEPLOYMENT_ID_HEADER, getDeploymentId } from "../../utils/deployment-id.js";
|
|
5
|
-
import {
|
|
6
|
+
import { fetchCachedPagesData, fetchStaticPagesData } from "./pages-data-fetch-dedup.js";
|
|
6
7
|
//#region src/shims/internal/pages-data-target.ts
|
|
7
8
|
/**
|
|
8
9
|
* Shared decision helper for the Pages Router `/_next/data/<id>/<page>.json`
|
|
@@ -13,6 +14,75 @@ import { dedupedPagesDataFetch } from "./pages-data-fetch-dedup.js";
|
|
|
13
14
|
* module init time — link.tsx and router.ts must remain free of circular
|
|
14
15
|
* imports and SSR-side router-init side effects.
|
|
15
16
|
*/
|
|
17
|
+
function hasVinextMiddleware(nextData) {
|
|
18
|
+
if (!isUnknownRecord(nextData)) return false;
|
|
19
|
+
const vinext = nextData.__vinext;
|
|
20
|
+
return isUnknownRecord(vinext) && vinext.hasMiddleware === true;
|
|
21
|
+
}
|
|
22
|
+
function isClientMiddlewareMatcherObject(value) {
|
|
23
|
+
if (!isUnknownRecord(value)) return false;
|
|
24
|
+
if (typeof value.source !== "string") return false;
|
|
25
|
+
if (value.locale !== void 0 && value.locale !== false) return false;
|
|
26
|
+
if (value.has !== void 0 && !Array.isArray(value.has)) return false;
|
|
27
|
+
if (value.missing !== void 0 && !Array.isArray(value.missing)) return false;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
function stripLocaleForMiddlewareMatcher(pathname) {
|
|
31
|
+
const locales = window.__VINEXT_LOCALES__;
|
|
32
|
+
if (!locales || locales.length === 0 || pathname === "/") return pathname;
|
|
33
|
+
const firstSegment = pathname.split("/")[1];
|
|
34
|
+
if (!firstSegment || !locales.includes(firstSegment)) return pathname;
|
|
35
|
+
return "/" + pathname.split("/").slice(2).join("/");
|
|
36
|
+
}
|
|
37
|
+
function clientMiddlewareSourceMatches(pathname, source) {
|
|
38
|
+
if (!/[\\():*+?]/.test(source)) return removeTrailingSlash(pathname) === removeTrailingSlash(source);
|
|
39
|
+
if (source.includes("(") || source.includes("\\")) return true;
|
|
40
|
+
const sourceParts = source.split("/").filter(Boolean);
|
|
41
|
+
const pathParts = pathname.split("/").filter(Boolean);
|
|
42
|
+
let pathIndex = 0;
|
|
43
|
+
for (const sourcePart of sourceParts) {
|
|
44
|
+
if (sourcePart.startsWith(":")) {
|
|
45
|
+
if (sourcePart.endsWith("*")) return true;
|
|
46
|
+
if (sourcePart.endsWith("+")) return pathIndex < pathParts.length;
|
|
47
|
+
if (pathIndex >= pathParts.length) return false;
|
|
48
|
+
pathIndex++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (pathParts[pathIndex] !== sourcePart) return false;
|
|
52
|
+
pathIndex++;
|
|
53
|
+
}
|
|
54
|
+
return pathIndex === pathParts.length;
|
|
55
|
+
}
|
|
56
|
+
function clientMiddlewareMatcherMatches(pathname, matcher) {
|
|
57
|
+
if (matcher === void 0) return true;
|
|
58
|
+
if (typeof matcher === "string") return clientMiddlewareSourceMatches(stripLocaleForMiddlewareMatcher(pathname), matcher);
|
|
59
|
+
if (!Array.isArray(matcher)) return true;
|
|
60
|
+
for (const item of matcher) {
|
|
61
|
+
if (typeof item === "string") {
|
|
62
|
+
if (clientMiddlewareSourceMatches(stripLocaleForMiddlewareMatcher(pathname), item)) return true;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (!isClientMiddlewareMatcherObject(item)) return true;
|
|
66
|
+
if (clientMiddlewareSourceMatches(item.locale === false ? pathname : stripLocaleForMiddlewareMatcher(pathname), item.source)) return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
function getPagesMiddlewareDataHref(browserUrl, basePath) {
|
|
71
|
+
const nextData = window.__NEXT_DATA__;
|
|
72
|
+
if (!nextData || !hasVinextMiddleware(nextData)) return null;
|
|
73
|
+
const buildId = nextData.buildId;
|
|
74
|
+
if (typeof buildId !== "string" || buildId.length === 0) return null;
|
|
75
|
+
let parsed;
|
|
76
|
+
try {
|
|
77
|
+
parsed = new URL(browserUrl, window.location.href);
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (parsed.origin !== window.location.origin) return null;
|
|
82
|
+
const pathname = stripBasePath(parsed.pathname, basePath);
|
|
83
|
+
if (!clientMiddlewareMatcherMatches(pathname, window.__VINEXT_MIDDLEWARE_MATCHER__)) return null;
|
|
84
|
+
return buildPagesDataHref(basePath, buildId, pathname, parsed.search);
|
|
85
|
+
}
|
|
16
86
|
/**
|
|
17
87
|
* Decide whether the JSON data-endpoint navigation path is usable for this
|
|
18
88
|
* browser URL. We require:
|
|
@@ -56,11 +126,16 @@ function resolvePagesDataNavigationTarget(browserUrl, basePath) {
|
|
|
56
126
|
if (!match) return null;
|
|
57
127
|
const loader = loaders[match.pattern];
|
|
58
128
|
if (!loader) return null;
|
|
129
|
+
const ssgPatterns = window.__VINEXT_PAGES_SSG_PATTERNS__;
|
|
130
|
+
const sspPatterns = window.__VINEXT_PAGES_SSP_PATTERNS__;
|
|
131
|
+
const dataKind = ssgPatterns?.includes(match.pattern) ? "static" : sspPatterns?.includes(match.pattern) ? "server" : ssgPatterns === void 0 || sspPatterns === void 0 ? "server" : "none";
|
|
59
132
|
return {
|
|
60
133
|
dataHref: buildPagesDataHref(basePath, buildId, pagePath, parsed.search),
|
|
61
134
|
pattern: match.pattern,
|
|
62
135
|
params: match.params,
|
|
63
136
|
loader,
|
|
137
|
+
dataKind,
|
|
138
|
+
middlewareDataHref: getPagesMiddlewareDataHref(browserUrl, basePath) ?? void 0,
|
|
64
139
|
buildId,
|
|
65
140
|
pagePath,
|
|
66
141
|
search: parsed.search,
|
|
@@ -68,14 +143,12 @@ function resolvePagesDataNavigationTarget(browserUrl, basePath) {
|
|
|
68
143
|
};
|
|
69
144
|
}
|
|
70
145
|
/**
|
|
71
|
-
*
|
|
72
|
-
* warm by the time the user clicks.
|
|
146
|
+
* Kick off the code-split loader and, for SSG pages, prefetch the data JSON so
|
|
147
|
+
* the chunk and payload are warm by the time the user clicks.
|
|
73
148
|
*
|
|
74
|
-
* Used by both `Router.prefetch()` and `<Link>` hover/viewport prefetch.
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* request is shared with a racing navigation; after it settles, the browser's
|
|
78
|
-
* normal HTTP cache remains responsible for reuse.
|
|
149
|
+
* Used by both `Router.prefetch()` and `<Link>` hover/viewport prefetch.
|
|
150
|
+
* Matches Next.js Pages Router prefetch: non-SSG routes only warm the page
|
|
151
|
+
* chunk, while `getStaticProps` routes also fetch `/_next/data`.
|
|
79
152
|
*
|
|
80
153
|
* loader's returned Promise is intentionally discarded — `import()` caches the
|
|
81
154
|
* result, so a subsequent navigation re-invocation hits the cache without
|
|
@@ -84,15 +157,21 @@ function resolvePagesDataNavigationTarget(browserUrl, basePath) {
|
|
|
84
157
|
*/
|
|
85
158
|
function prefetchPagesData(target) {
|
|
86
159
|
if (typeof document === "undefined") return;
|
|
160
|
+
target.loader().catch(() => {});
|
|
161
|
+
if (target.dataKind !== "static" && !target.middlewareDataHref) return;
|
|
87
162
|
const headers = {
|
|
88
163
|
Accept: "application/json",
|
|
89
164
|
purpose: "prefetch",
|
|
90
165
|
"x-nextjs-data": "1"
|
|
91
166
|
};
|
|
167
|
+
if (target.middlewareDataHref) headers["x-middleware-prefetch"] = "1";
|
|
92
168
|
const deploymentId = getDeploymentId();
|
|
93
169
|
if (deploymentId) headers[NEXT_DEPLOYMENT_ID_HEADER] = deploymentId;
|
|
94
|
-
|
|
95
|
-
|
|
170
|
+
if (target.dataKind === "static") {
|
|
171
|
+
fetchStaticPagesData(target.middlewareDataHref ?? target.dataHref, { headers }).catch(() => {});
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (target.middlewareDataHref) fetchCachedPagesData(target.middlewareDataHref, { headers }).catch(() => {});
|
|
96
175
|
}
|
|
97
176
|
//#endregion
|
|
98
|
-
export { prefetchPagesData, resolvePagesDataNavigationTarget };
|
|
177
|
+
export { getPagesMiddlewareDataHref, prefetchPagesData, resolvePagesDataNavigationTarget };
|
|
@@ -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 };
|
|
@@ -2,6 +2,7 @@ import { SegmentMap } from "./navigation-context-state.js";
|
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/shims/layout-segment-context.d.ts
|
|
5
|
+
declare function mergeLayoutSegmentMap(previous: SegmentMap | null, next: SegmentMap): SegmentMap;
|
|
5
6
|
/**
|
|
6
7
|
* Wraps children with the layout segment context.
|
|
7
8
|
*
|
|
@@ -14,11 +15,13 @@ import { ReactNode } from "react";
|
|
|
14
15
|
* to read the segments for a specific parallel route.
|
|
15
16
|
*/
|
|
16
17
|
declare function LayoutSegmentProvider({
|
|
18
|
+
providerId,
|
|
17
19
|
segmentMap,
|
|
18
20
|
children
|
|
19
21
|
}: {
|
|
22
|
+
providerId?: string;
|
|
20
23
|
segmentMap: SegmentMap;
|
|
21
24
|
children: ReactNode;
|
|
22
25
|
}): string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").FunctionComponentElement<import("react").ProviderProps<SegmentMap>> | null | undefined;
|
|
23
26
|
//#endregion
|
|
24
|
-
export { LayoutSegmentProvider };
|
|
27
|
+
export { LayoutSegmentProvider, mergeLayoutSegmentMap };
|