vinext 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -10
- package/dist/build/app-page-static-eligibility.d.ts +15 -0
- package/dist/build/app-page-static-eligibility.js +82 -0
- package/dist/build/client-build-config.d.ts +10 -0
- package/dist/build/client-build-config.js +18 -2
- package/dist/build/pages-client-assets-module.d.ts +8 -0
- package/dist/build/pages-client-assets-module.js +21 -1
- package/dist/build/prerender-paths.js +8 -81
- package/dist/build/prerender.js +33 -8
- package/dist/build/run-prerender.js +1 -1
- package/dist/build/server-manifest.d.ts +7 -0
- package/dist/build/server-manifest.js +11 -1
- package/dist/build/ssr-manifest.d.ts +2 -0
- package/dist/build/ssr-manifest.js +6 -2
- package/dist/cache/cache-adapters-virtual.d.ts +7 -1
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.js +7 -6
- package/dist/cli.js +2 -1
- package/dist/client/client-redirect-matcher.d.ts +14 -0
- package/dist/client/client-redirect-matcher.js +37 -0
- package/dist/client/client-redirects.d.ts +27 -0
- package/dist/client/client-redirects.js +28 -0
- package/dist/client/client-rewrites.d.ts +2 -1
- package/dist/client/client-rewrites.js +1 -1
- package/dist/client/navigation-runtime.d.ts +11 -0
- package/dist/client/navigation-runtime.js +1 -1
- package/dist/config/config-matchers.d.ts +26 -11
- package/dist/config/config-matchers.js +81 -82
- package/dist/config/destination-params.d.ts +47 -0
- package/dist/config/destination-params.js +116 -0
- package/dist/config/next-config.d.ts +14 -0
- package/dist/config/next-config.js +21 -3
- package/dist/entries/app-rsc-entry.d.ts +6 -0
- package/dist/entries/app-rsc-entry.js +84 -49
- package/dist/entries/pages-client-entry.js +3 -1
- package/dist/entries/pages-server-entry.js +13 -37
- package/dist/index.d.ts +7 -2
- package/dist/index.js +193 -73
- package/dist/init-cloudflare.d.ts +9 -0
- package/dist/init-cloudflare.js +107 -31
- package/dist/init-platform.d.ts +4 -0
- package/dist/init-platform.js +27 -2
- package/dist/init.d.ts +1 -0
- package/dist/init.js +67 -3
- package/dist/plugins/ast-scope.d.ts +7 -0
- package/dist/plugins/ast-scope.js +59 -3
- package/dist/plugins/cache-flight-codec.d.ts +19 -0
- package/dist/plugins/cache-flight-codec.js +68 -0
- package/dist/plugins/commonjs-esm-facade.d.ts +35 -0
- package/dist/plugins/commonjs-esm-facade.js +80 -0
- package/dist/plugins/dynamic-preload-metadata.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +9 -8
- package/dist/plugins/fonts.d.ts +8 -11
- package/dist/plugins/fonts.js +71 -34
- package/dist/plugins/ignore-dynamic-requests.d.ts +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +3 -4
- package/dist/plugins/middleware-server-only.d.ts +5 -4
- package/dist/plugins/middleware-server-only.js +8 -5
- package/dist/plugins/pages-node-externals.js +1 -1
- package/dist/plugins/rsc-scan-glob-imports.d.ts +19 -0
- package/dist/plugins/rsc-scan-glob-imports.js +50 -0
- package/dist/plugins/strip-server-exports.js +262 -98
- package/dist/plugins/transform-result.d.ts +9 -5
- package/dist/plugins/transitive-externals.js +1 -1
- package/dist/plugins/typeof-window.d.ts +2 -2
- package/dist/plugins/use-cache-callable.js +8 -2
- package/dist/plugins/worker-server-only-imports.d.ts +20 -0
- package/dist/plugins/worker-server-only-imports.js +31 -0
- package/dist/plugins/worker-use-server.d.ts +25 -0
- package/dist/plugins/worker-use-server.js +129 -0
- package/dist/routing/file-matcher.d.ts +1 -0
- package/dist/routing/file-matcher.js +1 -1
- package/dist/server/api-handler.d.ts +1 -0
- package/dist/server/api-handler.js +19 -8
- package/dist/server/app-browser-action-result.d.ts +1 -1
- package/dist/server/app-browser-action-result.js +9 -2
- package/dist/server/app-browser-entry.js +11 -7
- package/dist/server/app-browser-history-controller.d.ts +2 -0
- package/dist/server/app-browser-history-controller.js +8 -0
- package/dist/server/app-browser-interception-context.js +26 -2
- package/dist/server/app-browser-navigation-controller.d.ts +7 -1
- package/dist/server/app-browser-navigation-controller.js +94 -11
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-fallback-renderer.d.ts +2 -0
- package/dist/server/app-fallback-renderer.js +1 -0
- package/dist/server/app-history-state.d.ts +3 -0
- package/dist/server/app-history-state.js +7 -0
- package/dist/server/app-middleware.d.ts +11 -0
- package/dist/server/app-middleware.js +19 -3
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-boundary-render.d.ts +5 -0
- package/dist/server/app-page-boundary-render.js +6 -4
- package/dist/server/app-page-cache-finalizer.d.ts +11 -0
- package/dist/server/app-page-cache-finalizer.js +41 -7
- package/dist/server/app-page-cache-render.d.ts +18 -0
- package/dist/server/app-page-cache-render.js +63 -43
- package/dist/server/app-page-cache.d.ts +6 -1
- package/dist/server/app-page-cache.js +28 -8
- package/dist/server/app-page-dispatch.d.ts +12 -2
- package/dist/server/app-page-dispatch.js +51 -33
- package/dist/server/app-page-element-builder.d.ts +7 -0
- package/dist/server/app-page-element-builder.js +27 -42
- package/dist/server/app-page-execution.d.ts +15 -12
- package/dist/server/app-page-execution.js +30 -40
- package/dist/server/app-page-head.d.ts +5 -0
- package/dist/server/app-page-head.js +9 -3
- package/dist/server/app-page-ppr-runtime.js +1 -1
- package/dist/server/app-page-probe.d.ts +0 -109
- package/dist/server/app-page-probe.js +3 -136
- package/dist/server/app-page-render-identity.d.ts +0 -1
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render-observation.js +3 -3
- package/dist/server/app-page-render.d.ts +13 -5
- package/dist/server/app-page-render.js +219 -119
- package/dist/server/app-page-request.d.ts +0 -1
- package/dist/server/app-page-request.js +54 -17
- package/dist/server/app-page-response.d.ts +4 -3
- package/dist/server/app-page-response.js +4 -3
- package/dist/server/app-page-route-wiring.d.ts +17 -5
- package/dist/server/app-page-route-wiring.js +57 -35
- package/dist/server/app-page-rsc-render-status.d.ts +48 -0
- package/dist/server/app-page-rsc-render-status.js +54 -0
- package/dist/server/app-page-stream.d.ts +15 -8
- package/dist/server/app-page-stream.js +6 -0
- package/dist/server/app-pages-bridge.d.ts +1 -1
- package/dist/server/app-pages-bridge.js +2 -3
- package/dist/server/app-prerender-endpoints.js +9 -6
- package/dist/server/app-request-stage-dispatch.js +7 -3
- package/dist/server/app-request-stage-independent-entry.js +29 -9
- package/dist/server/app-response-header-provenance.d.ts +2 -0
- package/dist/server/app-response-header-provenance.js +10 -4
- package/dist/server/app-response-stage-entry.js +10 -2
- package/dist/server/app-route-handler-cache.d.ts +1 -0
- package/dist/server/app-route-handler-cache.js +1 -0
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +6 -3
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-runtime.d.ts +4 -1
- package/dist/server/app-route-handler-runtime.js +45 -24
- package/dist/server/app-router-entry.js +27 -8
- package/dist/server/app-rsc-cache-busting.js +1 -1
- package/dist/server/app-rsc-errors.js +20 -16
- package/dist/server/app-rsc-handler.d.ts +11 -0
- package/dist/server/app-rsc-handler.js +291 -125
- package/dist/server/app-rsc-request-normalization.d.ts +3 -1
- package/dist/server/app-rsc-request-normalization.js +4 -2
- package/dist/server/app-rsc-response-stage.d.ts +1 -1
- package/dist/server/app-rsc-response-stage.js +10 -6
- package/dist/server/app-rsc-route-matching.d.ts +9 -1
- package/dist/server/app-rsc-route-matching.js +36 -19
- package/dist/server/app-segment-config.d.ts +2 -1
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-server-action-execution.js +62 -23
- package/dist/server/app-ssr-entry.d.ts +3 -2
- package/dist/server/app-ssr-entry.js +8 -5
- package/dist/server/app-ssr-stream.d.ts +6 -1
- package/dist/server/app-ssr-stream.js +34 -15
- package/dist/server/app-worker-stages.d.ts +7 -2
- package/dist/server/app-worker-stages.js +4 -4
- package/dist/server/cacheability-request.js +11 -7
- package/dist/server/client-build-files.d.ts +16 -0
- package/dist/server/client-build-files.js +36 -0
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/config-headers.js +2 -0
- package/dist/server/dev-server.js +50 -29
- package/dist/server/dev-stack-sourcemap.js +18 -23
- package/dist/server/document-initial-head.d.ts +0 -11
- package/dist/server/document-initial-head.js +1 -1
- package/dist/server/forwarded-middleware-context.d.ts +5 -0
- package/dist/server/forwarded-middleware-context.js +22 -0
- package/dist/server/headers.d.ts +18 -1
- package/dist/server/headers.js +19 -2
- package/dist/server/http-conditional.d.ts +11 -0
- package/dist/server/http-conditional.js +10 -1
- package/dist/server/http-error-responses.d.ts +1 -1
- package/dist/server/image-optimization.d.ts +54 -0
- package/dist/server/image-optimization.js +118 -9
- package/dist/server/isr-cache.d.ts +10 -0
- package/dist/server/isr-cache.js +43 -8
- package/dist/server/metadata-route-response.js +9 -8
- package/dist/server/middleware-matcher-pattern.js +8 -4
- package/dist/server/middleware-matcher.d.ts +2 -0
- package/dist/server/middleware-matcher.js +23 -2
- package/dist/server/middleware-response-headers.js +2 -0
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +33 -20
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +3 -1
- package/dist/server/multi-stage.d.ts +19 -0
- package/dist/server/navigation-planner.js +1 -1
- package/dist/server/node-response-signal.d.ts +16 -0
- package/dist/server/node-response-signal.js +26 -0
- package/dist/server/normalize-path.d.ts +0 -13
- package/dist/server/normalize-path.js +1 -34
- package/dist/server/open-redirect.d.ts +47 -0
- package/dist/server/open-redirect.js +74 -1
- package/dist/server/pages-api-route.d.ts +3 -2
- package/dist/server/pages-api-route.js +4 -3
- package/dist/server/pages-cache-tag.d.ts +12 -0
- package/dist/server/pages-cache-tag.js +19 -0
- package/dist/server/pages-client-assets.d.ts +2 -0
- package/dist/server/pages-data-route.d.ts +10 -0
- package/dist/server/pages-data-route.js +19 -2
- package/dist/server/pages-document-asset-props.d.ts +5 -1
- package/dist/server/pages-document-asset-props.js +13 -5
- package/dist/server/pages-document-splice.d.ts +19 -0
- package/dist/server/pages-document-splice.js +55 -0
- package/dist/server/pages-i18n.d.ts +12 -1
- package/dist/server/pages-i18n.js +18 -4
- package/dist/server/pages-node-compat.d.ts +16 -5
- package/dist/server/pages-node-compat.js +20 -12
- package/dist/server/pages-page-data.d.ts +32 -24
- package/dist/server/pages-page-data.js +50 -120
- package/dist/server/pages-page-handler.d.ts +0 -6
- package/dist/server/pages-page-handler.js +209 -130
- package/dist/server/pages-page-response.d.ts +12 -6
- package/dist/server/pages-page-response.js +41 -34
- package/dist/server/pages-request-pipeline.d.ts +10 -2
- package/dist/server/pages-request-pipeline.js +37 -18
- package/dist/server/pages-request-stage-entry.d.ts +6 -0
- package/dist/server/pages-request-stage-entry.js +79 -16
- package/dist/server/pages-response-stage-entry.js +4 -0
- package/dist/server/pages-revalidate.js +1 -1
- package/dist/server/pages-router-entry.js +4 -3
- package/dist/server/prerender-manifest.d.ts +3 -3
- package/dist/server/prerender-manifest.js +4 -3
- package/dist/server/prerender-work-unit-setup.js +4 -0
- package/dist/server/prod-server.d.ts +20 -7
- package/dist/server/prod-server.js +343 -129
- package/dist/server/proper-error.d.ts +4 -0
- package/dist/server/proper-error.js +31 -0
- package/dist/server/request-pipeline.d.ts +24 -9
- package/dist/server/request-pipeline.js +24 -9
- package/dist/server/response-compression.d.ts +43 -0
- package/dist/server/response-compression.js +111 -0
- package/dist/server/revalidation-request.d.ts +1 -0
- package/dist/server/revalidation-request.js +1 -1
- package/dist/server/rsc-stream-hints.js +31 -2
- package/dist/server/seed-cache.d.ts +1 -0
- package/dist/server/seed-cache.js +15 -11
- package/dist/server/server-reference-loader.d.ts +4 -0
- package/dist/server/server-reference-loader.js +29 -0
- package/dist/server/socket-error-backstop.d.ts +23 -1
- package/dist/server/socket-error-backstop.js +69 -17
- package/dist/server/static-file-signal.d.ts +15 -4
- package/dist/server/static-file-signal.js +46 -12
- package/dist/server/worker-image-optimization.d.ts +34 -0
- package/dist/server/worker-image-optimization.js +86 -0
- package/dist/server/worker-stages.d.ts +1 -1
- package/dist/server/worker-stages.js +2 -2
- package/dist/server/worker-utils.d.ts +8 -3
- package/dist/server/worker-utils.js +12 -7
- package/dist/shims/app-router-scroll.js +4 -1
- package/dist/shims/app-router-tree-context.d.ts +5 -0
- package/dist/shims/app-router-tree-context.js +27 -0
- package/dist/shims/cache-adapter-instantiate.d.ts +50 -0
- package/dist/shims/cache-adapter-instantiate.js +118 -0
- package/dist/shims/cache-callable-runtime.d.ts +6 -42
- package/dist/shims/cache-callable-runtime.js +65 -174
- package/dist/shims/cache-flight-arguments.d.ts +22 -0
- package/dist/shims/cache-flight-arguments.js +56 -0
- package/dist/shims/cache-handler.js +1 -9
- package/dist/shims/cache-request-state.d.ts +15 -0
- package/dist/shims/cache-request-state.js +31 -8
- package/dist/shims/cache-runtime.d.ts +12 -20
- package/dist/shims/cache-runtime.js +166 -225
- package/dist/shims/cache.d.ts +4 -4
- package/dist/shims/cache.js +44 -16
- package/dist/shims/cacheability-classification.d.ts +7 -0
- package/dist/shims/cdn-cache.d.ts +8 -0
- package/dist/shims/cdn-cache.js +17 -1
- package/dist/shims/disable-smooth-scroll.d.ts +3 -0
- package/dist/shims/disable-smooth-scroll.js +36 -0
- package/dist/shims/document-placeholders.d.ts +19 -0
- package/dist/shims/document-placeholders.js +45 -0
- package/dist/shims/document.js +21 -5
- package/dist/shims/dynamic-preload-chunks.d.ts +1 -0
- package/dist/shims/dynamic-preload-chunks.js +13 -9
- package/dist/shims/dynamic.d.ts +1 -1
- package/dist/shims/dynamic.js +60 -8
- package/dist/shims/error-boundary-navigation.d.ts +7 -0
- package/dist/shims/error-boundary-navigation.js +19 -1
- package/dist/shims/error-boundary.d.ts +10 -10
- package/dist/shims/error-boundary.js +26 -7
- package/dist/shims/fetch-cache-state.d.ts +66 -0
- package/dist/shims/fetch-cache-state.js +92 -0
- package/dist/shims/fetch-cache.d.ts +3 -61
- package/dist/shims/fetch-cache.js +161 -108
- package/dist/shims/form.js +1 -1
- package/dist/shims/head.d.ts +10 -6
- package/dist/shims/head.js +15 -13
- package/dist/shims/headers.d.ts +13 -0
- package/dist/shims/headers.js +47 -4
- package/dist/shims/image.js +2 -1
- package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -2
- package/dist/shims/internal/app-page-props-cache-key.js +24 -15
- package/dist/shims/internal/headers-state.d.ts +0 -1
- package/dist/shims/internal/work-store-scope.d.ts +5 -0
- package/dist/shims/internal/work-store-scope.js +24 -0
- package/dist/shims/metadata.js +3 -3
- package/dist/shims/navigation-errors.d.ts +6 -0
- package/dist/shims/navigation-errors.js +11 -1
- package/dist/shims/navigation.d.ts +7 -0
- package/dist/shims/navigation.js +45 -9
- package/dist/shims/request-context.d.ts +11 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/router.js +12 -20
- package/dist/shims/server.d.ts +16 -0
- package/dist/shims/server.js +24 -4
- package/dist/shims/thenable-params.d.ts +4 -0
- package/dist/shims/thenable-params.js +25 -3
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/shims/url-utils.d.ts +2 -0
- package/dist/shims/url-utils.js +3 -1
- package/dist/utils/client-runtime-metadata.js +1 -1
- package/dist/utils/hash.d.ts +7 -0
- package/dist/utils/hash.js +11 -1
- package/dist/utils/mdx-scan.d.ts +5 -0
- package/dist/utils/mdx-scan.js +8 -1
- package/dist/utils/package-name.d.ts +6 -0
- package/dist/utils/package-name.js +12 -1
- package/dist/utils/plugin-rsc-version.d.ts +4 -0
- package/dist/utils/plugin-rsc-version.js +15 -0
- package/dist/utils/prerender-output-paths.js +15 -4
- package/dist/utils/public-file-path.d.ts +10 -2
- package/dist/utils/public-file-path.js +13 -9
- package/dist/utils/public-routes.js +2 -2
- package/dist/utils/react-version.d.ts +3 -0
- package/dist/utils/react-version.js +1 -1
- package/dist/utils/regex-safety.d.ts +10 -0
- package/dist/utils/regex-safety.js +70 -18
- package/package.json +9 -5
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
1
|
+
import { isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
3
2
|
import { getRequestExecutionContext } from "./request-context.js";
|
|
4
3
|
import { getDataCacheHandler } from "./cache-handler.js";
|
|
5
4
|
import { encodeCacheTags } from "../utils/encode-cache-tag.js";
|
|
5
|
+
import { sha256Hex } from "../utils/hash.js";
|
|
6
6
|
import { traceAppFetch } from "../server/app-fetch-tracing.js";
|
|
7
|
+
import { addCollectedRequestTags, fallbackFetchCacheState, fetchCacheAls, getCurrentFetchSoftTags, getFetchCacheState, resetFallbackFetchCacheState, runWithDetachedFetchObservations } from "./fetch-cache-state.js";
|
|
7
8
|
import { isInsideAnyCacheScope, markDynamicUsage } from "./internal/headers-state.js";
|
|
8
9
|
import { getHeadersContext } from "./headers.js";
|
|
9
10
|
import { _hasPendingRevalidatedTag, _setRequestScopedCacheLife } from "./cache-request-state.js";
|
|
@@ -35,7 +36,7 @@ import { Buffer } from "node:buffer";
|
|
|
35
36
|
* All other headers ARE included in the cache key, matching Next.js behavior.
|
|
36
37
|
*/
|
|
37
38
|
const HEADER_BLOCKLIST = ["traceparent", "tracestate"];
|
|
38
|
-
const CACHE_KEY_PREFIX = "
|
|
39
|
+
const CACHE_KEY_PREFIX = "v8";
|
|
39
40
|
const MAX_CACHE_KEY_BODY_BYTES = 1048576;
|
|
40
41
|
const ONE_YEAR_SECONDS = 31536e3;
|
|
41
42
|
var BodyTooLargeForCacheKeyError = class extends Error {
|
|
@@ -76,6 +77,17 @@ function hasAuthHeaders(input, init) {
|
|
|
76
77
|
const headers = collectHeaders(input, init);
|
|
77
78
|
return AUTH_HEADERS.some((name) => name in headers);
|
|
78
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Workers' `cf.resolveOverride` sends the request to a different origin
|
|
82
|
+
* without changing the URL or headers, so it must be part of the fetch cache
|
|
83
|
+
* and dedupe keys. Other `cf` properties only tune Cloudflare's edge cache or
|
|
84
|
+
* optimize the same resource, so they stay out of the keys. Next.js has no
|
|
85
|
+
* equivalent because it never runs on Workers.
|
|
86
|
+
*/
|
|
87
|
+
function getResolveOverride(input, init) {
|
|
88
|
+
const initCf = init?.cf;
|
|
89
|
+
return (initCf !== void 0 ? initCf : input instanceof Request ? input.cf : void 0)?.resolveOverride ?? null;
|
|
90
|
+
}
|
|
79
91
|
const BYTE_HEX = Array.from({ length: 256 }, (_, value) => value.toString(16).padStart(2, "0"));
|
|
80
92
|
function encodeBodyBytes(bytes) {
|
|
81
93
|
let encoded = "bytes:";
|
|
@@ -143,6 +155,40 @@ function normalizeFetchMethod(method) {
|
|
|
143
155
|
const upperMethod = method.toUpperCase();
|
|
144
156
|
return NORMALIZED_FETCH_METHODS.has(upperMethod) ? upperMethod : method;
|
|
145
157
|
}
|
|
158
|
+
function getIntrinsic(prototype, key) {
|
|
159
|
+
const getter = Object.getOwnPropertyDescriptor(prototype, key)?.get;
|
|
160
|
+
if (!getter) throw new Error(`Missing intrinsic getter: ${String(key)}`);
|
|
161
|
+
return (target) => Reflect.apply(getter, target, []);
|
|
162
|
+
}
|
|
163
|
+
const typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
164
|
+
const getTypedArrayTag = getIntrinsic(typedArrayPrototype, Symbol.toStringTag);
|
|
165
|
+
const getTypedArrayBuffer = getIntrinsic(typedArrayPrototype, "buffer");
|
|
166
|
+
const getTypedArrayByteOffset = getIntrinsic(typedArrayPrototype, "byteOffset");
|
|
167
|
+
const getTypedArrayByteLength = getIntrinsic(typedArrayPrototype, "byteLength");
|
|
168
|
+
const getDataViewBuffer = getIntrinsic(DataView.prototype, "buffer");
|
|
169
|
+
const getDataViewByteOffset = getIntrinsic(DataView.prototype, "byteOffset");
|
|
170
|
+
const getDataViewByteLength = getIntrinsic(DataView.prototype, "byteLength");
|
|
171
|
+
const getArrayBufferByteLength = getIntrinsic(ArrayBuffer.prototype, "byteLength");
|
|
172
|
+
function isArrayBuffer(value) {
|
|
173
|
+
if (!(value instanceof ArrayBuffer)) return false;
|
|
174
|
+
try {
|
|
175
|
+
getArrayBufferByteLength(value);
|
|
176
|
+
return true;
|
|
177
|
+
} catch {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The bytes sent for a binary body chunk: the bytes an ArrayBuffer holds, or
|
|
183
|
+
* those a typed array or DataView covers. Undefined for any other chunk.
|
|
184
|
+
*/
|
|
185
|
+
function getBinaryChunkBytes(value) {
|
|
186
|
+
if (ArrayBuffer.isView(value)) {
|
|
187
|
+
if (getTypedArrayTag(value) !== void 0) return new Uint8Array(getTypedArrayBuffer(value), getTypedArrayByteOffset(value), getTypedArrayByteLength(value));
|
|
188
|
+
return new Uint8Array(getDataViewBuffer(value), getDataViewByteOffset(value), getDataViewByteLength(value));
|
|
189
|
+
}
|
|
190
|
+
if (isArrayBuffer(value)) return new Uint8Array(value);
|
|
191
|
+
}
|
|
146
192
|
async function readRequestBodyChunksWithinLimit(request, effectiveHeaders) {
|
|
147
193
|
const contentLengthHeader = effectiveHeaders.get("content-length");
|
|
148
194
|
if (contentLengthHeader) {
|
|
@@ -162,9 +208,11 @@ async function readRequestBodyChunksWithinLimit(request, effectiveHeaders) {
|
|
|
162
208
|
while (true) {
|
|
163
209
|
const { done, value } = await reader.read();
|
|
164
210
|
if (done) break;
|
|
165
|
-
|
|
211
|
+
const bytes = getBinaryChunkBytes(value);
|
|
212
|
+
if (!bytes) throw new SkipCacheKeyGenerationError();
|
|
213
|
+
totalBodyBytes += bytes.byteLength;
|
|
166
214
|
if (totalBodyBytes > MAX_CACHE_KEY_BODY_BYTES) throw new BodyTooLargeForCacheKeyError();
|
|
167
|
-
chunks.push(
|
|
215
|
+
chunks.push(bytes);
|
|
168
216
|
}
|
|
169
217
|
} catch (err) {
|
|
170
218
|
reader.cancel().catch(() => {});
|
|
@@ -175,6 +223,61 @@ async function readRequestBodyChunksWithinLimit(request, effectiveHeaders) {
|
|
|
175
223
|
contentType
|
|
176
224
|
};
|
|
177
225
|
}
|
|
226
|
+
const builtBodyRequests = /* @__PURE__ */ new WeakSet();
|
|
227
|
+
/**
|
|
228
|
+
* Whether serializeBody keys this init body type itself. Only genuine
|
|
229
|
+
* instances count, so an array (which has keys()) or a Response (which has
|
|
230
|
+
* arrayBuffer()) is sent however the runtime sends it.
|
|
231
|
+
*/
|
|
232
|
+
function isKeyableInitBody(body) {
|
|
233
|
+
return typeof body === "string" || body instanceof ArrayBuffer || ArrayBuffer.isView(body) || body instanceof URLSearchParams || body instanceof ReadableStream || body instanceof FormData || body instanceof Blob;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Copy a cacheable fetch's request when fetch is called, as fetch itself does.
|
|
237
|
+
* Its cache key is built, and it is sent, only after awaits. A URL, headers,
|
|
238
|
+
* body or `cf` the caller changes in the meantime must reach neither: the
|
|
239
|
+
* request would be sent with values its key doesn't hold, and its response
|
|
240
|
+
* cached for the values the key does hold. A stream body is read after the
|
|
241
|
+
* call, as fetch reads it, and sent as the bytes its key is built from.
|
|
242
|
+
*/
|
|
243
|
+
function snapshotFetchRequest(input, init) {
|
|
244
|
+
const snapshotInit = { ...init };
|
|
245
|
+
const headers = snapshotInit.headers !== void 0 ? snapshotInit.headers : input instanceof Request ? input.headers : void 0;
|
|
246
|
+
if (headers !== void 0) snapshotInit.headers = new Headers(headers);
|
|
247
|
+
const cf = snapshotInit.cf !== void 0 ? snapshotInit.cf : input instanceof Request ? input.cf : void 0;
|
|
248
|
+
if (cf !== null && typeof cf === "object") snapshotInit.cf = snapshotCf(cf);
|
|
249
|
+
if (snapshotInit.body !== void 0 && snapshotInit.body !== null) snapshotInit.body = snapshotBody(snapshotInit.body);
|
|
250
|
+
return {
|
|
251
|
+
input: input instanceof Request ? input : String(input),
|
|
252
|
+
init: snapshotInit
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function snapshotCf(cf) {
|
|
256
|
+
try {
|
|
257
|
+
return JSON.parse(JSON.stringify(cf));
|
|
258
|
+
} catch {
|
|
259
|
+
return cf;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function snapshotBody(body) {
|
|
263
|
+
const bytes = getBinaryChunkBytes(body);
|
|
264
|
+
if (bytes) return bytes.slice();
|
|
265
|
+
if (body instanceof URLSearchParams) return new URLSearchParams(body);
|
|
266
|
+
if (body instanceof FormData) {
|
|
267
|
+
const formData = new FormData();
|
|
268
|
+
for (const [name, value] of body) formData.append(name, typeof value === "string" ? value : snapshotBlob(value));
|
|
269
|
+
return formData;
|
|
270
|
+
}
|
|
271
|
+
if (body instanceof Blob) return snapshotBlob(body);
|
|
272
|
+
return body;
|
|
273
|
+
}
|
|
274
|
+
function snapshotBlob(blob) {
|
|
275
|
+
if (blob instanceof File) return new File([blob], blob.name, {
|
|
276
|
+
type: blob.type,
|
|
277
|
+
lastModified: blob.lastModified
|
|
278
|
+
});
|
|
279
|
+
return new Blob([blob], { type: blob.type });
|
|
280
|
+
}
|
|
178
281
|
/**
|
|
179
282
|
* Serialize request body into string chunks for cache key inclusion.
|
|
180
283
|
* Handles all body types: string, Uint8Array, ReadableStream, FormData, Blob,
|
|
@@ -200,8 +303,9 @@ async function serializeBody(input, init) {
|
|
|
200
303
|
pushBodyChunk(encodeBodyBytes(bytes), bytes.byteLength);
|
|
201
304
|
};
|
|
202
305
|
const getTotalBodyBytes = () => totalBodyBytes;
|
|
203
|
-
|
|
204
|
-
|
|
306
|
+
const directBodyBytes = getBinaryChunkBytes(init?.body);
|
|
307
|
+
if (init?.body && directBodyBytes) {
|
|
308
|
+
const bytes = directBodyBytes;
|
|
205
309
|
if (bytes.byteLength > MAX_CACHE_KEY_BODY_BYTES) throw new BodyTooLargeForCacheKeyError();
|
|
206
310
|
pushBodyBytes(bytes);
|
|
207
311
|
init._ogBody = init.body;
|
|
@@ -214,12 +318,16 @@ async function serializeBody(input, init) {
|
|
|
214
318
|
while (true) {
|
|
215
319
|
const { done, value } = await reader.read();
|
|
216
320
|
if (done) break;
|
|
217
|
-
const bytes = typeof value === "string" ? encoder.encode(value) : value;
|
|
321
|
+
const bytes = typeof value === "string" ? encoder.encode(value) : getBinaryChunkBytes(value);
|
|
322
|
+
if (!bytes) throw new SkipCacheKeyGenerationError();
|
|
218
323
|
totalBodyBytes += bytes.byteLength;
|
|
219
324
|
if (totalBodyBytes > MAX_CACHE_KEY_BODY_BYTES) throw new BodyTooLargeForCacheKeyError();
|
|
220
325
|
chunks.push(bytes);
|
|
221
326
|
}
|
|
222
|
-
|
|
327
|
+
const bytes = concatBodyBytes(chunks);
|
|
328
|
+
bodyChunks.push(encodeBodyBytes(bytes));
|
|
329
|
+
init._ogBody = bytes;
|
|
330
|
+
bodyForFetch.cancel().catch(() => {});
|
|
223
331
|
} catch (err) {
|
|
224
332
|
reader.cancel().catch(() => {});
|
|
225
333
|
if (err instanceof BodyTooLargeForCacheKeyError) throw err;
|
|
@@ -258,7 +366,8 @@ async function serializeBody(input, init) {
|
|
|
258
366
|
if (err instanceof BodyTooLargeForCacheKeyError) throw err;
|
|
259
367
|
throw new SkipCacheKeyGenerationError();
|
|
260
368
|
}
|
|
261
|
-
|
|
369
|
+
if (init) init._ogBody = concatBodyBytes(chunks);
|
|
370
|
+
const formContentType = builtBodyRequests.has(input) ? void 0 : getParsedFormContentType(contentType);
|
|
262
371
|
if (formContentType) try {
|
|
263
372
|
await serializeFormData(await new Request(input.url, {
|
|
264
373
|
method: input.method,
|
|
@@ -316,11 +425,10 @@ async function buildFetchCacheKey(input, init) {
|
|
|
316
425
|
init?.integrity ?? inputRequest?.integrity ?? "",
|
|
317
426
|
init?.cache ?? inputRequest?.cache ?? "default",
|
|
318
427
|
bodyChunks,
|
|
319
|
-
bodyMetadata
|
|
428
|
+
bodyMetadata,
|
|
429
|
+
getResolveOverride(input, init)
|
|
320
430
|
]);
|
|
321
|
-
|
|
322
|
-
const hashBuffer = await crypto.subtle.digest("SHA-256", buffer);
|
|
323
|
-
return Array.prototype.map.call(new Uint8Array(hashBuffer), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
431
|
+
return sha256Hex(cacheString);
|
|
324
432
|
}
|
|
325
433
|
const _PENDING_KEY = Symbol.for("vinext.fetchCache.pendingRefetches");
|
|
326
434
|
const _gPending = globalThis;
|
|
@@ -333,54 +441,17 @@ function _resetPendingRefetches() {
|
|
|
333
441
|
const _ORIG_FETCH_KEY = Symbol.for("vinext.fetchCache.originalFetch");
|
|
334
442
|
const _gFetch = globalThis;
|
|
335
443
|
const originalFetch = _gFetch[_ORIG_FETCH_KEY] ??= globalThis.fetch;
|
|
336
|
-
const _FALLBACK_KEY = Symbol.for("vinext.fetchCache.fallback");
|
|
337
|
-
const _g = globalThis;
|
|
338
|
-
const _als = getOrCreateAls("vinext.fetchCache.als");
|
|
339
444
|
const _noop = () => {};
|
|
340
445
|
let _responseBodyRegistry;
|
|
341
446
|
if (globalThis.FinalizationRegistry) _responseBodyRegistry = new FinalizationRegistry((weakRef) => {
|
|
342
447
|
const stream = weakRef.deref();
|
|
343
448
|
if (stream && !stream.locked) stream.cancel("Response object has been garbage collected").then(_noop, _noop);
|
|
344
449
|
});
|
|
345
|
-
const _fallbackState = _g[_FALLBACK_KEY] ??= {
|
|
346
|
-
cacheableFetchUrls: /* @__PURE__ */ new Set(),
|
|
347
|
-
currentRequestTags: [],
|
|
348
|
-
currentFetchSoftTags: [],
|
|
349
|
-
currentFetchCacheMode: null,
|
|
350
|
-
currentFetchRevalidate: null,
|
|
351
|
-
currentForceDynamicFetchDefault: false,
|
|
352
|
-
dynamicFetchUrls: /* @__PURE__ */ new Set(),
|
|
353
|
-
refreshStaleFetchesInForeground: false,
|
|
354
|
-
isFetchDedupeActive: false,
|
|
355
|
-
currentFetchDedupeEntries: /* @__PURE__ */ new Map(),
|
|
356
|
-
nextFetchId: 1
|
|
357
|
-
};
|
|
358
|
-
function _getState() {
|
|
359
|
-
if (isInsideUnifiedScope()) return getRequestContext();
|
|
360
|
-
return _als.getStore() ?? _fallbackState;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Reset the fallback state for a new request. Used by `withFetchCache()`
|
|
364
|
-
* in single-threaded contexts where ALS.run() isn't used.
|
|
365
|
-
*/
|
|
366
|
-
function _resetFallbackState(isFetchDedupeActive) {
|
|
367
|
-
_fallbackState.cacheableFetchUrls = /* @__PURE__ */ new Set();
|
|
368
|
-
_fallbackState.currentRequestTags = [];
|
|
369
|
-
_fallbackState.currentFetchSoftTags = [];
|
|
370
|
-
_fallbackState.currentFetchCacheMode = null;
|
|
371
|
-
_fallbackState.currentFetchRevalidate = null;
|
|
372
|
-
_fallbackState.currentForceDynamicFetchDefault = false;
|
|
373
|
-
_fallbackState.dynamicFetchUrls = /* @__PURE__ */ new Set();
|
|
374
|
-
_fallbackState.refreshStaleFetchesInForeground = false;
|
|
375
|
-
_fallbackState.isFetchDedupeActive = isFetchDedupeActive;
|
|
376
|
-
_fallbackState.currentFetchDedupeEntries = /* @__PURE__ */ new Map();
|
|
377
|
-
_fallbackState.nextFetchId = 1;
|
|
378
|
-
}
|
|
379
450
|
function getFetchObservationUrl(input) {
|
|
380
451
|
return typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
381
452
|
}
|
|
382
453
|
function addDynamicFetchObservation(input) {
|
|
383
|
-
|
|
454
|
+
getFetchCacheState().dynamicFetchUrls.add(getFetchObservationUrl(input));
|
|
384
455
|
}
|
|
385
456
|
function recordDynamicFetchObservation(input) {
|
|
386
457
|
if (isInsideAnyCacheScope()) return;
|
|
@@ -389,21 +460,21 @@ function recordDynamicFetchObservation(input) {
|
|
|
389
460
|
function markUncachedFetchForPageOutput(input) {
|
|
390
461
|
if (isInsideAnyCacheScope()) return;
|
|
391
462
|
addDynamicFetchObservation(input);
|
|
392
|
-
if (getHeadersContext()?.forceStatic !== true)
|
|
463
|
+
if (getHeadersContext()?.forceStatic !== true) getFetchCacheState().currentFetchRevalidate = 0;
|
|
393
464
|
markDynamicUsage();
|
|
394
465
|
}
|
|
395
466
|
function recordCacheableFetchObservation(input) {
|
|
396
|
-
|
|
467
|
+
getFetchCacheState().cacheableFetchUrls.add(getFetchObservationUrl(input));
|
|
397
468
|
}
|
|
398
469
|
function recordFiniteFetchRevalidate(revalidateSeconds) {
|
|
399
470
|
if (Number.isFinite(revalidateSeconds) && revalidateSeconds > 0) _setRequestScopedCacheLife({ revalidate: revalidateSeconds });
|
|
400
471
|
}
|
|
401
472
|
function lowerCurrentFetchRevalidate(revalidateSeconds) {
|
|
402
|
-
const state =
|
|
473
|
+
const state = getFetchCacheState();
|
|
403
474
|
if (state.currentFetchRevalidate === null || revalidateSeconds < state.currentFetchRevalidate) state.currentFetchRevalidate = revalidateSeconds;
|
|
404
475
|
}
|
|
405
476
|
function shouldRefreshStaleFetchInForeground() {
|
|
406
|
-
return
|
|
477
|
+
return getFetchCacheState().refreshStaleFetchesInForeground;
|
|
407
478
|
}
|
|
408
479
|
async function buildFetchCacheValue(response, tags, revalidateSeconds, options) {
|
|
409
480
|
if (response.status !== 200) return null;
|
|
@@ -450,13 +521,13 @@ async function lowerFetchCacheRevalidateIfNeeded(handler, cacheKey, cachedValue,
|
|
|
450
521
|
});
|
|
451
522
|
}
|
|
452
523
|
function peekCacheableFetchObservations() {
|
|
453
|
-
return [...
|
|
524
|
+
return [...getFetchCacheState().cacheableFetchUrls].sort();
|
|
454
525
|
}
|
|
455
526
|
function peekDynamicFetchObservations() {
|
|
456
|
-
return [...
|
|
527
|
+
return [...getFetchCacheState().dynamicFetchUrls].sort();
|
|
457
528
|
}
|
|
458
529
|
function consumeDynamicFetchObservations() {
|
|
459
|
-
const state =
|
|
530
|
+
const state = getFetchCacheState();
|
|
460
531
|
const observed = [...state.dynamicFetchUrls].sort();
|
|
461
532
|
state.dynamicFetchUrls = /* @__PURE__ */ new Set();
|
|
462
533
|
return observed;
|
|
@@ -467,24 +538,7 @@ function consumeDynamicFetchObservations() {
|
|
|
467
538
|
* fetch tags used during rendering.
|
|
468
539
|
*/
|
|
469
540
|
function getCollectedFetchTags() {
|
|
470
|
-
return [...
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Append cache tags to the current request's collected tags.
|
|
474
|
-
*
|
|
475
|
-
* Mirrors Next.js's `propagateCacheLifeAndTagsToRevalidateStore`: tags declared
|
|
476
|
-
* inside a `"use cache"` function (via `cacheTag()`, persisted on the data cache
|
|
477
|
-
* entry) must also bubble up to the surrounding page / route-handler ISR entry
|
|
478
|
-
* so `revalidateTag()` / `revalidatePath()` can evict the rendered output, not
|
|
479
|
-
* just the inner data cache entry. Without this, a cached `"use cache"` result
|
|
480
|
-
* keeps being served from a stale page/route entry after its tag is revalidated
|
|
481
|
-
* (issue #1453). Tags are already encoded by the caller; deduped to match the
|
|
482
|
-
* tagged-fetch path. A no-op for empty input.
|
|
483
|
-
*/
|
|
484
|
-
function addCollectedRequestTags(tags) {
|
|
485
|
-
if (tags.length === 0) return;
|
|
486
|
-
const reqTags = _getState().currentRequestTags;
|
|
487
|
-
for (const tag of tags) if (!reqTags.includes(tag)) reqTags.push(tag);
|
|
541
|
+
return [...getFetchCacheState().currentRequestTags];
|
|
488
542
|
}
|
|
489
543
|
/**
|
|
490
544
|
* Set path-derived implicit tags for fetch cache reads in the current render.
|
|
@@ -494,29 +548,19 @@ function addCollectedRequestTags(tags) {
|
|
|
494
548
|
* affected route, without permanently coupling a shared fetch entry to one path.
|
|
495
549
|
*/
|
|
496
550
|
function setCurrentFetchSoftTags(tags) {
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Read the path-derived soft tags for the current render.
|
|
501
|
-
*
|
|
502
|
-
* Used by the "use cache" runtime to pass soft tags to the cache handler
|
|
503
|
-
* so that `revalidatePath()` invalidates "use cache" entries during the
|
|
504
|
-
* affected route's next request, even when the entry carries no hard tags.
|
|
505
|
-
*/
|
|
506
|
-
function getCurrentFetchSoftTags() {
|
|
507
|
-
return _getState().currentFetchSoftTags;
|
|
551
|
+
getFetchCacheState().currentFetchSoftTags = [...tags];
|
|
508
552
|
}
|
|
509
553
|
function setCurrentFetchCacheMode(mode) {
|
|
510
|
-
|
|
554
|
+
getFetchCacheState().currentFetchCacheMode = mode;
|
|
511
555
|
}
|
|
512
556
|
function setCurrentFetchRevalidate(revalidate) {
|
|
513
|
-
|
|
557
|
+
getFetchCacheState().currentFetchRevalidate = revalidate;
|
|
514
558
|
}
|
|
515
559
|
function setCurrentForceDynamicFetchDefault(enabled) {
|
|
516
|
-
|
|
560
|
+
getFetchCacheState().currentForceDynamicFetchDefault = enabled;
|
|
517
561
|
}
|
|
518
562
|
function setRefreshStaleFetchesInForeground(enabled) {
|
|
519
|
-
|
|
563
|
+
getFetchCacheState().refreshStaleFetchesInForeground = enabled;
|
|
520
564
|
}
|
|
521
565
|
function isNoStoreFetch(cacheDirective, nextOpts) {
|
|
522
566
|
return cacheDirective === "no-store" || cacheDirective === "no-cache" || nextOpts?.revalidate === 0;
|
|
@@ -552,7 +596,7 @@ function getFetchCacheDirective(input, init) {
|
|
|
552
596
|
if (!(input instanceof Request) || input.cache === "default") return;
|
|
553
597
|
return input.cache;
|
|
554
598
|
}
|
|
555
|
-
function buildFetchDedupeKey(request) {
|
|
599
|
+
function buildFetchDedupeKey(request, resolveOverride) {
|
|
556
600
|
const filteredHeaders = Array.from(request.headers.entries()).filter(([key]) => !HEADER_BLOCKLIST.includes(key.toLowerCase()));
|
|
557
601
|
return JSON.stringify([
|
|
558
602
|
request.method,
|
|
@@ -562,7 +606,8 @@ function buildFetchDedupeKey(request) {
|
|
|
562
606
|
request.credentials,
|
|
563
607
|
request.referrer,
|
|
564
608
|
request.referrerPolicy,
|
|
565
|
-
request.integrity
|
|
609
|
+
request.integrity,
|
|
610
|
+
resolveOverride
|
|
566
611
|
]);
|
|
567
612
|
}
|
|
568
613
|
function createFetchDedupeCandidate(input, init) {
|
|
@@ -574,7 +619,7 @@ function createFetchDedupeCandidate(input, init) {
|
|
|
574
619
|
if (request.method !== "GET" && request.method !== "HEAD" || request.keepalive) return null;
|
|
575
620
|
return {
|
|
576
621
|
url: request.url,
|
|
577
|
-
key: buildFetchDedupeKey(request)
|
|
622
|
+
key: buildFetchDedupeKey(request, getResolveOverride(input, init))
|
|
578
623
|
};
|
|
579
624
|
}
|
|
580
625
|
function buildDedupeClone(body, source) {
|
|
@@ -612,7 +657,7 @@ function buildCachedFetchResponse(data, input) {
|
|
|
612
657
|
return response;
|
|
613
658
|
}
|
|
614
659
|
function dedupeFetch(input, init) {
|
|
615
|
-
const state =
|
|
660
|
+
const state = getFetchCacheState();
|
|
616
661
|
if (!state.isFetchDedupeActive) return originalFetch(input, init);
|
|
617
662
|
const candidate = createFetchDedupeCandidate(input, init);
|
|
618
663
|
if (!candidate) return originalFetch(input, init);
|
|
@@ -661,8 +706,8 @@ function dedupeFetch(input, init) {
|
|
|
661
706
|
function createPatchedFetch() {
|
|
662
707
|
const patchedFetch = async function patchedFetch(input, init, span) {
|
|
663
708
|
const nextOpts = init?.next;
|
|
664
|
-
const state =
|
|
665
|
-
const fetchIdx = isInsideUnifiedScope() ||
|
|
709
|
+
const state = getFetchCacheState();
|
|
710
|
+
const fetchIdx = isInsideUnifiedScope() || fetchCacheAls.getStore() !== void 0 || fallbackFetchCacheState.isFetchDedupeActive ? (state.nextFetchId ?? 1) + 1 : void 0;
|
|
666
711
|
if (fetchIdx !== void 0) state.nextFetchId = fetchIdx;
|
|
667
712
|
const recordFetchOutcome = (response, cacheStatus, cacheReason) => {
|
|
668
713
|
if (fetchIdx !== void 0) span?.setAttributes({
|
|
@@ -695,7 +740,7 @@ function createPatchedFetch() {
|
|
|
695
740
|
else if (nextOpts?.revalidate === false) revalidateSeconds = ONE_YEAR_SECONDS;
|
|
696
741
|
else if (typeof nextOpts?.revalidate === "number" && nextOpts.revalidate > 0) revalidateSeconds = nextOpts.revalidate;
|
|
697
742
|
else if (tags.length > 0) {
|
|
698
|
-
const routeRevalidate =
|
|
743
|
+
const routeRevalidate = getFetchCacheState().currentFetchRevalidate;
|
|
699
744
|
if (routeRevalidate === 0) {
|
|
700
745
|
const cleanInit = stripNextFromInit(init, cacheDirective);
|
|
701
746
|
markUncachedFetchForPageOutput(input);
|
|
@@ -713,12 +758,19 @@ function createPatchedFetch() {
|
|
|
713
758
|
lowerCurrentFetchRevalidate(nextOpts.revalidate);
|
|
714
759
|
recordFiniteFetchRevalidate(nextOpts.revalidate);
|
|
715
760
|
}
|
|
716
|
-
const reqTags =
|
|
761
|
+
const reqTags = getFetchCacheState().currentRequestTags;
|
|
717
762
|
if (tags.length > 0) {
|
|
718
763
|
for (const tag of tags) if (!reqTags.includes(tag)) reqTags.push(tag);
|
|
719
764
|
}
|
|
720
|
-
const softTags =
|
|
721
|
-
let fetchInit
|
|
765
|
+
const softTags = getFetchCacheState().currentFetchSoftTags;
|
|
766
|
+
let fetchInit;
|
|
767
|
+
({input, init: fetchInit} = snapshotFetchRequest(input, stripNextFromInit(init, cacheDirective)));
|
|
768
|
+
const initBody = fetchInit.body;
|
|
769
|
+
if (initBody !== void 0 && initBody !== null && !isKeyableInitBody(initBody)) {
|
|
770
|
+
input = new Request(input, fetchInit);
|
|
771
|
+
builtBodyRequests.add(input);
|
|
772
|
+
fetchInit = {};
|
|
773
|
+
}
|
|
722
774
|
let cacheKey;
|
|
723
775
|
try {
|
|
724
776
|
cacheKey = await buildFetchCacheKey(input, fetchInit);
|
|
@@ -810,6 +862,7 @@ function stripNextFromInit(init, cacheOverride) {
|
|
|
810
862
|
return Object.keys(rest).length > 0 ? rest : void 0;
|
|
811
863
|
}
|
|
812
864
|
const _PATCH_KEY = Symbol.for("vinext.fetchCache.patchInstalled");
|
|
865
|
+
const _g = globalThis;
|
|
813
866
|
function _ensurePatchInstalled() {
|
|
814
867
|
if (_g[_PATCH_KEY]) return;
|
|
815
868
|
_g[_PATCH_KEY] = true;
|
|
@@ -828,9 +881,9 @@ function _ensurePatchInstalled() {
|
|
|
828
881
|
*/
|
|
829
882
|
function withFetchCache() {
|
|
830
883
|
_ensurePatchInstalled();
|
|
831
|
-
|
|
884
|
+
resetFallbackFetchCacheState(true);
|
|
832
885
|
return () => {
|
|
833
|
-
|
|
886
|
+
resetFallbackFetchCacheState(false);
|
|
834
887
|
};
|
|
835
888
|
}
|
|
836
889
|
/**
|
|
@@ -850,7 +903,7 @@ async function runWithFetchCache(fn) {
|
|
|
850
903
|
uCtx.currentFetchDedupeEntries = /* @__PURE__ */ new Map();
|
|
851
904
|
uCtx.nextFetchId = 1;
|
|
852
905
|
}, fn);
|
|
853
|
-
return
|
|
906
|
+
return fetchCacheAls.run({
|
|
854
907
|
cacheableFetchUrls: /* @__PURE__ */ new Set(),
|
|
855
908
|
currentRequestTags: [],
|
|
856
909
|
currentFetchSoftTags: [],
|
|
@@ -866,13 +919,13 @@ async function runWithFetchCache(fn) {
|
|
|
866
919
|
}
|
|
867
920
|
function runWithFetchDedupe(fn) {
|
|
868
921
|
_ensurePatchInstalled();
|
|
869
|
-
const state =
|
|
922
|
+
const state = getFetchCacheState();
|
|
870
923
|
if (state.isFetchDedupeActive) return fn();
|
|
871
924
|
if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((uCtx) => {
|
|
872
925
|
uCtx.isFetchDedupeActive = true;
|
|
873
926
|
uCtx.currentFetchDedupeEntries = /* @__PURE__ */ new Map();
|
|
874
927
|
}, fn);
|
|
875
|
-
return
|
|
928
|
+
return fetchCacheAls.run({
|
|
876
929
|
...state,
|
|
877
930
|
isFetchDedupeActive: true,
|
|
878
931
|
currentFetchDedupeEntries: /* @__PURE__ */ new Map()
|
|
@@ -897,4 +950,4 @@ function getOriginalFetch() {
|
|
|
897
950
|
return originalFetch;
|
|
898
951
|
}
|
|
899
952
|
//#endregion
|
|
900
|
-
export { _resetPendingRefetches, addCollectedRequestTags, consumeDynamicFetchObservations, ensureFetchPatch, getCollectedFetchTags, getCurrentFetchSoftTags, getOriginalFetch, peekCacheableFetchObservations, peekDynamicFetchObservations, runWithFetchCache, runWithFetchDedupe, setCurrentFetchCacheMode, setCurrentFetchRevalidate, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault, setRefreshStaleFetchesInForeground, withFetchCache };
|
|
953
|
+
export { _resetPendingRefetches, addCollectedRequestTags, consumeDynamicFetchObservations, ensureFetchPatch, getCollectedFetchTags, getCurrentFetchSoftTags, getOriginalFetch, peekCacheableFetchObservations, peekDynamicFetchObservations, runWithDetachedFetchObservations, runWithFetchCache, runWithFetchDedupe, setCurrentFetchCacheMode, setCurrentFetchRevalidate, setCurrentFetchSoftTags, setCurrentForceDynamicFetchDefault, setRefreshStaleFetchesInForeground, withFetchCache };
|
package/dist/shims/form.js
CHANGED
|
@@ -4,9 +4,9 @@ import { VINEXT_MOUNTED_SLOTS_HEADER } from "../server/app-rsc-vary.js";
|
|
|
4
4
|
import "../server/headers.js";
|
|
5
5
|
import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
6
6
|
import { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "../server/app-rsc-render-mode.js";
|
|
7
|
+
import { withBasePath } from "./url-utils.js";
|
|
7
8
|
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
8
9
|
import "../server/app-elements.js";
|
|
9
|
-
import { withBasePath } from "./url-utils.js";
|
|
10
10
|
import { createRscRequestHeaders, createRscRequestUrl } from "../server/app-rsc-cache-busting.js";
|
|
11
11
|
import { hasAppNavigationRuntime } from "../client/navigation-runtime.js";
|
|
12
12
|
import { getMountedSlotsHeader, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, navigateClientSide, prefetchRscResponse } from "./navigation.js";
|
package/dist/shims/head.d.ts
CHANGED
|
@@ -46,13 +46,17 @@ export declare function isSafeAttrName(name: string): boolean;
|
|
|
46
46
|
export declare function escapeAttr(s: string): string;
|
|
47
47
|
/**
|
|
48
48
|
* Escape content that will be placed inside a raw <script> or <style> tag
|
|
49
|
-
* during SSR
|
|
50
|
-
* of the block regardless of JavaScript string context, so any occurrence
|
|
51
|
-
* of `</` followed by the tag name must be escaped.
|
|
49
|
+
* during SSR, so nothing in the content can move where the element ends.
|
|
52
50
|
*
|
|
53
|
-
*
|
|
54
|
-
* and
|
|
55
|
-
*
|
|
51
|
+
* For scripts we mirror React Fizz's escaping of script children: `<script`
|
|
52
|
+
* and `</script` (case-insensitive) become `<\u0073cript` and `</\u0073cript`
|
|
53
|
+
* (`\u0053` for an uppercase `S`). The escape is equivalent in JS strings,
|
|
54
|
+
* regexes, template literals, comments and identifiers. Escaping only the
|
|
55
|
+
* closing tag is not enough: `<!--<script>` puts the tokenizer in the
|
|
56
|
+
* double-escaped script state, where the real `</script>` no longer closes it.
|
|
57
|
+
*
|
|
58
|
+
* For styles we replace `</style` with `<\/style`, which is harmless in CSS
|
|
59
|
+
* string context but prevents the HTML parser from seeing a closing tag.
|
|
56
60
|
*/
|
|
57
61
|
export declare function escapeInlineContent(content: string, tag: string): string;
|
|
58
62
|
export declare function _applyHeadPropsToElement(domEl: HeadDOMElement, props: Record<string, unknown>): void;
|
package/dist/shims/head.js
CHANGED
|
@@ -105,10 +105,8 @@ const SELF_CLOSING_HEAD_TAGS = /* @__PURE__ */ new Set([
|
|
|
105
105
|
]);
|
|
106
106
|
/** Tags whose content is raw text — closing-tag sequences must be escaped during SSR. */
|
|
107
107
|
const RAW_CONTENT_TAGS = /* @__PURE__ */ new Set(["script", "style"]);
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
style: /<\/(style)/gi
|
|
111
|
-
};
|
|
108
|
+
const INLINE_SCRIPT_TAG_RE = /(<\/|<)(s)(cript)/gi;
|
|
109
|
+
const INLINE_STYLE_CLOSE_TAG_RE = /<\/(style)/gi;
|
|
112
110
|
function warnDisallowedHeadTag(tag) {
|
|
113
111
|
if (process.env.NODE_ENV !== "production") console.warn(`[vinext] <Head> ignoring disallowed tag <${tag}>. Only ${ALLOWED_HEAD_TAGS_LIST} are allowed.`);
|
|
114
112
|
}
|
|
@@ -244,18 +242,22 @@ function escapeAttr(s) {
|
|
|
244
242
|
}
|
|
245
243
|
/**
|
|
246
244
|
* Escape content that will be placed inside a raw <script> or <style> tag
|
|
247
|
-
* during SSR
|
|
248
|
-
*
|
|
249
|
-
*
|
|
245
|
+
* during SSR, so nothing in the content can move where the element ends.
|
|
246
|
+
*
|
|
247
|
+
* For scripts we mirror React Fizz's escaping of script children: `<script`
|
|
248
|
+
* and `<\/script` (case-insensitive) become `<\u0073cript` and `</\u0073cript`
|
|
249
|
+
* (`\u0053` for an uppercase `S`). The escape is equivalent in JS strings,
|
|
250
|
+
* regexes, template literals, comments and identifiers. Escaping only the
|
|
251
|
+
* closing tag is not enough: `<!--<script>` puts the tokenizer in the
|
|
252
|
+
* double-escaped script state, where the real `<\/script>` no longer closes it.
|
|
250
253
|
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
* context but prevents the HTML parser from seeing a closing tag.
|
|
254
|
+
* For styles we replace `</style` with `<\/style`, which is harmless in CSS
|
|
255
|
+
* string context but prevents the HTML parser from seeing a closing tag.
|
|
254
256
|
*/
|
|
255
257
|
function escapeInlineContent(content, tag) {
|
|
256
|
-
|
|
257
|
-
if (
|
|
258
|
-
return content
|
|
258
|
+
if (tag === "script") return content.replace(INLINE_SCRIPT_TAG_RE, (_match, prefix, s, suffix) => `${prefix}${s === "s" ? "\\u0073" : "\\u0053"}${suffix}`);
|
|
259
|
+
if (tag === "style") return content.replace(INLINE_STYLE_CLOSE_TAG_RE, "<\\/$1");
|
|
260
|
+
return content;
|
|
259
261
|
}
|
|
260
262
|
function getDangerouslySetInnerHTML(value) {
|
|
261
263
|
if (typeof value !== "object" || value === null) return void 0;
|
package/dist/shims/headers.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RenderRequestApiKind } from "../server/cache-proof.js";
|
|
2
|
+
import { CacheLifeConfig } from "./cache-request-state.js";
|
|
2
3
|
import { ConnectionProbeResult, HeadersAccessPhase, RenderDynamicLatch, VinextHeadersShimState, createRenderDynamicLatch, getHeadersAccessPhase, isInsideAnyCacheScope, isRenderDynamicLatched, markDynamicUsage, markRenderRequestApiUsage, onRenderDynamicLatched, throwIfInsideCacheScope, throwIfStaticGenerationAccessError } from "./internal/headers-state.js";
|
|
3
4
|
import { ReadonlyRequestCookies } from "@vinext/types/next/upstream/dist/server/web/spec-extension/adapters/request-cookies";
|
|
4
5
|
import { ResponseCookie } from "@vinext/types/next/upstream/dist/compiled/@edge-runtime/cookies/index";
|
|
@@ -27,6 +28,18 @@ export declare function runWithIsolatedDynamicUsage<T>(fn: () => T | Promise<T>)
|
|
|
27
28
|
result: T;
|
|
28
29
|
dynamicDetected: boolean;
|
|
29
30
|
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Run a pre-render probe without letting its dynamic API usage classify the
|
|
33
|
+
* request. Next.js has no probe: only the render decides whether a page is
|
|
34
|
+
* dynamic, and the render runs the probed layouts and page again. Returns the
|
|
35
|
+
* probe's own usage and cacheLife for a caller whose probe response replaces
|
|
36
|
+
* the render.
|
|
37
|
+
*/
|
|
38
|
+
export declare function runWithDetachedDynamicUsage<T>(fn: () => T | Promise<T>): Promise<{
|
|
39
|
+
result: T;
|
|
40
|
+
dynamicDetected: boolean;
|
|
41
|
+
cacheLife: CacheLifeConfig | null;
|
|
42
|
+
}>;
|
|
30
43
|
export declare function runWithConnectionProbe<T>(fn: () => T | Promise<T>): Promise<ConnectionProbeResult<T>>;
|
|
31
44
|
export declare function suspendConnectionProbe(): Promise<never> | null;
|
|
32
45
|
export declare function peekRenderRequestApiUsage(): RenderRequestApiKind[];
|