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/image.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { getDeploymentId } from "../utils/deployment-id.js";
|
|
2
3
|
import { useMergedRef } from "./use-merged-ref.js";
|
|
3
4
|
import { hasRemoteMatch, isPrivateIp } from "./image-config.js";
|
|
4
5
|
import { forwardRef, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
@@ -54,6 +55,22 @@ const __imageDeviceSizes = (() => {
|
|
|
54
55
|
];
|
|
55
56
|
}
|
|
56
57
|
})();
|
|
58
|
+
const __imageSizes = (() => {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(process.env.__VINEXT_IMAGE_SIZES ?? "[16,32,48,64,96,128,256,384]");
|
|
61
|
+
} catch {
|
|
62
|
+
return [
|
|
63
|
+
16,
|
|
64
|
+
32,
|
|
65
|
+
48,
|
|
66
|
+
64,
|
|
67
|
+
96,
|
|
68
|
+
128,
|
|
69
|
+
256,
|
|
70
|
+
384
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
57
74
|
/**
|
|
58
75
|
* Whether dangerouslyAllowSVG is enabled in next.config.js.
|
|
59
76
|
* When false (default), .svg sources auto-skip the optimization endpoint
|
|
@@ -68,6 +85,7 @@ const __dangerouslyAllowSVG = process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_SVG =
|
|
|
68
85
|
* are blocked to mitigate SSRF risk.
|
|
69
86
|
*/
|
|
70
87
|
const __dangerouslyAllowLocalIP = process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_LOCAL_IP === "true";
|
|
88
|
+
const __globallyUnoptimized = process.env.__VINEXT_IMAGE_UNOPTIMIZED === "true";
|
|
71
89
|
/**
|
|
72
90
|
* Validate that a remote URL is allowed by the configured remote patterns.
|
|
73
91
|
* Returns true if the URL is allowed, false otherwise.
|
|
@@ -210,7 +228,33 @@ function resolveImageSource(v) {
|
|
|
210
228
|
* These are the breakpoints used for srcSet generation.
|
|
211
229
|
* Configurable via `images.deviceSizes` in next.config.js.
|
|
212
230
|
*/
|
|
213
|
-
const RESPONSIVE_WIDTHS = __imageDeviceSizes;
|
|
231
|
+
const RESPONSIVE_WIDTHS = [...__imageDeviceSizes].sort((left, right) => left - right);
|
|
232
|
+
const ALL_IMAGE_WIDTHS = [...RESPONSIVE_WIDTHS, ...__imageSizes].sort((left, right) => left - right);
|
|
233
|
+
function extractLocalDeploymentId(src) {
|
|
234
|
+
let deploymentId = getDeploymentId();
|
|
235
|
+
if (!src.startsWith("/") || src.startsWith("//")) return {
|
|
236
|
+
src,
|
|
237
|
+
deploymentId
|
|
238
|
+
};
|
|
239
|
+
const queryIndex = src.indexOf("?");
|
|
240
|
+
if (queryIndex === -1) return {
|
|
241
|
+
src,
|
|
242
|
+
deploymentId
|
|
243
|
+
};
|
|
244
|
+
const params = new URLSearchParams(src.slice(queryIndex + 1));
|
|
245
|
+
const sourceDeploymentId = params.get("dpl");
|
|
246
|
+
if (!sourceDeploymentId) return {
|
|
247
|
+
src,
|
|
248
|
+
deploymentId
|
|
249
|
+
};
|
|
250
|
+
deploymentId = sourceDeploymentId;
|
|
251
|
+
params.delete("dpl");
|
|
252
|
+
const remainingQuery = params.toString();
|
|
253
|
+
return {
|
|
254
|
+
src: src.slice(0, queryIndex) + (remainingQuery ? `?${remainingQuery}` : ""),
|
|
255
|
+
deploymentId
|
|
256
|
+
};
|
|
257
|
+
}
|
|
214
258
|
/**
|
|
215
259
|
* Build a `/_next/image` optimization URL.
|
|
216
260
|
*
|
|
@@ -219,7 +263,9 @@ const RESPONSIVE_WIDTHS = __imageDeviceSizes;
|
|
|
219
263
|
* server handles it as a passthrough (serves the original file).
|
|
220
264
|
*/
|
|
221
265
|
function imageOptimizationUrl(src, width, quality = 75) {
|
|
222
|
-
|
|
266
|
+
const source = extractLocalDeploymentId(src);
|
|
267
|
+
const deploymentQuery = source.src.startsWith("/") && source.deploymentId ? `&dpl=${source.deploymentId}` : "";
|
|
268
|
+
return `/_next/image?url=${encodeURIComponent(source.src)}&w=${width}&q=${quality}${deploymentQuery}`;
|
|
223
269
|
}
|
|
224
270
|
function preloadImageResource(input) {
|
|
225
271
|
if (!input.shouldPreload) return;
|
|
@@ -235,13 +281,26 @@ function preloadImageResource(input) {
|
|
|
235
281
|
* Generate a srcSet string for responsive images.
|
|
236
282
|
*
|
|
237
283
|
* Each width points to the `/_next/image` optimization endpoint so the
|
|
238
|
-
* server can resize and transcode the image.
|
|
239
|
-
* <= 2x the original image width to avoid pointless upscaling.
|
|
284
|
+
* server can resize and transcode the image.
|
|
240
285
|
*/
|
|
241
|
-
function
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
286
|
+
function getImageWidths(width) {
|
|
287
|
+
return [...new Set([width, width * 2].map((targetWidth) => ALL_IMAGE_WIDTHS.find((configuredWidth) => configuredWidth >= targetWidth) ?? ALL_IMAGE_WIDTHS[ALL_IMAGE_WIDTHS.length - 1]))];
|
|
288
|
+
}
|
|
289
|
+
function generateImageAttributes(src, width, quality = 75, sizes) {
|
|
290
|
+
if (sizes) {
|
|
291
|
+
const viewportPercentages = Array.from(sizes.matchAll(/(^|\s)(1?\d?\d)vw/g), (match) => Number.parseInt(match[2], 10));
|
|
292
|
+
const minimumWidth = viewportPercentages.length > 0 ? RESPONSIVE_WIDTHS[0] * (Math.min(...viewportPercentages) * .01) : 0;
|
|
293
|
+
const candidates = ALL_IMAGE_WIDTHS.filter((candidateWidth) => candidateWidth >= minimumWidth);
|
|
294
|
+
return {
|
|
295
|
+
src: imageOptimizationUrl(src, candidates[candidates.length - 1], quality),
|
|
296
|
+
srcSet: candidates.map((candidateWidth) => `${imageOptimizationUrl(src, candidateWidth, quality)} ${candidateWidth}w`).join(", ")
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
const widths = getImageWidths(width);
|
|
300
|
+
return {
|
|
301
|
+
src: imageOptimizationUrl(src, widths[widths.length - 1], quality),
|
|
302
|
+
srcSet: widths.map((candidateWidth, index) => `${imageOptimizationUrl(src, candidateWidth, quality)} ${index + 1}x`).join(", ")
|
|
303
|
+
};
|
|
245
304
|
}
|
|
246
305
|
const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill, preload, priority, quality, placeholder, blurDataURL, loader, sizes, className, style, onLoad, onLoadingComplete, onError, unoptimized: _unoptimized, overrideSrc, loading, ...rest }, ref) {
|
|
247
306
|
const lastLoadedSrcRef = useRef(void 0);
|
|
@@ -326,7 +385,7 @@ const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill
|
|
|
326
385
|
lastErrorSrcRef.current = src;
|
|
327
386
|
markBlurComplete();
|
|
328
387
|
} : void 0;
|
|
329
|
-
if (_unoptimized === true) {
|
|
388
|
+
if (_unoptimized === true || __globallyUnoptimized) {
|
|
330
389
|
const renderedSrc = overrideSrc || src;
|
|
331
390
|
const sanitizedBlur = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
|
|
332
391
|
const blurStyle = !blurComplete && placeholder === "blur" && sanitizedBlur ? {
|
|
@@ -456,8 +515,9 @@ const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill
|
|
|
456
515
|
}
|
|
457
516
|
const imgQuality = quality ?? 75;
|
|
458
517
|
const skipOptimization = isSvgUrl(src) && !__dangerouslyAllowSVG;
|
|
459
|
-
const
|
|
460
|
-
const
|
|
518
|
+
const optimizedAttributes = imgWidth && !fill && !skipOptimization ? generateImageAttributes(src, imgWidth, imgQuality, sizes) : void 0;
|
|
519
|
+
const srcSet = optimizedAttributes ? optimizedAttributes.srcSet : imgWidth && !fill ? RESPONSIVE_WIDTHS.filter((w) => w <= imgWidth * 2).map((w) => `${src} ${w}w`).join(", ") || `${src} ${imgWidth}w` : void 0;
|
|
520
|
+
const optimizedSrc = skipOptimization ? src : optimizedAttributes ? optimizedAttributes.src : imageOptimizationUrl(src, RESPONSIVE_WIDTHS[0], imgQuality);
|
|
461
521
|
const sanitizedLocalBlur = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
|
|
462
522
|
const blurStyle = !blurComplete && placeholder === "blur" && sanitizedLocalBlur ? {
|
|
463
523
|
backgroundImage: `url(${sanitizedLocalBlur})`,
|
|
@@ -508,7 +568,7 @@ function getImageProps(props) {
|
|
|
508
568
|
blurDataURL: blurDataURLProp
|
|
509
569
|
});
|
|
510
570
|
const shouldPreload = _preload === true || priority === true;
|
|
511
|
-
if (_unoptimized === true) {
|
|
571
|
+
if (_unoptimized === true || __globallyUnoptimized) {
|
|
512
572
|
const renderedSrc = overrideSrc || src;
|
|
513
573
|
const sanitizedBlurURL = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
|
|
514
574
|
const blurStyle = placeholder === "blur" && sanitizedBlurURL ? {
|
|
@@ -550,8 +610,9 @@ function getImageProps(props) {
|
|
|
550
610
|
quality: imgQuality
|
|
551
611
|
}) : src;
|
|
552
612
|
const skipOpt = isSvgUrl(resolvedSrc) && !__dangerouslyAllowSVG || blockedInProd || !!loader || isRemoteUrl(resolvedSrc);
|
|
553
|
-
const
|
|
554
|
-
const
|
|
613
|
+
const optimizedAttributes = imgWidth && !fill && !skipOpt ? generateImageAttributes(resolvedSrc, imgWidth, imgQuality, sizes) : null;
|
|
614
|
+
const optimizedSrc = skipOpt ? resolvedSrc : optimizedAttributes ? optimizedAttributes.src : imageOptimizationUrl(resolvedSrc, RESPONSIVE_WIDTHS[0], imgQuality);
|
|
615
|
+
const srcSet = optimizedAttributes?.srcSet;
|
|
555
616
|
const sanitizedBlurURL = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
|
|
556
617
|
const blurStyle = placeholder === "blur" && sanitizedBlurURL ? {
|
|
557
618
|
backgroundImage: `url(${sanitizedBlurURL})`,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/shims/internal/app-prefetch-fetch-queue.d.ts
|
|
2
|
+
declare function releaseAppPrefetchFetchSlot(response: Response): void;
|
|
3
|
+
/**
|
|
4
|
+
* Low-priority App Router prefetches share a small request queue. The consumer
|
|
5
|
+
* must either snapshot the returned Response with snapshotRscResponse() or call
|
|
6
|
+
* releaseAppPrefetchFetchSlot() when it drops the response without consuming it.
|
|
7
|
+
*/
|
|
8
|
+
declare function scheduleAppPrefetchFetch(fetcher: () => Promise<Response>, priority: "low" | "high"): Promise<Response>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { releaseAppPrefetchFetchSlot, scheduleAppPrefetchFetch };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/shims/internal/app-prefetch-fetch-queue.ts
|
|
3
|
+
const APP_PREFETCH_FETCH_SLOT_RELEASE_KEY = Symbol.for("vinext.appPrefetchFetchSlotRelease");
|
|
4
|
+
const MAX_DEFAULT_APP_PREFETCH_REQUESTS = 4;
|
|
5
|
+
const defaultAppPrefetchQueue = [];
|
|
6
|
+
let activeDefaultAppPrefetchRequests = 0;
|
|
7
|
+
let defaultAppPrefetchDrainScheduled = false;
|
|
8
|
+
function drainDefaultAppPrefetchQueue() {
|
|
9
|
+
defaultAppPrefetchDrainScheduled = false;
|
|
10
|
+
while (activeDefaultAppPrefetchRequests < MAX_DEFAULT_APP_PREFETCH_REQUESTS) {
|
|
11
|
+
const run = defaultAppPrefetchQueue.shift();
|
|
12
|
+
if (!run) return;
|
|
13
|
+
activeDefaultAppPrefetchRequests += 1;
|
|
14
|
+
run();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function scheduleDefaultAppPrefetchDrain() {
|
|
18
|
+
if (defaultAppPrefetchDrainScheduled) return;
|
|
19
|
+
defaultAppPrefetchDrainScheduled = true;
|
|
20
|
+
queueMicrotask(drainDefaultAppPrefetchQueue);
|
|
21
|
+
}
|
|
22
|
+
function releaseAppPrefetchFetchSlot(response) {
|
|
23
|
+
const release = response[APP_PREFETCH_FETCH_SLOT_RELEASE_KEY];
|
|
24
|
+
if (release === void 0) return;
|
|
25
|
+
response[APP_PREFETCH_FETCH_SLOT_RELEASE_KEY] = void 0;
|
|
26
|
+
release();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Low-priority App Router prefetches share a small request queue. The consumer
|
|
30
|
+
* must either snapshot the returned Response with snapshotRscResponse() or call
|
|
31
|
+
* releaseAppPrefetchFetchSlot() when it drops the response without consuming it.
|
|
32
|
+
*/
|
|
33
|
+
function scheduleAppPrefetchFetch(fetcher, priority) {
|
|
34
|
+
if (priority === "high") return fetcher();
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
defaultAppPrefetchQueue.push(() => {
|
|
37
|
+
let didRelease = false;
|
|
38
|
+
const release = () => {
|
|
39
|
+
if (didRelease) return;
|
|
40
|
+
didRelease = true;
|
|
41
|
+
activeDefaultAppPrefetchRequests -= 1;
|
|
42
|
+
drainDefaultAppPrefetchQueue();
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
fetcher().then((response) => {
|
|
46
|
+
response[APP_PREFETCH_FETCH_SLOT_RELEASE_KEY] = release;
|
|
47
|
+
resolve(response);
|
|
48
|
+
}, (error) => {
|
|
49
|
+
release();
|
|
50
|
+
reject(error);
|
|
51
|
+
});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
release();
|
|
54
|
+
reject(error);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
scheduleDefaultAppPrefetchDrain();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { releaseAppPrefetchFetchSlot, scheduleAppPrefetchFetch };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { VinextLinkPrefetchRoute } from "../../client/vinext-next-data.js";
|
|
2
|
+
import { getPagesRouterComponentsMap } from "./pages-router-components.js";
|
|
2
3
|
|
|
3
4
|
//#region src/shims/internal/app-route-detection.d.ts
|
|
4
5
|
declare global {
|
|
@@ -6,22 +7,6 @@ declare global {
|
|
|
6
7
|
__VINEXT_LINK_PREFETCH_ROUTES__?: VinextLinkPrefetchRoute[];
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
|
-
/**
|
|
10
|
-
* Pages Router `components` map shape. Next.js types this loosely (route
|
|
11
|
-
* pattern → `PrivateRouteInfo`), but for the App Router-detected case it
|
|
12
|
-
* stores `{ __appRouter: true }` as a marker (see Next.js source link above).
|
|
13
|
-
* Vinext only writes the marker variant; reads are by test code that checks
|
|
14
|
-
* for `__appRouter: true`.
|
|
15
|
-
*/
|
|
16
|
-
type PagesRouterComponentsMap = Record<string, {
|
|
17
|
-
__appRouter: true;
|
|
18
|
-
} | Record<string, unknown>>;
|
|
19
|
-
/**
|
|
20
|
-
* Get-or-create the Pages Router `components` map. Returns the same object
|
|
21
|
-
* on every call so `router.components` and `window.next.router.components`
|
|
22
|
-
* have referential identity.
|
|
23
|
-
*/
|
|
24
|
-
declare function getPagesRouterComponentsMap(): PagesRouterComponentsMap;
|
|
25
10
|
/**
|
|
26
11
|
* Record `components[pathname] = { __appRouter: true }` on the shared
|
|
27
12
|
* Pages Router map when the href matches an App Router route. No-op when the
|
|
@@ -34,6 +19,6 @@ declare function getPagesRouterComponentsMap(): PagesRouterComponentsMap;
|
|
|
34
19
|
* first (e.g. `link.tsx` normalises to match `trailingSlash` config before
|
|
35
20
|
* calling, while `router.prefetch()` passes the raw user-supplied URL).
|
|
36
21
|
*/
|
|
37
|
-
declare function markAppRouteDetectedOnPrefetch(href: string, basePath: string): void
|
|
22
|
+
declare function markAppRouteDetectedOnPrefetch(href: string, basePath: string): Promise<void>;
|
|
38
23
|
//#endregion
|
|
39
24
|
export { getPagesRouterComponentsMap, markAppRouteDetectedOnPrefetch };
|
|
@@ -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,7 @@
|
|
|
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
|
-
|
|
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
|
-
}
|
|
4
|
+
declare function resolveHybridClientRewriteHref(href: string, basePath: string): string | null;
|
|
17
5
|
/**
|
|
18
6
|
* Decide which router should own a soft-navigated URL. Returns:
|
|
19
7
|
* - "app" → the App Router runtime handles the navigation (RSC fetch).
|
|
@@ -28,4 +16,4 @@ declare global {
|
|
|
28
16
|
*/
|
|
29
17
|
declare function resolveHybridClientRouteOwner(href: string, basePath: string): HybridClientOwner | null;
|
|
30
18
|
//#endregion
|
|
31
|
-
export { HybridClientOwner, resolveHybridClientRouteOwner };
|
|
19
|
+
export { type HybridClientOwner, resolveHybridClientRewriteHref, 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,44 +49,38 @@ function resolveClientRewrite(href, basePath, rewrites, continueAfterMatch = fal
|
|
|
52
49
|
kind: "rewrite"
|
|
53
50
|
} : null;
|
|
54
51
|
}
|
|
55
|
-
|
|
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) {
|
|
52
|
+
function resolveHybridClientRewriteHref(href, basePath) {
|
|
70
53
|
if (typeof window === "undefined") return null;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
54
|
+
const rewrites = window.__VINEXT_CLIENT_REWRITES__;
|
|
55
|
+
if (!rewrites) return null;
|
|
56
|
+
let currentHref = href;
|
|
57
|
+
let didRewrite = false;
|
|
58
|
+
const beforeFilesRewrite = resolveClientRewrite(currentHref, basePath, rewrites.beforeFiles, true);
|
|
59
|
+
if (beforeFilesRewrite?.kind === "document") return null;
|
|
60
|
+
if (beforeFilesRewrite?.kind === "rewrite") {
|
|
61
|
+
currentHref = beforeFilesRewrite.href;
|
|
62
|
+
didRewrite = true;
|
|
76
63
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
64
|
+
let matches = matchDirectHybridClientRoutes(currentHref, basePath);
|
|
65
|
+
if ((matches.appMatch === null || matches.appMatch.isDynamic) && (matches.pagesMatch === null || matches.pagesMatch.isDynamic)) for (const rewrite of rewrites.afterFiles) {
|
|
66
|
+
const afterFilesRewrite = resolveClientRewrite(currentHref, basePath, [rewrite]);
|
|
67
|
+
if (afterFilesRewrite?.kind === "document") return didRewrite ? currentHref : null;
|
|
68
|
+
if (afterFilesRewrite?.kind !== "rewrite") continue;
|
|
69
|
+
currentHref = afterFilesRewrite.href;
|
|
70
|
+
didRewrite = true;
|
|
71
|
+
matches = matchDirectHybridClientRoutes(currentHref, basePath);
|
|
72
|
+
if (matches.appMatch || matches.pagesMatch) break;
|
|
73
|
+
}
|
|
74
|
+
if (matches.appMatch === null && matches.pagesMatch === null) for (const rewrite of rewrites.fallback) {
|
|
75
|
+
const fallbackRewrite = resolveClientRewrite(currentHref, basePath, [rewrite]);
|
|
76
|
+
if (fallbackRewrite?.kind === "document") return didRewrite ? currentHref : null;
|
|
77
|
+
if (fallbackRewrite?.kind !== "rewrite") continue;
|
|
78
|
+
currentHref = fallbackRewrite.href;
|
|
79
|
+
didRewrite = true;
|
|
80
|
+
matches = matchDirectHybridClientRoutes(currentHref, basePath);
|
|
81
|
+
if (matches.appMatch || matches.pagesMatch) break;
|
|
82
|
+
}
|
|
83
|
+
return didRewrite ? currentHref : null;
|
|
93
84
|
}
|
|
94
85
|
/**
|
|
95
86
|
* Decide which router should own a soft-navigated URL. Returns:
|
|
@@ -105,39 +96,30 @@ function matchPagesRoute(href, basePath, routes) {
|
|
|
105
96
|
*/
|
|
106
97
|
function resolveHybridClientRouteOwner(href, basePath) {
|
|
107
98
|
if (typeof window === "undefined") return null;
|
|
108
|
-
const appRoutes = window.__VINEXT_LINK_PREFETCH_ROUTES__;
|
|
109
|
-
const pagesRoutes = window.__VINEXT_PAGES_LINK_PREFETCH_ROUTES__;
|
|
110
99
|
const rewrites = window.__VINEXT_CLIENT_REWRITES__;
|
|
111
100
|
if (rewrites) {
|
|
112
101
|
const beforeFilesRewrite = resolveClientRewrite(href, basePath, rewrites.beforeFiles, true);
|
|
113
102
|
if (beforeFilesRewrite?.kind === "document") return "document";
|
|
114
103
|
if (beforeFilesRewrite?.kind === "rewrite") href = beforeFilesRewrite.href;
|
|
115
104
|
}
|
|
116
|
-
let
|
|
117
|
-
|
|
118
|
-
if (rewrites && (appMatch === null || appMatch.isDynamic) && (pagesMatch === null || pagesMatch.isDynamic)) for (const rewrite of rewrites.afterFiles) {
|
|
105
|
+
let matches = matchDirectHybridClientRoutes(href, basePath);
|
|
106
|
+
if (rewrites && (matches.appMatch === null || matches.appMatch.isDynamic) && (matches.pagesMatch === null || matches.pagesMatch.isDynamic)) for (const rewrite of rewrites.afterFiles) {
|
|
119
107
|
const afterFilesRewrite = resolveClientRewrite(href, basePath, [rewrite]);
|
|
120
108
|
if (afterFilesRewrite?.kind === "document") return "document";
|
|
121
109
|
if (afterFilesRewrite?.kind !== "rewrite") continue;
|
|
122
110
|
href = afterFilesRewrite.href;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (appMatch || pagesMatch) break;
|
|
111
|
+
matches = matchDirectHybridClientRoutes(href, basePath);
|
|
112
|
+
if (matches.appMatch || matches.pagesMatch) break;
|
|
126
113
|
}
|
|
127
|
-
if (rewrites && appMatch === null && pagesMatch === null) for (const rewrite of rewrites.fallback) {
|
|
114
|
+
if (rewrites && matches.appMatch === null && matches.pagesMatch === null) for (const rewrite of rewrites.fallback) {
|
|
128
115
|
const fallbackRewrite = resolveClientRewrite(href, basePath, [rewrite]);
|
|
129
116
|
if (fallbackRewrite?.kind === "document") return "document";
|
|
130
117
|
if (fallbackRewrite?.kind !== "rewrite") continue;
|
|
131
118
|
href = fallbackRewrite.href;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (appMatch || pagesMatch) break;
|
|
119
|
+
matches = matchDirectHybridClientRoutes(href, basePath);
|
|
120
|
+
if (matches.appMatch || matches.pagesMatch) break;
|
|
135
121
|
}
|
|
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;
|
|
122
|
+
return resolveMatchedHybridClientRouteOwner(matches);
|
|
141
123
|
}
|
|
142
124
|
//#endregion
|
|
143
|
-
export { resolveHybridClientRouteOwner };
|
|
125
|
+
export { resolveHybridClientRewriteHref, resolveHybridClientRouteOwner };
|
|
@@ -24,14 +24,19 @@
|
|
|
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 fetchUncachedPagesData(dataHref: string, init?: RequestInit): Promise<Response>;
|
|
39
|
+
declare function evictPagesDataCache(dataHref: string): void;
|
|
35
40
|
/**
|
|
36
41
|
* Dedupe a `fetch()` against the `_next/data` endpoint. Multiple concurrent
|
|
37
42
|
* callers for the same resolved URL and deployment ID share one underlying
|
|
@@ -51,4 +56,4 @@ declare function dedupedPagesDataFetch(dataHref: string, init?: RequestInit): Pr
|
|
|
51
56
|
*/
|
|
52
57
|
declare function clearPagesDataInflight(): void;
|
|
53
58
|
//#endregion
|
|
54
|
-
export { clearPagesDataInflight, dedupedPagesDataFetch };
|
|
59
|
+
export { clearPagesDataInflight, dedupedPagesDataFetch, evictPagesDataCache, fetchCachedPagesData, fetchStaticPagesData, fetchUncachedPagesData, getPagesStaticDataCache };
|