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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { isNavigationSignalError } from "../utils/navigation-signal.js";
|
|
3
3
|
import { decodeRedirectError, isRedirectError } from "./navigation-errors.js";
|
|
4
4
|
import "./navigation-server.js";
|
|
5
|
-
import { useErrorBoundaryPathname, useErrorBoundaryRouter } from "./error-boundary-navigation.js";
|
|
5
|
+
import { isRedirectToCurrentUrl, useErrorBoundaryPathname, useErrorBoundaryRouter } from "./error-boundary-navigation.js";
|
|
6
6
|
import DefaultGlobalError from "./default-global-error.js";
|
|
7
7
|
import { handleAppNavigationFailure } from "../client/app-nav-failure-handler.js";
|
|
8
8
|
import { VINEXT_DEV_ERROR_RECOVERY_EVENT } from "../utils/dev-error-recovery-event.js";
|
|
@@ -43,9 +43,13 @@ function removeDevErrorRecoveryListener(listener) {
|
|
|
43
43
|
if (typeof window === "undefined") return;
|
|
44
44
|
window.removeEventListener(VINEXT_DEV_ERROR_RECOVERY_EVENT, listener);
|
|
45
45
|
}
|
|
46
|
-
function HandleRedirect({ redirect, redirectType, reset }) {
|
|
46
|
+
function HandleRedirect({ redirect, redirectType, reset, stopsSelfRedirect }) {
|
|
47
47
|
const router = useErrorBoundaryRouter();
|
|
48
48
|
React.useEffect(() => {
|
|
49
|
+
if (stopsSelfRedirect && isRedirectToCurrentUrl(redirect)) {
|
|
50
|
+
console.error("[vinext] redirect() resolved to the current URL — not following it, to prevent an infinite loop.");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
49
53
|
React.startTransition(() => {
|
|
50
54
|
if (redirectType === "push") router.push(redirect);
|
|
51
55
|
else router.replace(redirect);
|
|
@@ -55,7 +59,8 @@ function HandleRedirect({ redirect, redirectType, reset }) {
|
|
|
55
59
|
redirect,
|
|
56
60
|
redirectType,
|
|
57
61
|
reset,
|
|
58
|
-
router
|
|
62
|
+
router,
|
|
63
|
+
stopsSelfRedirect
|
|
59
64
|
]);
|
|
60
65
|
return null;
|
|
61
66
|
}
|
|
@@ -64,7 +69,17 @@ var RedirectErrorBoundary = class extends React.Component {
|
|
|
64
69
|
super(props);
|
|
65
70
|
this.state = {
|
|
66
71
|
redirect: null,
|
|
67
|
-
redirectType: null
|
|
72
|
+
redirectType: null,
|
|
73
|
+
previousResetKey: normalizeBoundaryResetKey(props.resetKey)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
static getDerivedStateFromProps(props, state) {
|
|
77
|
+
const resetKey = normalizeBoundaryResetKey(props.resetKey);
|
|
78
|
+
if (resetKey === state.previousResetKey) return null;
|
|
79
|
+
return {
|
|
80
|
+
redirect: null,
|
|
81
|
+
redirectType: null,
|
|
82
|
+
previousResetKey: resetKey
|
|
68
83
|
};
|
|
69
84
|
}
|
|
70
85
|
static getDerivedStateFromError(error) {
|
|
@@ -90,13 +105,17 @@ var RedirectErrorBoundary = class extends React.Component {
|
|
|
90
105
|
reset: () => this.setState({
|
|
91
106
|
redirect: null,
|
|
92
107
|
redirectType: null
|
|
93
|
-
})
|
|
108
|
+
}),
|
|
109
|
+
stopsSelfRedirect: this.props.resetKey !== void 0
|
|
94
110
|
});
|
|
95
111
|
return this.props.children;
|
|
96
112
|
}
|
|
97
113
|
};
|
|
98
|
-
function RedirectBoundary({ children }) {
|
|
99
|
-
return /* @__PURE__ */ jsx(RedirectErrorBoundary, {
|
|
114
|
+
function RedirectBoundary({ children, resetKey }) {
|
|
115
|
+
return /* @__PURE__ */ jsx(RedirectErrorBoundary, {
|
|
116
|
+
resetKey,
|
|
117
|
+
children
|
|
118
|
+
});
|
|
100
119
|
}
|
|
101
120
|
/**
|
|
102
121
|
* Generic ErrorBoundary used to wrap route segments with error.tsx.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region src/shims/fetch-cache-state.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Request-scoped fetch cache state, kept apart from the fetch patching in
|
|
4
|
+
* fetch-cache.ts so modules that only read or update it, like next/cache,
|
|
5
|
+
* don't pull the patched fetch and its Node.js builtins into client graphs
|
|
6
|
+
* that import them.
|
|
7
|
+
*/
|
|
8
|
+
export type FetchDedupeEntry = {
|
|
9
|
+
key: string;
|
|
10
|
+
promise: Promise<Response>;
|
|
11
|
+
response: Response | null;
|
|
12
|
+
};
|
|
13
|
+
export type FetchCacheState = {
|
|
14
|
+
cacheableFetchUrls: Set<string>;
|
|
15
|
+
currentRequestTags: string[];
|
|
16
|
+
currentFetchSoftTags: string[];
|
|
17
|
+
currentFetchCacheMode: FetchCacheMode | null;
|
|
18
|
+
currentFetchRevalidate: number | null;
|
|
19
|
+
currentForceDynamicFetchDefault: boolean;
|
|
20
|
+
dynamicFetchUrls: Set<string>;
|
|
21
|
+
refreshStaleFetchesInForeground: boolean;
|
|
22
|
+
isFetchDedupeActive: boolean;
|
|
23
|
+
currentFetchDedupeEntries: Map<string, FetchDedupeEntry[]>;
|
|
24
|
+
nextFetchId: number;
|
|
25
|
+
};
|
|
26
|
+
export type FetchCacheMode = "auto" | "default-cache" | "default-no-store" | "force-cache" | "force-no-store" | "only-cache" | "only-no-store";
|
|
27
|
+
export declare const fetchCacheAls: import("node:async_hooks").AsyncLocalStorage<FetchCacheState>;
|
|
28
|
+
/**
|
|
29
|
+
* Process-wide state used only while the deprecated `withFetchCache()` is
|
|
30
|
+
* active, which marks it with `isFetchDedupeActive`.
|
|
31
|
+
*/
|
|
32
|
+
export declare const fallbackFetchCacheState: FetchCacheState;
|
|
33
|
+
export declare function getFetchCacheState(): FetchCacheState;
|
|
34
|
+
/**
|
|
35
|
+
* Reset the fallback state for a new request. Used by `withFetchCache()`
|
|
36
|
+
* in single-threaded contexts where ALS.run() isn't used.
|
|
37
|
+
*/
|
|
38
|
+
export declare function resetFallbackFetchCacheState(isFetchDedupeActive: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* Append cache tags to the current request's collected tags.
|
|
41
|
+
*
|
|
42
|
+
* Mirrors Next.js's `propagateCacheLifeAndTagsToRevalidateStore`: tags declared
|
|
43
|
+
* inside a `"use cache"` function (via `cacheTag()`, persisted on the data cache
|
|
44
|
+
* entry) must also bubble up to the surrounding page / route-handler ISR entry
|
|
45
|
+
* so `revalidateTag()` / `revalidatePath()` can evict the rendered output, not
|
|
46
|
+
* just the inner data cache entry. Without this, a cached `"use cache"` result
|
|
47
|
+
* keeps being served from a stale page/route entry after its tag is revalidated
|
|
48
|
+
* (issue #1453). Tags are already encoded by the caller; deduped to match the
|
|
49
|
+
* tagged-fetch path. A no-op for empty input.
|
|
50
|
+
*/
|
|
51
|
+
export declare function addCollectedRequestTags(tags: readonly string[]): void;
|
|
52
|
+
/**
|
|
53
|
+
* Read the path-derived soft tags for the current render.
|
|
54
|
+
*
|
|
55
|
+
* Used by the "use cache" runtime to pass soft tags to the cache handler
|
|
56
|
+
* so that `revalidatePath()` invalidates "use cache" entries during the
|
|
57
|
+
* affected route's next request, even when the entry carries no hard tags.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getCurrentFetchSoftTags(): string[];
|
|
60
|
+
/**
|
|
61
|
+
* Run `fn` with the request's fetch settings but its own record of the tags and
|
|
62
|
+
* URLs its fetches touch, so work done on the request's behalf after the fact
|
|
63
|
+
* (a background regeneration) leaves the request's response untouched.
|
|
64
|
+
*/
|
|
65
|
+
export declare function runWithDetachedFetchObservations<T>(fn: () => Promise<T>): Promise<T>;
|
|
66
|
+
//#endregion
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { getOrCreateAls } from "./internal/als-registry.js";
|
|
2
|
+
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
3
|
+
//#region src/shims/fetch-cache-state.ts
|
|
4
|
+
/**
|
|
5
|
+
* Request-scoped fetch cache state, kept apart from the fetch patching in
|
|
6
|
+
* fetch-cache.ts so modules that only read or update it, like next/cache,
|
|
7
|
+
* don't pull the patched fetch and its Node.js builtins into client graphs
|
|
8
|
+
* that import them.
|
|
9
|
+
*/
|
|
10
|
+
const _FALLBACK_KEY = Symbol.for("vinext.fetchCache.fallback");
|
|
11
|
+
const fetchCacheAls = getOrCreateAls("vinext.fetchCache.als");
|
|
12
|
+
function createFetchCacheState() {
|
|
13
|
+
return {
|
|
14
|
+
cacheableFetchUrls: /* @__PURE__ */ new Set(),
|
|
15
|
+
currentRequestTags: [],
|
|
16
|
+
currentFetchSoftTags: [],
|
|
17
|
+
currentFetchCacheMode: null,
|
|
18
|
+
currentFetchRevalidate: null,
|
|
19
|
+
currentForceDynamicFetchDefault: false,
|
|
20
|
+
dynamicFetchUrls: /* @__PURE__ */ new Set(),
|
|
21
|
+
refreshStaleFetchesInForeground: false,
|
|
22
|
+
isFetchDedupeActive: false,
|
|
23
|
+
currentFetchDedupeEntries: /* @__PURE__ */ new Map(),
|
|
24
|
+
nextFetchId: 1
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Process-wide state used only while the deprecated `withFetchCache()` is
|
|
29
|
+
* active, which marks it with `isFetchDedupeActive`.
|
|
30
|
+
*/
|
|
31
|
+
const fallbackFetchCacheState = globalThis[_FALLBACK_KEY] ??= createFetchCacheState();
|
|
32
|
+
function getFetchCacheState() {
|
|
33
|
+
if (isInsideUnifiedScope()) return getRequestContext();
|
|
34
|
+
const store = fetchCacheAls.getStore();
|
|
35
|
+
if (store) return store;
|
|
36
|
+
if (fallbackFetchCacheState.isFetchDedupeActive) return fallbackFetchCacheState;
|
|
37
|
+
return createFetchCacheState();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Reset the fallback state for a new request. Used by `withFetchCache()`
|
|
41
|
+
* in single-threaded contexts where ALS.run() isn't used.
|
|
42
|
+
*/
|
|
43
|
+
function resetFallbackFetchCacheState(isFetchDedupeActive) {
|
|
44
|
+
Object.assign(fallbackFetchCacheState, createFetchCacheState(), { isFetchDedupeActive });
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Append cache tags to the current request's collected tags.
|
|
48
|
+
*
|
|
49
|
+
* Mirrors Next.js's `propagateCacheLifeAndTagsToRevalidateStore`: tags declared
|
|
50
|
+
* inside a `"use cache"` function (via `cacheTag()`, persisted on the data cache
|
|
51
|
+
* entry) must also bubble up to the surrounding page / route-handler ISR entry
|
|
52
|
+
* so `revalidateTag()` / `revalidatePath()` can evict the rendered output, not
|
|
53
|
+
* just the inner data cache entry. Without this, a cached `"use cache"` result
|
|
54
|
+
* keeps being served from a stale page/route entry after its tag is revalidated
|
|
55
|
+
* (issue #1453). Tags are already encoded by the caller; deduped to match the
|
|
56
|
+
* tagged-fetch path. A no-op for empty input.
|
|
57
|
+
*/
|
|
58
|
+
function addCollectedRequestTags(tags) {
|
|
59
|
+
if (tags.length === 0) return;
|
|
60
|
+
const reqTags = getFetchCacheState().currentRequestTags;
|
|
61
|
+
for (const tag of tags) if (!reqTags.includes(tag)) reqTags.push(tag);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Read the path-derived soft tags for the current render.
|
|
65
|
+
*
|
|
66
|
+
* Used by the "use cache" runtime to pass soft tags to the cache handler
|
|
67
|
+
* so that `revalidatePath()` invalidates "use cache" entries during the
|
|
68
|
+
* affected route's next request, even when the entry carries no hard tags.
|
|
69
|
+
*/
|
|
70
|
+
function getCurrentFetchSoftTags() {
|
|
71
|
+
return getFetchCacheState().currentFetchSoftTags;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Run `fn` with the request's fetch settings but its own record of the tags and
|
|
75
|
+
* URLs its fetches touch, so work done on the request's behalf after the fact
|
|
76
|
+
* (a background regeneration) leaves the request's response untouched.
|
|
77
|
+
*/
|
|
78
|
+
function runWithDetachedFetchObservations(fn) {
|
|
79
|
+
if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((uCtx) => {
|
|
80
|
+
uCtx.cacheableFetchUrls = /* @__PURE__ */ new Set();
|
|
81
|
+
uCtx.currentRequestTags = [];
|
|
82
|
+
uCtx.dynamicFetchUrls = /* @__PURE__ */ new Set();
|
|
83
|
+
}, fn);
|
|
84
|
+
return fetchCacheAls.run({
|
|
85
|
+
...getFetchCacheState(),
|
|
86
|
+
cacheableFetchUrls: /* @__PURE__ */ new Set(),
|
|
87
|
+
currentRequestTags: [],
|
|
88
|
+
dynamicFetchUrls: /* @__PURE__ */ new Set()
|
|
89
|
+
}, fn);
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { addCollectedRequestTags, fallbackFetchCacheState, fetchCacheAls, getCurrentFetchSoftTags, getFetchCacheState, resetFallbackFetchCacheState, runWithDetachedFetchObservations };
|
|
@@ -1,33 +1,9 @@
|
|
|
1
|
+
import { FetchCacheMode, FetchCacheState, addCollectedRequestTags, getCurrentFetchSoftTags, runWithDetachedFetchObservations } from "./fetch-cache-state.js";
|
|
1
2
|
//#region src/shims/fetch-cache.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Extended fetch() with Next.js caching semantics.
|
|
4
|
-
*
|
|
5
|
-
* Patches `globalThis.fetch` during server rendering to support:
|
|
6
|
-
*
|
|
7
|
-
* fetch(url, { next: { revalidate: 60, tags: ['posts'] } })
|
|
8
|
-
* fetch(url, { cache: 'force-cache' })
|
|
9
|
-
* fetch(url, { cache: 'no-store' })
|
|
10
|
-
*
|
|
11
|
-
* Cached responses are stored via the pluggable CacheHandler, so
|
|
12
|
-
* revalidateTag() and revalidatePath() invalidate fetch-level caches.
|
|
13
|
-
*
|
|
14
|
-
* Usage (in server entry):
|
|
15
|
-
* import { withFetchCache, cleanupFetchCache } from './fetch-cache';
|
|
16
|
-
* const cleanup = withFetchCache();
|
|
17
|
-
* try { ... render ... } finally { cleanup(); }
|
|
18
|
-
*
|
|
19
|
-
* Or use the async helper:
|
|
20
|
-
* await runWithFetchCache(async () => { ... render ... });
|
|
21
|
-
*/
|
|
22
3
|
type NextFetchOptions = {
|
|
23
4
|
revalidate?: number | false;
|
|
24
5
|
tags?: string[];
|
|
25
6
|
};
|
|
26
|
-
type FetchDedupeEntry = {
|
|
27
|
-
key: string;
|
|
28
|
-
promise: Promise<Response>;
|
|
29
|
-
response: Response | null;
|
|
30
|
-
};
|
|
31
7
|
declare global {
|
|
32
8
|
interface RequestInit {
|
|
33
9
|
next?: NextFetchOptions;
|
|
@@ -35,20 +11,6 @@ declare global {
|
|
|
35
11
|
}
|
|
36
12
|
/** @internal Reset dedup state — exposed for test isolation only. */
|
|
37
13
|
export declare function _resetPendingRefetches(): void;
|
|
38
|
-
export type FetchCacheState = {
|
|
39
|
-
cacheableFetchUrls: Set<string>;
|
|
40
|
-
currentRequestTags: string[];
|
|
41
|
-
currentFetchSoftTags: string[];
|
|
42
|
-
currentFetchCacheMode: FetchCacheMode | null;
|
|
43
|
-
currentFetchRevalidate: number | null;
|
|
44
|
-
currentForceDynamicFetchDefault: boolean;
|
|
45
|
-
dynamicFetchUrls: Set<string>;
|
|
46
|
-
refreshStaleFetchesInForeground: boolean;
|
|
47
|
-
isFetchDedupeActive: boolean;
|
|
48
|
-
currentFetchDedupeEntries: Map<string, FetchDedupeEntry[]>;
|
|
49
|
-
nextFetchId: number;
|
|
50
|
-
};
|
|
51
|
-
export type FetchCacheMode = "auto" | "default-cache" | "default-no-store" | "force-cache" | "force-no-store" | "only-cache" | "only-no-store";
|
|
52
14
|
export declare function peekCacheableFetchObservations(): string[];
|
|
53
15
|
export declare function peekDynamicFetchObservations(): string[];
|
|
54
16
|
export declare function consumeDynamicFetchObservations(): string[];
|
|
@@ -58,19 +20,6 @@ export declare function consumeDynamicFetchObservations(): string[];
|
|
|
58
20
|
* fetch tags used during rendering.
|
|
59
21
|
*/
|
|
60
22
|
export declare function getCollectedFetchTags(): string[];
|
|
61
|
-
/**
|
|
62
|
-
* Append cache tags to the current request's collected tags.
|
|
63
|
-
*
|
|
64
|
-
* Mirrors Next.js's `propagateCacheLifeAndTagsToRevalidateStore`: tags declared
|
|
65
|
-
* inside a `"use cache"` function (via `cacheTag()`, persisted on the data cache
|
|
66
|
-
* entry) must also bubble up to the surrounding page / route-handler ISR entry
|
|
67
|
-
* so `revalidateTag()` / `revalidatePath()` can evict the rendered output, not
|
|
68
|
-
* just the inner data cache entry. Without this, a cached `"use cache"` result
|
|
69
|
-
* keeps being served from a stale page/route entry after its tag is revalidated
|
|
70
|
-
* (issue #1453). Tags are already encoded by the caller; deduped to match the
|
|
71
|
-
* tagged-fetch path. A no-op for empty input.
|
|
72
|
-
*/
|
|
73
|
-
export declare function addCollectedRequestTags(tags: readonly string[]): void;
|
|
74
23
|
/**
|
|
75
24
|
* Set path-derived implicit tags for fetch cache reads in the current render.
|
|
76
25
|
*
|
|
@@ -79,14 +28,6 @@ export declare function addCollectedRequestTags(tags: readonly string[]): void;
|
|
|
79
28
|
* affected route, without permanently coupling a shared fetch entry to one path.
|
|
80
29
|
*/
|
|
81
30
|
export declare function setCurrentFetchSoftTags(tags: string[]): void;
|
|
82
|
-
/**
|
|
83
|
-
* Read the path-derived soft tags for the current render.
|
|
84
|
-
*
|
|
85
|
-
* Used by the "use cache" runtime to pass soft tags to the cache handler
|
|
86
|
-
* so that `revalidatePath()` invalidates "use cache" entries during the
|
|
87
|
-
* affected route's next request, even when the entry carries no hard tags.
|
|
88
|
-
*/
|
|
89
|
-
export declare function getCurrentFetchSoftTags(): string[];
|
|
90
31
|
export declare function setCurrentFetchCacheMode(mode: FetchCacheMode | null): void;
|
|
91
32
|
export declare function setCurrentFetchRevalidate(revalidate: number | null): void;
|
|
92
33
|
export declare function setCurrentForceDynamicFetchDefault(enabled: boolean): void;
|
|
@@ -137,4 +78,5 @@ export declare function ensureFetchPatch(): void;
|
|
|
137
78
|
* Useful for internal code that should bypass caching.
|
|
138
79
|
*/
|
|
139
80
|
export declare function getOriginalFetch(): typeof globalThis.fetch;
|
|
140
|
-
//#endregion
|
|
81
|
+
//#endregion
|
|
82
|
+
export { type FetchCacheMode, type FetchCacheState, addCollectedRequestTags, getCurrentFetchSoftTags, runWithDetachedFetchObservations };
|