vinext 0.1.8 → 0.2.1
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/css-url-assets.d.ts +3 -1
- package/dist/build/css-url-assets.js +18 -1
- package/dist/build/inject-pregenerated-paths.d.ts +7 -0
- package/dist/build/inject-pregenerated-paths.js +21 -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-server-entry.d.ts +1 -0
- package/dist/build/prerender-server-entry.js +49 -0
- package/dist/build/prerender-server-pool.d.ts +44 -0
- package/dist/build/prerender-server-pool.js +194 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +98 -27
- 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 +12 -2
- package/dist/build/standalone.js +2 -0
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.d.ts +4 -6
- package/dist/check.js +48 -11
- 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 +112 -96
- 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/vinext-next-data.d.ts +4 -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 +45 -19
- package/dist/config/next-config.d.ts +41 -9
- package/dist/config/next-config.js +60 -3
- package/dist/config/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/entries/app-browser-entry.js +5 -1
- package/dist/entries/app-rsc-entry.d.ts +5 -3
- package/dist/entries/app-rsc-entry.js +44 -10
- package/dist/entries/app-rsc-manifest.js +2 -0
- package/dist/entries/pages-client-entry.d.ts +3 -0
- package/dist/entries/pages-client-entry.js +28 -3
- package/dist/entries/pages-server-entry.js +23 -6
- 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 +482 -120
- 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 +209 -99
- 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 +9 -2
- 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 +272 -0
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +44 -20
- 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/fonts.js +1 -1
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/og-assets.js +2 -1
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/rsc-reference-validation-normalizer.d.ts +12 -0
- package/dist/plugins/rsc-reference-validation-normalizer.js +48 -0
- package/dist/plugins/sass.d.ts +17 -1
- package/dist/plugins/sass.js +74 -1
- package/dist/plugins/styled-jsx.d.ts +16 -0
- package/dist/plugins/styled-jsx.js +149 -0
- 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 +23 -2
- package/dist/routing/app-route-graph.js +138 -38
- package/dist/routing/file-matcher.d.ts +11 -1
- package/dist/routing/file-matcher.js +18 -3
- 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 +198 -57
- 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 +1 -1
- package/dist/server/app-browser-server-action-client.js +8 -7
- package/dist/server/app-browser-state.d.ts +12 -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 +42 -24
- 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 +2 -1
- package/dist/server/app-fallback-renderer.js +10 -6
- 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.js +2 -1
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +5 -4
- 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 +27 -7
- package/dist/server/app-page-dispatch.d.ts +1 -0
- package/dist/server/app-page-dispatch.js +26 -8
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +59 -4
- package/dist/server/app-page-execution.js +2 -1
- package/dist/server/app-page-probe.js +5 -0
- package/dist/server/app-page-render-identity.d.ts +2 -0
- package/dist/server/app-page-render-identity.js +3 -2
- package/dist/server/app-page-render.d.ts +2 -0
- package/dist/server/app-page-render.js +85 -16
- package/dist/server/app-page-request.d.ts +14 -0
- package/dist/server/app-page-request.js +69 -4
- package/dist/server/app-page-response.d.ts +7 -0
- package/dist/server/app-page-response.js +16 -4
- package/dist/server/app-page-route-wiring.d.ts +8 -1
- package/dist/server/app-page-route-wiring.js +32 -18
- 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 +7 -1
- package/dist/server/app-page-stream.js +3 -1
- package/dist/server/app-route-handler-execution.js +5 -1
- 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-tree-prefetch.d.ts +43 -0
- package/dist/server/app-route-tree-prefetch.js +187 -0
- package/dist/server/app-router-entry.js +9 -2
- package/dist/server/app-rsc-cache-busting.d.ts +2 -1
- package/dist/server/app-rsc-cache-busting.js +9 -4
- package/dist/server/app-rsc-handler.d.ts +7 -0
- package/dist/server/app-rsc-handler.js +148 -39
- package/dist/server/app-rsc-render-mode.d.ts +3 -2
- package/dist/server/app-rsc-render-mode.js +4 -1
- package/dist/server/app-rsc-request-normalization.d.ts +6 -6
- package/dist/server/app-rsc-request-normalization.js +10 -8
- package/dist/server/app-segment-config.d.ts +11 -0
- package/dist/server/app-segment-config.js +62 -6
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +61 -30
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +13 -5
- package/dist/server/app-ssr-stream.d.ts +7 -3
- package/dist/server/app-ssr-stream.js +10 -6
- package/dist/server/app-visited-response-cache.d.ts +6 -0
- package/dist/server/app-visited-response-cache.js +3 -1
- package/dist/server/cache-control.d.ts +3 -1
- package/dist/server/cache-control.js +13 -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.d.ts +11 -1
- package/dist/server/dev-server.js +94 -35
- 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 +7 -15
- package/dist/server/headers.js +11 -18
- 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 +3 -2
- package/dist/server/isr-cache.js +9 -5
- 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-data-route.d.ts +4 -2
- package/dist/server/pages-data-route.js +18 -4
- package/dist/server/pages-dev-module-url.d.ts +2 -1
- package/dist/server/pages-dev-module-url.js +6 -3
- package/dist/server/pages-node-compat.d.ts +19 -1
- package/dist/server/pages-node-compat.js +81 -4
- package/dist/server/pages-page-data.d.ts +33 -1
- package/dist/server/pages-page-data.js +62 -33
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +38 -19
- package/dist/server/pages-page-response.d.ts +8 -0
- package/dist/server/pages-page-response.js +7 -3
- package/dist/server/pages-request-pipeline.d.ts +9 -5
- package/dist/server/pages-request-pipeline.js +55 -7
- 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 +5 -3
- package/dist/server/prod-server.js +68 -39
- package/dist/server/request-pipeline.js +2 -1
- package/dist/server/seed-cache.js +4 -4
- 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-handler.js +8 -1
- package/dist/shims/cache.js +22 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/fetch-cache.d.ts +3 -1
- package/dist/shims/fetch-cache.js +77 -52
- package/dist/shims/form.d.ts +4 -2
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +7 -1
- package/dist/shims/headers.js +17 -3
- package/dist/shims/image.js +75 -14
- package/dist/shims/internal/app-prefetch-fetch-queue.d.ts +10 -0
- package/dist/shims/internal/app-prefetch-fetch-queue.js +61 -0
- 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 +3 -15
- package/dist/shims/internal/hybrid-client-route-owner.js +40 -58
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +10 -5
- package/dist/shims/internal/pages-data-fetch-dedup.js +84 -14
- package/dist/shims/internal/pages-data-target.d.ts +18 -12
- package/dist/shims/internal/pages-data-target.js +97 -13
- 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.d.ts +1 -1
- package/dist/shims/link.js +224 -58
- package/dist/shims/navigation.d.ts +19 -3
- package/dist/shims/navigation.js +245 -47
- package/dist/shims/request-context.js +18 -0
- 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 +387 -102
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/typegen.js +1 -1
- 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 +3 -3
- package/dist/utils/project.d.ts +48 -2
- package/dist/utils/project.js +225 -4
- package/dist/utils/protocol-headers.d.ts +23 -0
- package/dist/utils/protocol-headers.js +23 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/dist/utils/vite-version.d.ts +2 -0
- package/dist/utils/vite-version.js +11 -1
- package/package.json +47 -2
- package/dist/deploy.d.ts +0 -197
- package/dist/deploy.js +0 -1040
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
package/dist/shims/link.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
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
|
-
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";
|
|
6
|
+
import { getPagesMiddlewareDataHref, prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.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 {
|
|
16
|
+
import { scheduleAppPrefetchFetch } from "./internal/app-prefetch-fetch-queue.js";
|
|
22
17
|
import { getI18nContext } from "./i18n-context.js";
|
|
23
18
|
import { canLinkIntentPrefetch, canLinkPrefetch, getLinkPrefetchHref } from "./link-prefetch.js";
|
|
24
19
|
import { clearLinkForCurrentNavigation, notifyLinkNavigationStart, setLinkForCurrentNavigation } from "./internal/link-status-registry.js";
|
|
@@ -144,7 +139,7 @@ function getLinkPrefetchRouterMode() {
|
|
|
144
139
|
}
|
|
145
140
|
function resolveMatchedAutoAppRoutePrefetch(route) {
|
|
146
141
|
return {
|
|
147
|
-
cacheForNavigation: !route.canPrefetchLoadingShell,
|
|
142
|
+
cacheForNavigation: !route.canPrefetchLoadingShell && route.requiresDynamicNavigationRequest !== true,
|
|
148
143
|
prefetchShellFirst: !route.isDynamic,
|
|
149
144
|
shouldPrefetch: true
|
|
150
145
|
};
|
|
@@ -155,9 +150,8 @@ function canAutoPrefetchFullAppRoute(href) {
|
|
|
155
150
|
if (!routes) return false;
|
|
156
151
|
const routeHref = toSameOriginRouteHref(href);
|
|
157
152
|
if (routeHref === null) return false;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return resolveMatchedAutoAppRoutePrefetch(match.route).cacheForNavigation;
|
|
153
|
+
if (!matchRouteWithTrie(routeHref, routes, linkPrefetchRouteTrieCache)) return false;
|
|
154
|
+
return resolveAutoAppRoutePrefetch(href).cacheForNavigation;
|
|
161
155
|
}
|
|
162
156
|
function resolveAutoAppRoutePrefetch(href) {
|
|
163
157
|
if (typeof window === "undefined") return {
|
|
@@ -183,19 +177,34 @@ function resolveAutoAppRoutePrefetch(href) {
|
|
|
183
177
|
prefetchShellFirst: false,
|
|
184
178
|
shouldPrefetch: false
|
|
185
179
|
};
|
|
186
|
-
|
|
180
|
+
const prefetch = resolveMatchedAutoAppRoutePrefetch(match.route);
|
|
181
|
+
if (new URL(routeHref, "http://vinext.local").search !== "") return {
|
|
182
|
+
...prefetch,
|
|
183
|
+
cacheForNavigation: false,
|
|
184
|
+
prefetchShellFirst: true
|
|
185
|
+
};
|
|
186
|
+
return prefetch;
|
|
187
|
+
}
|
|
188
|
+
function resolveFullAppRoutePrefetch() {
|
|
189
|
+
return {
|
|
190
|
+
cacheForNavigation: true,
|
|
191
|
+
prefetchShellFirst: true,
|
|
192
|
+
shouldPrefetch: true
|
|
193
|
+
};
|
|
187
194
|
}
|
|
188
195
|
/**
|
|
189
196
|
* Prefetch a URL for faster navigation.
|
|
190
197
|
*
|
|
191
198
|
* For App Router (RSC): fetches the .rsc payload in the background and
|
|
192
199
|
* stores it in an in-memory cache for instant use during navigation.
|
|
193
|
-
* For Pages Router:
|
|
200
|
+
* For Pages Router: warms the page chunk, prefetches data only for SSG pages,
|
|
201
|
+
* and falls back to a document prefetch hint when no page loader matches.
|
|
194
202
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
203
|
+
* App Router and high-priority prefetches start immediately. Low-priority
|
|
204
|
+
* Pages Router fallback prefetches use `requestIdleCallback` (or `setTimeout`
|
|
205
|
+
* fallback) to avoid blocking the main thread during initial page load.
|
|
197
206
|
*/
|
|
198
|
-
function prefetchUrl(href, mode, priority = "low") {
|
|
207
|
+
function prefetchUrl(href, mode, priority = "low", pagesRouteHref, locale) {
|
|
199
208
|
if (typeof window === "undefined") return;
|
|
200
209
|
const prefetchHref = getLinkPrefetchHref({
|
|
201
210
|
href,
|
|
@@ -204,31 +213,59 @@ function prefetchUrl(href, mode, priority = "low") {
|
|
|
204
213
|
});
|
|
205
214
|
if (prefetchHref == null) return;
|
|
206
215
|
const fullHref = toBrowserNavigationHref(prefetchHref, window.location.href, __basePath);
|
|
216
|
+
const fullRouteHref = toBrowserNavigationHref(pagesRouteHref === void 0 ? prefetchHref : getLinkPrefetchHref({
|
|
217
|
+
href: pagesRouteHref,
|
|
218
|
+
basePath: __basePath,
|
|
219
|
+
currentOrigin: window.location.origin
|
|
220
|
+
}) ?? prefetchHref, window.location.href, __basePath);
|
|
207
221
|
const target = new URL(fullHref, window.location.href);
|
|
208
222
|
if (target.origin === window.location.origin && target.pathname === window.location.pathname && target.search === window.location.search) return;
|
|
209
|
-
|
|
210
|
-
fn();
|
|
211
|
-
} : window.requestIdleCallback ?? ((fn) => setTimeout(fn, 100)))(() => {
|
|
223
|
+
const runPrefetch = () => {
|
|
212
224
|
(async () => {
|
|
213
225
|
if (hasAppNavigationRuntime()) {
|
|
226
|
+
if (isBotUserAgent(window.navigator?.userAgent ?? "")) return;
|
|
227
|
+
const [navigation, { AppElementsWire }, rscCacheBusting, { APP_RSC_RENDER_MODE_PREFETCH_DYNAMIC_SHELL, APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL }, headersModule, { resolveHybridClientRewriteHref, resolveHybridClientRouteOwner }] = await Promise.all([
|
|
228
|
+
import("./navigation.js"),
|
|
229
|
+
import("../server/app-elements.js"),
|
|
230
|
+
import("../server/app-rsc-cache-busting.js"),
|
|
231
|
+
import("../server/app-rsc-render-mode.js"),
|
|
232
|
+
import("../server/headers.js"),
|
|
233
|
+
import("./internal/hybrid-client-route-owner.js")
|
|
234
|
+
]);
|
|
235
|
+
const { getPrefetchInterceptionContext, getPrefetchCache, getPrefetchedUrls, getMountedSlotsHeader, hasSearchAgnosticPrefetchShellForRoute, hasPrefetchCacheEntryForNavigation, peekPrefetchResponseForNavigation, prefetchRscResponse, restoreRscResponse, PREFETCH_CACHE_TTL } = navigation;
|
|
236
|
+
const { createRscRequestHeaders, createRscRequestUrl } = rscCacheBusting;
|
|
237
|
+
const { NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, VINEXT_MOUNTED_SLOTS_HEADER } = headersModule;
|
|
214
238
|
const hybridOwner = resolveHybridClientRouteOwner(prefetchHref, __basePath);
|
|
215
239
|
if (hybridOwner === "pages" || hybridOwner === "document") return;
|
|
216
|
-
const
|
|
240
|
+
const rewrittenPrefetchHref = resolveHybridClientRewriteHref(fullHref, __basePath);
|
|
241
|
+
const autoPrefetch = mode === "auto" ? resolveAutoAppRoutePrefetch(rewrittenPrefetchHref ?? prefetchHref) : mode === "full-after-shell" ? {
|
|
217
242
|
cacheForNavigation: true,
|
|
218
243
|
prefetchShellFirst: true,
|
|
219
244
|
shouldPrefetch: true
|
|
220
|
-
};
|
|
245
|
+
} : resolveFullAppRoutePrefetch();
|
|
221
246
|
if (!autoPrefetch.shouldPrefetch) return;
|
|
222
247
|
const interceptionContext = getPrefetchInterceptionContext(fullHref);
|
|
223
248
|
const mountedSlotsHeader = getMountedSlotsHeader();
|
|
224
249
|
const isOptimisticRouteShellPrefetch = !autoPrefetch.cacheForNavigation;
|
|
250
|
+
const hasSearchParams = new URL(fullHref, window.location.href).search !== "";
|
|
251
|
+
const isAutomaticSearchParamShell = mode === "auto" && isOptimisticRouteShellPrefetch && hasSearchParams;
|
|
225
252
|
if (isOptimisticRouteShellPrefetch && interceptionContext !== null) return;
|
|
253
|
+
const hasSearchAgnosticShell = isAutomaticSearchParamShell && hasSearchAgnosticPrefetchShellForRoute(await createRscRequestUrl(fullHref, new Headers()), interceptionContext, mountedSlotsHeader);
|
|
226
254
|
const headers = createRscRequestHeaders({
|
|
227
255
|
interceptionContext,
|
|
228
|
-
renderMode: isOptimisticRouteShellPrefetch ? APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL : void 0
|
|
256
|
+
renderMode: isOptimisticRouteShellPrefetch ? hasSearchAgnosticShell ? APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL : isAutomaticSearchParamShell ? APP_RSC_RENDER_MODE_PREFETCH_DYNAMIC_SHELL : APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL : void 0
|
|
229
257
|
});
|
|
230
258
|
if (mountedSlotsHeader) headers.set(VINEXT_MOUNTED_SLOTS_HEADER, mountedSlotsHeader);
|
|
259
|
+
const shouldSendSegmentPrefetchHeaders = isOptimisticRouteShellPrefetch || mode === "auto";
|
|
260
|
+
if (__prefetchInlining && autoPrefetch.cacheForNavigation) {
|
|
261
|
+
headers.set(NEXT_ROUTER_PREFETCH_HEADER, "1");
|
|
262
|
+
headers.set(NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, "/__PAGE__");
|
|
263
|
+
} else if (shouldSendSegmentPrefetchHeaders) {
|
|
264
|
+
headers.set(NEXT_ROUTER_PREFETCH_HEADER, "1");
|
|
265
|
+
headers.set(NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, "1");
|
|
266
|
+
}
|
|
231
267
|
const rscUrl = await createRscRequestUrl(fullHref, headers);
|
|
268
|
+
const additionalRscUrls = rewrittenPrefetchHref && rewrittenPrefetchHref !== fullHref ? [await createRscRequestUrl(rewrittenPrefetchHref, headers)] : [];
|
|
232
269
|
const cacheKey = AppElementsWire.encodeCacheKey(rscUrl, interceptionContext);
|
|
233
270
|
const prefetched = getPrefetchedUrls();
|
|
234
271
|
if (prefetched.has(cacheKey)) {
|
|
@@ -236,43 +273,130 @@ function prefetchUrl(href, mode, priority = "low") {
|
|
|
236
273
|
const existing = getPrefetchCache().get(cacheKey);
|
|
237
274
|
if (existing?.cacheForNavigation === false) existing.cacheForNavigation = true;
|
|
238
275
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
276
|
+
const fetchFullRscPayload = () => scheduleAppPrefetchFetch(() => fetch(rscUrl, {
|
|
277
|
+
headers,
|
|
278
|
+
credentials: "include",
|
|
279
|
+
priority,
|
|
280
|
+
purpose: "prefetch"
|
|
281
|
+
}), priority);
|
|
282
|
+
const fetchLoadingShellForReuse = async () => {
|
|
242
283
|
const shellHeaders = createRscRequestHeaders({
|
|
243
284
|
interceptionContext,
|
|
244
285
|
renderMode: APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL
|
|
245
286
|
});
|
|
287
|
+
shellHeaders.set(NEXT_ROUTER_PREFETCH_HEADER, "1");
|
|
288
|
+
shellHeaders.set(NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, "1");
|
|
246
289
|
if (mountedSlotsHeader) shellHeaders.set(VINEXT_MOUNTED_SLOTS_HEADER, mountedSlotsHeader);
|
|
247
290
|
const shellRscUrl = await createRscRequestUrl(fullHref, shellHeaders);
|
|
248
|
-
const
|
|
249
|
-
|
|
291
|
+
const shellCacheKey = AppElementsWire.encodeCacheKey(shellRscUrl, interceptionContext);
|
|
292
|
+
const shellCache = getPrefetchCache();
|
|
293
|
+
let shellEntry = shellCache.get(shellCacheKey);
|
|
294
|
+
if (shellEntry === void 0) {
|
|
295
|
+
getPrefetchedUrls().add(shellCacheKey);
|
|
296
|
+
prefetchRscResponse(shellRscUrl, scheduleAppPrefetchFetch(() => fetch(shellRscUrl, {
|
|
297
|
+
headers: shellHeaders,
|
|
298
|
+
credentials: "include",
|
|
299
|
+
priority,
|
|
300
|
+
purpose: "prefetch"
|
|
301
|
+
}), priority), interceptionContext, mountedSlotsHeader, void 0, {
|
|
302
|
+
cacheForNavigation: false,
|
|
303
|
+
optimisticRouteShell: true,
|
|
304
|
+
prefetchKind: "loading-shell"
|
|
305
|
+
});
|
|
306
|
+
shellEntry = shellCache.get(shellCacheKey);
|
|
307
|
+
}
|
|
308
|
+
await shellEntry?.pending?.catch(() => {});
|
|
309
|
+
};
|
|
310
|
+
const fetchAliasCacheHitProbe = async () => {
|
|
311
|
+
const probeHeaders = createRscRequestHeaders({
|
|
312
|
+
interceptionContext,
|
|
313
|
+
renderMode: APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL
|
|
314
|
+
});
|
|
315
|
+
probeHeaders.set(NEXT_ROUTER_PREFETCH_HEADER, "1");
|
|
316
|
+
probeHeaders.set(NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, "1");
|
|
317
|
+
if (mountedSlotsHeader) probeHeaders.set(VINEXT_MOUNTED_SLOTS_HEADER, mountedSlotsHeader);
|
|
318
|
+
const probeRscUrl = await createRscRequestUrl(fullHref, probeHeaders);
|
|
319
|
+
return fetch(probeRscUrl, {
|
|
320
|
+
method: "HEAD",
|
|
321
|
+
headers: probeHeaders,
|
|
250
322
|
credentials: "include",
|
|
251
323
|
priority,
|
|
252
324
|
purpose: "prefetch"
|
|
253
325
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
326
|
+
};
|
|
327
|
+
const hasExactNavigationCacheEntry = autoPrefetch.cacheForNavigation && hasPrefetchCacheEntryForNavigation(rscUrl, interceptionContext, mountedSlotsHeader);
|
|
328
|
+
if (hasExactNavigationCacheEntry || autoPrefetch.cacheForNavigation && hasPrefetchCacheEntryForNavigation(rscUrl, interceptionContext, mountedSlotsHeader, { additionalRscUrls })) {
|
|
329
|
+
if (!hasExactNavigationCacheEntry && !prefetched.has(cacheKey) && additionalRscUrls.length > 0 && autoPrefetch.prefetchShellFirst && mountedSlotsHeader === null) {
|
|
330
|
+
prefetched.add(cacheKey);
|
|
331
|
+
fetchAliasCacheHitProbe().then((response) => response.arrayBuffer()).catch(() => {});
|
|
332
|
+
}
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
prefetched.add(cacheKey);
|
|
336
|
+
const gateViaRouteTree = __prefetchInlining && mode === "auto" && autoPrefetch.prefetchShellFirst;
|
|
337
|
+
const gateViaExplicitSearchShell = mode === "full" && hasSearchParams && autoPrefetch.prefetchShellFirst && mountedSlotsHeader === null;
|
|
338
|
+
const gateViaLoadingShell = (mode === "full-after-shell" || gateViaExplicitSearchShell) && autoPrefetch.prefetchShellFirst;
|
|
339
|
+
const fetchPromise = autoPrefetch.cacheForNavigation && (gateViaRouteTree || gateViaLoadingShell) ? (async () => {
|
|
340
|
+
if (gateViaLoadingShell) {
|
|
341
|
+
await fetchLoadingShellForReuse();
|
|
342
|
+
return fetchFullRscPayload();
|
|
343
|
+
}
|
|
344
|
+
const shellHeaders = createRscRequestHeaders({
|
|
345
|
+
interceptionContext,
|
|
346
|
+
renderMode: void 0
|
|
347
|
+
});
|
|
348
|
+
shellHeaders.set(NEXT_ROUTER_PREFETCH_HEADER, "1");
|
|
349
|
+
shellHeaders.set(NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, "/_tree");
|
|
350
|
+
if (mountedSlotsHeader) shellHeaders.set(VINEXT_MOUNTED_SLOTS_HEADER, mountedSlotsHeader);
|
|
351
|
+
const shellRscUrl = await createRscRequestUrl(fullHref, shellHeaders);
|
|
352
|
+
const shellCacheKey = AppElementsWire.encodeCacheKey(shellRscUrl, interceptionContext);
|
|
353
|
+
const shellCache = getPrefetchCache();
|
|
354
|
+
let shellEntry = shellCache.get(shellCacheKey);
|
|
355
|
+
if (shellEntry === void 0) {
|
|
356
|
+
getPrefetchedUrls().add(shellCacheKey);
|
|
357
|
+
prefetchRscResponse(shellRscUrl, scheduleAppPrefetchFetch(() => fetch(shellRscUrl, {
|
|
358
|
+
headers: shellHeaders,
|
|
359
|
+
credentials: "include",
|
|
360
|
+
priority,
|
|
361
|
+
purpose: "prefetch"
|
|
362
|
+
}), priority), interceptionContext, mountedSlotsHeader, void 0, {
|
|
363
|
+
cacheForNavigation: false,
|
|
364
|
+
optimisticRouteShell: false,
|
|
365
|
+
prefetchKind: "route-tree"
|
|
366
|
+
});
|
|
367
|
+
shellEntry = shellCache.get(shellCacheKey);
|
|
368
|
+
}
|
|
369
|
+
await shellEntry?.pending?.catch(() => {});
|
|
370
|
+
const renderedPathAndSearch = shellEntry?.snapshot?.renderedPathAndSearch;
|
|
371
|
+
if (renderedPathAndSearch) {
|
|
372
|
+
const cachedRenderedResponse = peekPrefetchResponseForNavigation(await createRscRequestUrl(renderedPathAndSearch, headers), interceptionContext, mountedSlotsHeader);
|
|
373
|
+
if (cachedRenderedResponse) return restoreRscResponse(cachedRenderedResponse);
|
|
374
|
+
}
|
|
375
|
+
return scheduleAppPrefetchFetch(() => fetch(rscUrl, {
|
|
257
376
|
headers,
|
|
258
377
|
credentials: "include",
|
|
259
378
|
priority,
|
|
260
379
|
purpose: "prefetch"
|
|
261
|
-
});
|
|
262
|
-
})() :
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
priority,
|
|
266
|
-
purpose: "prefetch"
|
|
267
|
-
}), interceptionContext, mountedSlotsHeader, void 0, {
|
|
380
|
+
}), priority);
|
|
381
|
+
})() : fetchFullRscPayload();
|
|
382
|
+
if (mode === "full" && autoPrefetch.cacheForNavigation && autoPrefetch.prefetchShellFirst && mountedSlotsHeader === null && !gateViaExplicitSearchShell) fetchLoadingShellForReuse();
|
|
383
|
+
prefetchRscResponse(rscUrl, fetchPromise, interceptionContext, mountedSlotsHeader, void 0, {
|
|
268
384
|
cacheForNavigation: autoPrefetch.cacheForNavigation,
|
|
269
|
-
|
|
385
|
+
fallbackTtlMs: PREFETCH_CACHE_TTL,
|
|
386
|
+
optimisticRouteShell: isOptimisticRouteShellPrefetch,
|
|
387
|
+
prefetchKind: isOptimisticRouteShellPrefetch ? "loading-shell" : "navigation",
|
|
388
|
+
searchAgnosticShell: isAutomaticSearchParamShell && !hasSearchAgnosticShell
|
|
270
389
|
});
|
|
271
390
|
} else if (HAS_PAGES_ROUTER && window.__NEXT_DATA__) {
|
|
272
|
-
const dataTarget = resolvePagesDataNavigationTarget(
|
|
273
|
-
if (dataTarget)
|
|
274
|
-
|
|
275
|
-
|
|
391
|
+
const dataTarget = resolvePagesDataNavigationTarget(fullRouteHref, __basePath, { locale });
|
|
392
|
+
if (dataTarget) {
|
|
393
|
+
const middlewareDataHref = fullRouteHref === fullHref ? dataTarget.middlewareDataHref : getPagesMiddlewareDataHref(fullHref, __basePath) ?? void 0;
|
|
394
|
+
prefetchPagesData({
|
|
395
|
+
...dataTarget,
|
|
396
|
+
middlewareDataHref
|
|
397
|
+
});
|
|
398
|
+
} else {
|
|
399
|
+
await markAppRouteDetectedOnPrefetch(fullHref, __basePath);
|
|
276
400
|
const link = document.createElement("link");
|
|
277
401
|
link.rel = "prefetch";
|
|
278
402
|
link.href = fullHref;
|
|
@@ -283,10 +407,17 @@ function prefetchUrl(href, mode, priority = "low") {
|
|
|
283
407
|
})().catch((error) => {
|
|
284
408
|
console.error("[vinext] RSC prefetch setup error:", error);
|
|
285
409
|
});
|
|
286
|
-
}
|
|
410
|
+
};
|
|
411
|
+
if (priority === "high" || hasAppNavigationRuntime()) {
|
|
412
|
+
runPrefetch();
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
(window.requestIdleCallback ?? ((fn) => setTimeout(fn, 100)))(runPrefetch);
|
|
287
416
|
}
|
|
288
|
-
function promotePrefetchEntriesForNavigation(href) {
|
|
417
|
+
async function promotePrefetchEntriesForNavigation(href) {
|
|
289
418
|
if (typeof window === "undefined") return;
|
|
419
|
+
if (!hasAppNavigationRuntime()) return;
|
|
420
|
+
const [{ getPrefetchCache }, { stripRscCacheBustingSearchParam, stripRscSuffix }] = await Promise.all([import("./navigation.js"), import("../server/app-rsc-cache-busting.js")]);
|
|
290
421
|
let target;
|
|
291
422
|
try {
|
|
292
423
|
target = new URL(toBrowserNavigationHref(href, window.location.href, __basePath), window.location.href);
|
|
@@ -295,6 +426,7 @@ function promotePrefetchEntriesForNavigation(href) {
|
|
|
295
426
|
}
|
|
296
427
|
for (const [cacheKey, entry] of getPrefetchCache()) {
|
|
297
428
|
if (entry.optimisticRouteShell === true) continue;
|
|
429
|
+
if (entry.prefetchKind === "route-tree") continue;
|
|
298
430
|
const [rscUrl] = cacheKey.split("\0", 1);
|
|
299
431
|
let cached;
|
|
300
432
|
try {
|
|
@@ -313,12 +445,33 @@ function promotePrefetchEntriesForNavigation(href) {
|
|
|
313
445
|
let sharedObserver = null;
|
|
314
446
|
const observedLinkPrefetches = /* @__PURE__ */ new WeakMap();
|
|
315
447
|
const visibleLinkPrefetches = /* @__PURE__ */ new Set();
|
|
448
|
+
const visibleAppPrefetchQueue = [];
|
|
449
|
+
let visibleAppPrefetchDrainScheduled = false;
|
|
450
|
+
function drainVisibleAppPrefetchQueue() {
|
|
451
|
+
visibleAppPrefetchDrainScheduled = false;
|
|
452
|
+
while (true) {
|
|
453
|
+
const instance = visibleAppPrefetchQueue.pop();
|
|
454
|
+
if (!instance) return;
|
|
455
|
+
instance.queuedViewportPrefetch = false;
|
|
456
|
+
if (!instance.isVisible || instance.routerMode !== "app") continue;
|
|
457
|
+
prefetchUrl(instance.href, instance.mode, "low", instance.pagesRouteHref);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
function scheduleVisibleAppPrefetch(instance) {
|
|
461
|
+
if (instance.queuedViewportPrefetch) return;
|
|
462
|
+
instance.queuedViewportPrefetch = true;
|
|
463
|
+
visibleAppPrefetchQueue.push(instance);
|
|
464
|
+
if (visibleAppPrefetchDrainScheduled) return;
|
|
465
|
+
visibleAppPrefetchDrainScheduled = true;
|
|
466
|
+
queueMicrotask(drainVisibleAppPrefetchQueue);
|
|
467
|
+
}
|
|
316
468
|
function setVisibleLinkPrefetch(instance, isVisible) {
|
|
317
469
|
instance.isVisible = isVisible;
|
|
318
470
|
if (isVisible) {
|
|
319
471
|
visibleLinkPrefetches.add(instance);
|
|
320
472
|
if (instance.routerMode === "pages" && instance.viewportPrefetched) return;
|
|
321
|
-
|
|
473
|
+
if (instance.routerMode === "app") scheduleVisibleAppPrefetch(instance);
|
|
474
|
+
else prefetchUrl(instance.href, instance.mode, "low", instance.pagesRouteHref, instance.locale);
|
|
322
475
|
instance.viewportPrefetched = true;
|
|
323
476
|
} else visibleLinkPrefetches.delete(instance);
|
|
324
477
|
}
|
|
@@ -327,7 +480,7 @@ function registerVisibleLinkPing() {
|
|
|
327
480
|
registerNavigationRuntimeFunctions({ pingVisibleLinks: pingVisibleLinkPrefetches });
|
|
328
481
|
}
|
|
329
482
|
function pingVisibleLinkPrefetches() {
|
|
330
|
-
for (const instance of visibleLinkPrefetches) if (instance.isVisible && instance.routerMode === "app")
|
|
483
|
+
for (const instance of visibleLinkPrefetches) if (instance.isVisible && instance.routerMode === "app") scheduleVisibleAppPrefetch(instance);
|
|
331
484
|
}
|
|
332
485
|
function getSharedObserver() {
|
|
333
486
|
if (typeof window === "undefined" || typeof IntersectionObserver === "undefined") return null;
|
|
@@ -426,6 +579,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
426
579
|
const resolvedHref = typeof rawResolvedHref === "string" ? warnAndNormalizeRepeatedSlashesInHref(rawResolvedHref) : rawResolvedHref;
|
|
427
580
|
const isDangerous = typeof resolvedHref === "string" && isDangerousScheme(resolvedHref);
|
|
428
581
|
const normalizedHref = normalizePathTrailingSlash(applyLocaleToHref(isDangerous ? "/" : resolvedHref, locale), __trailingSlash);
|
|
582
|
+
const normalizedRouteHref = HAS_PAGES_ROUTER && typeof as === "string" && typeof routeHrefRaw === "string" && as !== routeHrefRaw ? normalizePathTrailingSlash(applyLocaleToHref(isDangerous ? "/" : routeHrefRaw, locale), __trailingSlash) : normalizedHref;
|
|
429
583
|
const fullHref = normalizePathTrailingSlash(withBasePath(normalizedHref, __basePath), __trailingSlash);
|
|
430
584
|
const [pending, setPending] = useState(false);
|
|
431
585
|
const mountedRef = useRef(true);
|
|
@@ -469,7 +623,14 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
469
623
|
const instance = {
|
|
470
624
|
href: hrefToPrefetch,
|
|
471
625
|
isVisible: false,
|
|
626
|
+
locale,
|
|
472
627
|
mode: prefetchMode,
|
|
628
|
+
pagesRouteHref: normalizedRouteHref === normalizedHref ? void 0 : getLinkPrefetchHref({
|
|
629
|
+
href: normalizedRouteHref,
|
|
630
|
+
basePath: __basePath,
|
|
631
|
+
currentOrigin: window.location.origin
|
|
632
|
+
}) ?? void 0,
|
|
633
|
+
queuedViewportPrefetch: false,
|
|
473
634
|
routerMode: getLinkPrefetchRouterMode(),
|
|
474
635
|
viewportPrefetched: false
|
|
475
636
|
};
|
|
@@ -479,11 +640,14 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
479
640
|
observer.unobserve(node);
|
|
480
641
|
observedLinkPrefetches.delete(node);
|
|
481
642
|
visibleLinkPrefetches.delete(instance);
|
|
643
|
+
instance.isVisible = false;
|
|
482
644
|
};
|
|
483
645
|
}, [
|
|
484
646
|
shouldViewportPrefetch,
|
|
485
647
|
prefetchMode,
|
|
486
|
-
normalizedHref
|
|
648
|
+
normalizedHref,
|
|
649
|
+
normalizedRouteHref,
|
|
650
|
+
locale
|
|
487
651
|
]);
|
|
488
652
|
const prefetchOnIntent = useCallback(() => {
|
|
489
653
|
if (!canLinkIntentPrefetch({
|
|
@@ -492,18 +656,20 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
492
656
|
isDangerous,
|
|
493
657
|
routerMode: getLinkPrefetchRouterMode()
|
|
494
658
|
})) return;
|
|
495
|
-
const intentMode = unstable_dynamicOnHover ? "full" : prefetchMode;
|
|
659
|
+
const intentMode = unstable_dynamicOnHover ? "full-after-shell" : prefetchMode;
|
|
496
660
|
if (unstable_dynamicOnHover && internalRef.current) {
|
|
497
661
|
const instance = observedLinkPrefetches.get(internalRef.current);
|
|
498
|
-
if (instance) instance.mode = "full";
|
|
662
|
+
if (instance) instance.mode = "full-after-shell";
|
|
499
663
|
promotePrefetchEntriesForNavigation(normalizedHref);
|
|
500
664
|
}
|
|
501
|
-
prefetchUrl(normalizedHref, intentMode, "high");
|
|
665
|
+
prefetchUrl(normalizedHref, intentMode, "high", normalizedRouteHref === normalizedHref ? void 0 : normalizedRouteHref, locale);
|
|
502
666
|
}, [
|
|
503
667
|
prefetchProp,
|
|
504
668
|
isDangerous,
|
|
505
669
|
prefetchMode,
|
|
506
670
|
normalizedHref,
|
|
671
|
+
normalizedRouteHref,
|
|
672
|
+
locale,
|
|
507
673
|
unstable_dynamicOnHover
|
|
508
674
|
]);
|
|
509
675
|
const handleMouseEnter = useCallback((e) => {
|
|
@@ -553,12 +719,14 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
553
719
|
onNavigate(navEvent);
|
|
554
720
|
if (navEvent.defaultPrevented) return;
|
|
555
721
|
} catch {}
|
|
556
|
-
|
|
722
|
+
const hybridOwner = HAS_PAGES_ROUTER && hasAppNavigationRuntime ? (await import("./internal/hybrid-client-route-owner.js")).resolveHybridClientRouteOwner(navigateHref, __basePath) : null;
|
|
723
|
+
if (HAS_PAGES_ROUTER && hasAppNavigationRuntime && ["pages", "document"].includes(hybridOwner ?? "")) {
|
|
557
724
|
if (replace) window.location.replace(absoluteFullHref);
|
|
558
725
|
else window.location.assign(absoluteFullHref);
|
|
559
726
|
return;
|
|
560
727
|
}
|
|
561
728
|
if (hasAppNavigationRuntime) {
|
|
729
|
+
const { navigateClientSide } = await import("./navigation.js");
|
|
562
730
|
const setter = setPendingRef.current;
|
|
563
731
|
if (setter) setLinkForCurrentNavigation(setter);
|
|
564
732
|
setPending(true);
|
|
@@ -573,7 +741,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
573
741
|
const Router = window.next?.appDir === true ? void 0 : window.next?.router;
|
|
574
742
|
await navigatePagesRouterLinkWithFallback({
|
|
575
743
|
router: Router && "reload" in Router ? Router : void 0,
|
|
576
|
-
loadRouter: async () => (await import("next/router
|
|
744
|
+
loadRouter: async () => (await import("next/router")).default,
|
|
577
745
|
navigation: {
|
|
578
746
|
href: pagesHrefForLink,
|
|
579
747
|
as: pagesAsForLink,
|
|
@@ -651,7 +819,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
651
819
|
onClick: (event) => {
|
|
652
820
|
if (childOnClick) childOnClick(event);
|
|
653
821
|
if (event.defaultPrevented) return;
|
|
654
|
-
handleClick(event, { skipLinkOnClick: true });
|
|
822
|
+
return handleClick(event, { skipLinkOnClick: true });
|
|
655
823
|
},
|
|
656
824
|
onMouseEnter: (event) => {
|
|
657
825
|
if (childOnMouseEnter) childOnMouseEnter(event);
|
|
@@ -673,9 +841,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
|
|
|
673
841
|
children: /* @__PURE__ */ jsx("a", {
|
|
674
842
|
ref: setRefs,
|
|
675
843
|
href: fullHref,
|
|
676
|
-
onClick:
|
|
677
|
-
handleClick(event);
|
|
678
|
-
},
|
|
844
|
+
onClick: handleClick,
|
|
679
845
|
onMouseEnter: handleMouseEnter,
|
|
680
846
|
onTouchStart: handleTouchStart,
|
|
681
847
|
...anchorProps,
|
|
@@ -10,8 +10,9 @@ import * as React$1 from "react";
|
|
|
10
10
|
//#region src/shims/navigation.d.ts
|
|
11
11
|
/** basePath from next.config.js, injected by the plugin at build time */
|
|
12
12
|
declare const __basePath: string;
|
|
13
|
-
/** Maximum
|
|
14
|
-
declare const MAX_PREFETCH_CACHE_SIZE
|
|
13
|
+
/** Maximum buffered bytes in the RSC prefetch cache. Mirrors Next.js' 50 MB LRU. */
|
|
14
|
+
declare const MAX_PREFETCH_CACHE_SIZE: number;
|
|
15
|
+
declare const DYNAMIC_NAVIGATION_CACHE_TTL: number;
|
|
15
16
|
declare const PREFETCH_CACHE_TTL: number;
|
|
16
17
|
/** A buffered RSC response stored as an ArrayBuffer for replay. */
|
|
17
18
|
type CachedRscResponse = {
|
|
@@ -22,12 +23,14 @@ type CachedRscResponse = {
|
|
|
22
23
|
expiresAt?: number;
|
|
23
24
|
mountedSlotsHeader?: string | null;
|
|
24
25
|
paramsHeader: string | null;
|
|
26
|
+
renderedPathAndSearch: string | null;
|
|
25
27
|
url: string;
|
|
26
28
|
};
|
|
27
29
|
type PrefetchOptions = {
|
|
28
30
|
kind?: unknown;
|
|
29
31
|
onInvalidate?: () => void;
|
|
30
32
|
};
|
|
33
|
+
type PrefetchCacheKind = "loading-shell" | "navigation" | "route-tree";
|
|
31
34
|
type PrefetchCacheEntry = {
|
|
32
35
|
cacheForNavigation?: boolean;
|
|
33
36
|
expiresAt?: number;
|
|
@@ -37,7 +40,11 @@ type PrefetchCacheEntry = {
|
|
|
37
40
|
optimisticRouteShell?: boolean;
|
|
38
41
|
outcome: "pending" | "cache-seeded";
|
|
39
42
|
snapshot?: CachedRscResponse;
|
|
43
|
+
cacheKeys?: Set<string>;
|
|
40
44
|
pending?: Promise<void>;
|
|
45
|
+
prefetchKind?: PrefetchCacheKind;
|
|
46
|
+
searchAgnosticShell?: boolean;
|
|
47
|
+
size?: number;
|
|
41
48
|
timestamp: number;
|
|
42
49
|
};
|
|
43
50
|
declare function getCurrentInterceptionContext(): string | null;
|
|
@@ -54,9 +61,13 @@ declare function resolveCachedRscResponseTtlMs(cached: Pick<CachedRscResponse, "
|
|
|
54
61
|
declare function resolveCachedRscResponseExpiresAt(timestamp: number, cached: Pick<CachedRscResponse, "dynamicStaleTimeSeconds" | "expiresAt">, fallbackTtlMs: number): number;
|
|
55
62
|
declare function resolvePrefetchCacheEntryMountedSlotsHeader(entry: PrefetchCacheEntry): string | null;
|
|
56
63
|
declare function hasPrefetchCacheEntryForNavigation(rscUrl: string, interceptionContext?: string | null, mountedSlotsHeader?: string | null, options?: {
|
|
64
|
+
additionalRscUrls?: readonly string[];
|
|
57
65
|
notifyInvalidation?: boolean;
|
|
58
66
|
}): boolean;
|
|
67
|
+
declare function hasSearchAgnosticPrefetchShellForRoute(rscUrl: string, interceptionContext?: string | null, mountedSlotsHeader?: string | null): boolean;
|
|
59
68
|
declare function invalidatePrefetchCache(): void;
|
|
69
|
+
declare function seedPrefetchResponseSnapshot(rscUrl: string, snapshot: CachedRscResponse, interceptionContext?: string | null, mountedSlotsHeader?: string | null, fallbackTtlMs?: number): void;
|
|
70
|
+
declare function deletePrefetchResponseSnapshot(rscUrl: string, snapshot: CachedRscResponse, interceptionContext?: string | null): void;
|
|
60
71
|
/**
|
|
61
72
|
* Store a prefetched RSC response in the cache by snapshotting it to an
|
|
62
73
|
* ArrayBuffer. The snapshot completes asynchronously; during that window
|
|
@@ -105,8 +116,12 @@ declare function restoreRscResponse(cached: CachedRscResponse, copy?: boolean):
|
|
|
105
116
|
*/
|
|
106
117
|
declare function prefetchRscResponse(rscUrl: string, fetchPromise: Promise<Response>, interceptionContext?: string | null, mountedSlotsHeader?: string | null, options?: PrefetchOptions, behavior?: {
|
|
107
118
|
cacheForNavigation?: boolean;
|
|
119
|
+
fallbackTtlMs?: number;
|
|
108
120
|
optimisticRouteShell?: boolean;
|
|
121
|
+
prefetchKind?: PrefetchCacheKind;
|
|
122
|
+
searchAgnosticShell?: boolean;
|
|
109
123
|
}): void;
|
|
124
|
+
declare function peekPrefetchResponseForNavigation(rscUrl: string, interceptionContext?: string | null, mountedSlotsHeader?: string | null): CachedRscResponse | null;
|
|
110
125
|
/**
|
|
111
126
|
* Consume a prefetched response for a given rscUrl.
|
|
112
127
|
* Only returns settled (non-pending) snapshots synchronously.
|
|
@@ -121,6 +136,7 @@ declare function consumePrefetchResponse(rscUrl: string, interceptionContext?: s
|
|
|
121
136
|
* one in-flight network request that navigation should share.
|
|
122
137
|
*/
|
|
123
138
|
type ConsumePrefetchResponseForNavigationOptions = {
|
|
139
|
+
additionalRscUrls?: readonly string[];
|
|
124
140
|
shouldConsume?: () => boolean;
|
|
125
141
|
};
|
|
126
142
|
declare function consumePrefetchResponseForNavigation(rscUrl: string, interceptionContext?: string | null, mountedSlotsHeader?: string | null, options?: ConsumePrefetchResponseForNavigationOptions): Promise<CachedRscResponse | null>;
|
|
@@ -283,4 +299,4 @@ declare function useSelectedLayoutSegments(parallelRoutesKey?: string): string[]
|
|
|
283
299
|
*/
|
|
284
300
|
declare function useServerInsertedHTML(callback: () => unknown): void;
|
|
285
301
|
//#endregion
|
|
286
|
-
export { BailoutToCSRError, CachedRscResponse, ClientNavigationRenderSnapshot, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, type NavigationContext, type NavigationStateAccessors, PREFETCH_CACHE_TTL, PrefetchCacheEntry, PrefetchOptions, ReadonlyURLSearchParams, RedirectType, type SegmentMap, ServerInsertedHTMLContext, UnrecognizedActionError, __basePath, _registerStateAccessors, activateNavigationSnapshot, appRouterInstance, applyAppRouterScrollFallback, clearPendingPathname, clearServerInsertedHTML, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, decodeRedirectError, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getClientNavigationRenderContext, getClientNavigationState, getClientParams, getCurrentInterceptionContext, getCurrentNextUrl, getLayoutSegmentContext, getMountedSlotsHeader, getNavigationContext, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, invalidatePrefetchCache, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, navigateClientSide, notFound, permanentRedirect, prefetchRscResponse, pushHistoryStateWithoutNotify, redirect, renderServerInsertedHTML, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveCachedRscResponseExpiresAt, resolveCachedRscResponseTtlMs, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, setClientParams, setMountedSlotsHeader, setNavigationContext, setPendingPathname, snapshotRscResponse, storePrefetchResponse, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useClientNavigationRenderSnapshot, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
|
|
302
|
+
export { BailoutToCSRError, CachedRscResponse, ClientNavigationRenderSnapshot, DYNAMIC_NAVIGATION_CACHE_TTL, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, type NavigationContext, type NavigationStateAccessors, PREFETCH_CACHE_TTL, PrefetchCacheEntry, PrefetchCacheKind, PrefetchOptions, ReadonlyURLSearchParams, RedirectType, type SegmentMap, ServerInsertedHTMLContext, UnrecognizedActionError, __basePath, _registerStateAccessors, activateNavigationSnapshot, appRouterInstance, applyAppRouterScrollFallback, clearPendingPathname, clearServerInsertedHTML, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, decodeRedirectError, deletePrefetchResponseSnapshot, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getClientNavigationRenderContext, getClientNavigationState, getClientParams, getCurrentInterceptionContext, getCurrentNextUrl, getLayoutSegmentContext, getMountedSlotsHeader, getNavigationContext, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, hasSearchAgnosticPrefetchShellForRoute, invalidatePrefetchCache, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, navigateClientSide, notFound, peekPrefetchResponseForNavigation, permanentRedirect, prefetchRscResponse, pushHistoryStateWithoutNotify, redirect, renderServerInsertedHTML, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveCachedRscResponseExpiresAt, resolveCachedRscResponseTtlMs, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, seedPrefetchResponseSnapshot, setClientParams, setMountedSlotsHeader, setNavigationContext, setPendingPathname, snapshotRscResponse, storePrefetchResponse, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useClientNavigationRenderSnapshot, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
|