vinext 1.0.0 → 1.1.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 +72 -1
- package/THIRD_PARTY_LICENSES.md +26 -0
- package/dist/build/app-page-static-eligibility.d.ts +15 -0
- package/dist/build/app-page-static-eligibility.js +82 -0
- package/dist/build/lifecycle.js +10 -10
- package/dist/build/pages-client-assets-module.js +6 -1
- package/dist/build/precompress.js +1 -1
- package/dist/build/prerender-paths.js +6 -85
- package/dist/build/prerender.d.ts +8 -1
- package/dist/build/prerender.js +167 -46
- package/dist/build/run-prerender.js +4 -3
- package/dist/build/server-entry.d.ts +2 -0
- package/dist/build/server-entry.js +7 -1
- package/dist/build/server-manifest.d.ts +7 -0
- package/dist/build/server-manifest.js +11 -1
- package/dist/cache/cache-adapters-virtual.d.ts +7 -1
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/client/browser-globals.d.ts +4 -0
- package/dist/client/browser-globals.js +5 -0
- package/dist/client/navigation-runtime.d.ts +11 -1
- package/dist/client/navigation-runtime.js +3 -3
- package/dist/config/config-matchers.js +3 -1
- package/dist/config/dotenv.js +14 -3
- package/dist/config/next-config.d.ts +7 -0
- package/dist/config/next-config.js +18 -3
- package/dist/entries/app-rsc-entry.d.ts +2 -0
- package/dist/entries/app-rsc-entry.js +67 -45
- package/dist/index.d.ts +4 -1
- package/dist/index.js +200 -100
- package/dist/init-cloudflare.d.ts +1 -1
- package/dist/init-cloudflare.js +6 -6
- package/dist/init-platform.js +1 -1
- package/dist/init.js +4 -2
- 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/commonjs-syntax.d.ts +16 -0
- package/dist/plugins/commonjs-syntax.js +22 -0
- package/dist/plugins/fonts.d.ts +8 -11
- package/dist/plugins/fonts.js +71 -34
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +54 -3
- package/dist/plugins/import-meta-url.js +6 -6
- package/dist/plugins/og-asset-ownership.d.ts +2 -0
- package/dist/plugins/og-asset-ownership.js +24 -13
- package/dist/plugins/og-assets.d.ts +18 -0
- package/dist/plugins/og-assets.js +50 -8
- package/dist/plugins/og-harfbuzz.js +38 -27
- package/dist/plugins/optimize-imports.js +2 -1
- package/dist/plugins/require-context.d.ts +1 -0
- package/dist/plugins/require-context.js +28 -1
- package/dist/plugins/scan-build-css.d.ts +12 -0
- package/dist/plugins/scan-build-css.js +39 -0
- package/dist/plugins/strip-server-exports.d.ts +2 -0
- package/dist/plugins/strip-server-exports.js +3 -1
- package/dist/plugins/transform-result.d.ts +18 -0
- package/dist/plugins/transform-result.js +23 -2
- package/dist/plugins/typeof-window.d.ts +10 -0
- package/dist/plugins/typeof-window.js +33 -9
- package/dist/routing/app-route-graph.d.ts +0 -1
- package/dist/routing/app-route-graph.js +2 -4
- package/dist/routing/app-route-ids.d.ts +3 -0
- package/dist/routing/app-route-ids.js +6 -0
- package/dist/routing/file-matcher.d.ts +1 -0
- package/dist/routing/file-matcher.js +1 -1
- package/dist/server/api-handler.js +17 -7
- package/dist/server/app-bfcache-id.d.ts +1 -0
- package/dist/server/app-bfcache-id.js +7 -1
- package/dist/server/app-bfcache-identity.js +1 -2
- package/dist/server/app-browser-entry.js +15 -9
- 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-hydration.d.ts +1 -1
- package/dist/server/app-browser-hydration.js +2 -2
- 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-state.js +1 -1
- package/dist/server/app-browser-stream.d.ts +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 -1
- package/dist/server/app-history-state.js +9 -5
- package/dist/server/app-middleware.js +2 -1
- 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 +65 -44
- package/dist/server/app-page-cache.d.ts +5 -0
- package/dist/server/app-page-cache.js +27 -7
- package/dist/server/app-page-dispatch.d.ts +9 -1
- package/dist/server/app-page-dispatch.js +47 -30
- 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-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 +2 -2
- package/dist/server/app-page-render.d.ts +13 -5
- package/dist/server/app-page-render.js +219 -118
- package/dist/server/app-page-request.d.ts +0 -1
- package/dist/server/app-page-request.js +1 -2
- 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 +55 -33
- 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-search-params-observation.js +1 -1
- package/dist/server/app-page-stream.d.ts +15 -8
- package/dist/server/app-page-stream.js +7 -1
- package/dist/server/app-page-tracing.js +2 -1
- package/dist/server/app-pages-bridge.js +3 -2
- package/dist/server/app-render-abort-error.d.ts +3 -0
- package/dist/server/app-render-abort-error.js +8 -0
- package/dist/server/app-request-stage-dispatch.js +1 -1
- package/dist/server/app-request-stage-independent-entry.js +8 -11
- 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-route-handler-cache.d.ts +2 -1
- package/dist/server/app-route-handler-cache.js +11 -7
- package/dist/server/app-route-handler-dispatch.js +11 -4
- package/dist/server/app-route-handler-execution.d.ts +9 -1
- package/dist/server/app-route-handler-execution.js +28 -13
- package/dist/server/app-route-handler-policy.js +2 -2
- package/dist/server/app-route-handler-response.d.ts +1 -1
- package/dist/server/app-route-handler-response.js +14 -5
- package/dist/server/app-router-entry.d.ts +2 -1
- package/dist/server/app-router-entry.js +8 -12
- package/dist/server/app-rsc-errors.d.ts +0 -1
- package/dist/server/app-rsc-errors.js +2 -6
- package/dist/server/app-rsc-handler.d.ts +5 -0
- package/dist/server/app-rsc-handler.js +229 -102
- package/dist/server/app-rsc-request-normalization.d.ts +4 -2
- package/dist/server/app-rsc-request-normalization.js +7 -4
- package/dist/server/app-rsc-response-finalizer.js +4 -1
- package/dist/server/app-rsc-response-stage.d.ts +1 -1
- package/dist/server/app-rsc-response-stage.js +6 -4
- package/dist/server/app-rsc-route-matching.d.ts +9 -1
- package/dist/server/app-rsc-route-matching.js +37 -20
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-server-action-execution.js +1 -1
- package/dist/server/app-ssr-entry.d.ts +3 -2
- package/dist/server/app-ssr-entry.js +9 -7
- package/dist/server/app-ssr-search-params-gate.js +1 -1
- package/dist/server/app-ssr-stream.d.ts +6 -1
- package/dist/server/app-ssr-stream.js +35 -16
- package/dist/server/app-worker-stages.d.ts +2 -2
- package/dist/server/app-worker-stages.js +3 -3
- package/dist/server/cache-control.js +3 -11
- package/dist/server/cacheability-request.js +56 -52
- package/dist/server/config-headers.js +3 -1
- package/dist/server/dev-server.js +23 -5
- package/dist/server/headers.d.ts +16 -0
- package/dist/server/headers.js +19 -1
- package/dist/server/http-error-responses.js +1 -0
- package/dist/server/image-optimization.d.ts +16 -0
- package/dist/server/image-optimization.js +26 -6
- package/dist/server/isr-cache.d.ts +2 -0
- package/dist/server/isr-cache.js +8 -3
- package/dist/server/metadata-route-response.js +94 -37
- package/dist/server/middleware-matcher-pattern.js +8 -4
- package/dist/server/middleware-response-headers.js +2 -0
- package/dist/server/multi-stage.d.ts +8 -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/open-redirect.d.ts +47 -0
- package/dist/server/open-redirect.js +74 -1
- package/dist/server/pages-api-route.js +8 -2
- package/dist/server/pages-asset-tags.d.ts +1 -0
- package/dist/server/pages-asset-tags.js +73 -22
- package/dist/server/pages-client-assets.d.ts +2 -0
- package/dist/server/pages-page-data.d.ts +6 -1
- package/dist/server/pages-page-data.js +71 -65
- package/dist/server/pages-page-handler.js +50 -15
- package/dist/server/pages-page-response.js +3 -1
- package/dist/server/pages-request-pipeline.d.ts +2 -1
- package/dist/server/pages-request-pipeline.js +20 -5
- package/dist/server/pages-request-stage-entry.js +14 -8
- package/dist/server/prerender-manifest.d.ts +6 -0
- package/dist/server/prerender-manifest.js +1 -1
- package/dist/server/prod-server.d.ts +8 -7
- package/dist/server/prod-server.js +152 -78
- package/dist/server/request-pipeline.d.ts +20 -8
- package/dist/server/request-pipeline.js +21 -7
- package/dist/server/response-compression.d.ts +43 -0
- package/dist/server/response-compression.js +111 -0
- package/dist/server/response-stage-cacheability.js +1 -1
- package/dist/server/seed-cache.js +10 -7
- package/dist/server/socket-error-backstop.d.ts +14 -0
- package/dist/server/socket-error-backstop.js +27 -4
- package/dist/server/worker-revalidation-context.d.ts +2 -1
- package/dist/server/worker-revalidation-context.js +1 -0
- package/dist/server/workers-tracing.d.ts +17 -0
- package/dist/server/workers-tracing.js +48 -8
- 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 +2 -40
- package/dist/shims/cache-callable-runtime.js +50 -168
- package/dist/shims/cache-flight-arguments.d.ts +22 -0
- package/dist/shims/cache-flight-arguments.js +56 -0
- package/dist/shims/cache-request-state.d.ts +18 -14
- package/dist/shims/cache-request-state.js +33 -21
- package/dist/shims/cache-runtime.d.ts +6 -19
- package/dist/shims/cache-runtime.js +168 -226
- package/dist/shims/cache.d.ts +3 -2
- package/dist/shims/cache.js +8 -5
- package/dist/shims/cacheability-classification.d.ts +8 -1
- package/dist/shims/cacheability-classification.js +2 -2
- package/dist/shims/cdn-cache.d.ts +10 -1
- package/dist/shims/cdn-cache.js +16 -9
- 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/error.d.ts +4 -18
- package/dist/shims/error.js +17 -10
- package/dist/shims/error.react-server.d.ts +4 -6
- package/dist/shims/error.react-server.js +4 -1
- package/dist/shims/fetch-cache.d.ts +6 -0
- package/dist/shims/fetch-cache.js +23 -4
- package/dist/shims/form.js +1 -1
- package/dist/shims/headers.d.ts +19 -69
- package/dist/shims/headers.js +82 -183
- 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/cache-context-accessor.d.ts +16 -0
- package/dist/shims/internal/cache-context-accessor.js +15 -0
- package/dist/shims/internal/headers-state.d.ts +73 -0
- package/dist/shims/internal/headers-state.js +157 -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 +16 -6
- package/dist/shims/request-context.d.ts +9 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/root-params.js +1 -1
- package/dist/shims/server.js +52 -2
- 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/utils/encode-cache-tag.d.ts +1 -0
- package/dist/utils/encode-cache-tag.js +11 -1
- package/dist/utils/mdx-scan.d.ts +5 -0
- package/dist/utils/mdx-scan.js +8 -1
- package/dist/utils/regex-safety.d.ts +10 -0
- package/dist/utils/regex-safety.js +70 -18
- package/dist/utils/vite-cli-invocation.js +8 -1
- package/package.json +8 -4
- package/dist/server/metadata-route-cache-policy.d.ts +0 -5
- package/dist/server/metadata-route-cache-policy.js +0 -6
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { getOrCreateAls } from "./als-registry.js";
|
|
2
|
+
import { ensureRenderDynamicLatch, getRequestContext, isInsideUnifiedScope } from "../unified-request-context.js";
|
|
3
|
+
//#region src/shims/internal/headers-state.ts
|
|
4
|
+
function createRenderDynamicLatch() {
|
|
5
|
+
return {
|
|
6
|
+
dynamic: false,
|
|
7
|
+
listeners: /* @__PURE__ */ new Set()
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const _FALLBACK_KEY = Symbol.for("vinext.nextHeadersShim.fallback");
|
|
11
|
+
const _g = globalThis;
|
|
12
|
+
const headersShimAls = getOrCreateAls("vinext.nextHeadersShim.als");
|
|
13
|
+
const _fallbackState = _g[_FALLBACK_KEY] ??= {
|
|
14
|
+
headersContext: null,
|
|
15
|
+
dynamicUsageDetected: false,
|
|
16
|
+
renderDynamicLatch: createRenderDynamicLatch(),
|
|
17
|
+
renderRequestApiUsage: /* @__PURE__ */ new Set(),
|
|
18
|
+
connectionProbe: null,
|
|
19
|
+
invalidDynamicUsageError: null,
|
|
20
|
+
pendingSetCookies: [],
|
|
21
|
+
draftModeCookieHeader: null,
|
|
22
|
+
phase: "render"
|
|
23
|
+
};
|
|
24
|
+
function getHeadersShimState() {
|
|
25
|
+
if (isInsideUnifiedScope()) return getRequestContext();
|
|
26
|
+
return headersShimAls.getStore() ?? _fallbackState;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Dynamic usage flag — set when a component calls connection(), cookies(),
|
|
30
|
+
* headers(), or noStore() during rendering. When true, ISR caching is
|
|
31
|
+
* bypassed and the response gets Cache-Control: no-store.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Mark the current render as requiring dynamic (uncached) rendering.
|
|
35
|
+
* Called by connection(), cookies(), headers(), and noStore().
|
|
36
|
+
*/
|
|
37
|
+
function markDynamicUsage() {
|
|
38
|
+
const state = getHeadersShimState();
|
|
39
|
+
if (state.headersContext?.forceStatic) return;
|
|
40
|
+
state.dynamicUsageDetected = true;
|
|
41
|
+
const latches = [ensureRenderDynamicLatch(state)];
|
|
42
|
+
forEachConnectionProbeTarget(state, (target) => {
|
|
43
|
+
target.dynamicUsageDetected = true;
|
|
44
|
+
latches.push(ensureRenderDynamicLatch(target));
|
|
45
|
+
});
|
|
46
|
+
for (const latch of latches) latchRenderDynamic(latch);
|
|
47
|
+
}
|
|
48
|
+
function latchRenderDynamic(latch) {
|
|
49
|
+
if (latch.dynamic) return;
|
|
50
|
+
latch.dynamic = true;
|
|
51
|
+
const listeners = [...latch.listeners];
|
|
52
|
+
latch.listeners.clear();
|
|
53
|
+
for (const listener of listeners) try {
|
|
54
|
+
listener();
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Whether the current render has used a dynamic API at any point so far. */
|
|
60
|
+
function isRenderDynamicLatched() {
|
|
61
|
+
return ensureRenderDynamicLatch(getHeadersShimState()).dynamic;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Call `listener` once when the current render first uses a dynamic API.
|
|
65
|
+
* Returns an unsubscribe function. The listener never runs if the render is
|
|
66
|
+
* already latched; check `isRenderDynamicLatched()` first.
|
|
67
|
+
*/
|
|
68
|
+
function onRenderDynamicLatched(listener) {
|
|
69
|
+
const latch = ensureRenderDynamicLatch(getHeadersShimState());
|
|
70
|
+
if (latch.dynamic) return () => {};
|
|
71
|
+
latch.listeners.add(listener);
|
|
72
|
+
return () => {
|
|
73
|
+
latch.listeners.delete(listener);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function forEachConnectionProbeTarget(state, visit) {
|
|
77
|
+
let target = state.connectionProbe?.dynamicUsageTarget ?? null;
|
|
78
|
+
const seen = /* @__PURE__ */ new Set([state]);
|
|
79
|
+
while (target && !seen.has(target)) {
|
|
80
|
+
seen.add(target);
|
|
81
|
+
visit(target);
|
|
82
|
+
target = target.connectionProbe?.dynamicUsageTarget ?? null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function propagateInvalidDynamicUsageError(state, error) {
|
|
86
|
+
forEachConnectionProbeTarget(state, (target) => {
|
|
87
|
+
if (target.invalidDynamicUsageError == null) target.invalidDynamicUsageError = error;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function markRenderRequestApiUsage(kind) {
|
|
91
|
+
getHeadersShimState().renderRequestApiUsage.add(kind);
|
|
92
|
+
}
|
|
93
|
+
function throwIfStaticGenerationAccessError() {
|
|
94
|
+
const accessError = getHeadersShimState().headersContext?.accessError;
|
|
95
|
+
if (accessError) throw accessError;
|
|
96
|
+
}
|
|
97
|
+
/** Symbol used by cache-runtime.ts to store the "use cache" ALS on globalThis */
|
|
98
|
+
const _USE_CACHE_ALS_KEY = Symbol.for("vinext.cacheRuntime.contextAls");
|
|
99
|
+
/** Symbol used by cache.ts to store the unstable_cache ALS on globalThis */
|
|
100
|
+
const _UNSTABLE_CACHE_ALS_KEY = Symbol.for("vinext.unstableCache.als");
|
|
101
|
+
function _getGlobalCacheScopeStore(key) {
|
|
102
|
+
const value = Reflect.get(globalThis, key);
|
|
103
|
+
if (!value || typeof value !== "object") return null;
|
|
104
|
+
const getStore = Reflect.get(value, "getStore");
|
|
105
|
+
if (typeof getStore !== "function") return null;
|
|
106
|
+
return getStore.call(value);
|
|
107
|
+
}
|
|
108
|
+
function _getUseCacheGuardContext() {
|
|
109
|
+
const store = _getGlobalCacheScopeStore(_USE_CACHE_ALS_KEY);
|
|
110
|
+
if (!store || typeof store !== "object") return null;
|
|
111
|
+
return store;
|
|
112
|
+
}
|
|
113
|
+
function _isInsidePublicUseCache() {
|
|
114
|
+
const ctx = _getUseCacheGuardContext();
|
|
115
|
+
return ctx !== null && ctx.variant !== "private";
|
|
116
|
+
}
|
|
117
|
+
function _isInsideUnstableCache() {
|
|
118
|
+
return _getGlobalCacheScopeStore(_UNSTABLE_CACHE_ALS_KEY) === true;
|
|
119
|
+
}
|
|
120
|
+
/** Whether work is executing inside a cache boundary that owns its reuse. */
|
|
121
|
+
function isInsideAnyCacheScope() {
|
|
122
|
+
return _getUseCacheGuardContext() !== null || _isInsideUnstableCache();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Throw if the current execution is inside a "use cache" or unstable_cache()
|
|
126
|
+
* scope. Called by dynamic request APIs (headers, cookies, connection) to
|
|
127
|
+
* prevent request-specific data from being frozen into cached results.
|
|
128
|
+
*
|
|
129
|
+
* @param apiName - The name of the API being called (e.g. "connection()")
|
|
130
|
+
*/
|
|
131
|
+
function throwIfInsideCacheScope(apiName) {
|
|
132
|
+
if (_isInsidePublicUseCache()) {
|
|
133
|
+
const error = /* @__PURE__ */ new Error(`\`${apiName}\` cannot be called inside "use cache". If you need this data inside a cached function, call \`${apiName}\` outside and pass the required data as an argument.`);
|
|
134
|
+
try {
|
|
135
|
+
const cacheCtx = _getUseCacheGuardContext();
|
|
136
|
+
if (cacheCtx) cacheCtx.invalidDynamicUsageError = error;
|
|
137
|
+
const ctx = getRequestContext();
|
|
138
|
+
if (ctx) ctx.invalidDynamicUsageError = error;
|
|
139
|
+
propagateInvalidDynamicUsageError(getHeadersShimState(), error);
|
|
140
|
+
} catch {}
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
if (_isInsideUnstableCache()) {
|
|
144
|
+
const error = /* @__PURE__ */ new Error(`\`${apiName}\` cannot be called inside a function cached with \`unstable_cache()\`. If you need this data inside a cached function, call \`${apiName}\` outside and pass the required data as an argument.`);
|
|
145
|
+
try {
|
|
146
|
+
const ctx = getRequestContext();
|
|
147
|
+
if (ctx) ctx.invalidDynamicUsageError = error;
|
|
148
|
+
propagateInvalidDynamicUsageError(getHeadersShimState(), error);
|
|
149
|
+
} catch {}
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function getHeadersAccessPhase() {
|
|
154
|
+
return getHeadersShimState().phase;
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
export { createRenderDynamicLatch, getHeadersAccessPhase, getHeadersShimState, headersShimAls, isInsideAnyCacheScope, isRenderDynamicLatched, markDynamicUsage, markRenderRequestApiUsage, onRenderDynamicLatched, throwIfInsideCacheScope, throwIfStaticGenerationAccessError };
|
package/dist/shims/metadata.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAbsoluteOrProtocolRelativeUrl } from "./url-utils.js";
|
|
2
|
+
import { withUseCacheLayoutMarker, withUseCachePageMarker } from "./internal/app-page-props-cache-key.js";
|
|
2
3
|
import { makeThenableParams } from "./thenable-params.js";
|
|
3
|
-
import { withUseCachePageMarker } from "./internal/app-page-props-cache-key.js";
|
|
4
4
|
import React from "react";
|
|
5
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/shims/metadata.tsx
|
|
@@ -19,7 +19,7 @@ const USE_CACHE_ACCEPTS_SECOND_ARGUMENT_SYMBOL = Symbol.for("vinext.useCacheAcce
|
|
|
19
19
|
async function resolveModuleViewport(mod, params = {}, searchParams, parent = Promise.resolve(mergeViewport([])), searchParamsObserver) {
|
|
20
20
|
if (typeof mod.generateViewport === "function") {
|
|
21
21
|
const asyncParams = makeThenableParams(params);
|
|
22
|
-
const props = searchParams === void 0 ? { params: asyncParams } : withUseCachePageMarker(mod.generateViewport, {
|
|
22
|
+
const props = searchParams === void 0 ? withUseCacheLayoutMarker(mod.generateViewport, { params: asyncParams }) : withUseCachePageMarker(mod.generateViewport, {
|
|
23
23
|
params: asyncParams,
|
|
24
24
|
searchParams: makeThenableParams(searchParams, searchParamsObserver)
|
|
25
25
|
});
|
|
@@ -268,7 +268,7 @@ async function resolveModuleMetadata(mod, params = {}, searchParams, parent = Pr
|
|
|
268
268
|
if (typeof mod.generateMetadata === "function") {
|
|
269
269
|
const generateMetadata = mod.generateMetadata;
|
|
270
270
|
const asyncParams = makeThenableParams(params);
|
|
271
|
-
const props = searchParams === void 0 ? { params: asyncParams } : withUseCachePageMarker(generateMetadata, {
|
|
271
|
+
const props = searchParams === void 0 ? withUseCacheLayoutMarker(generateMetadata, { params: asyncParams }) : withUseCachePageMarker(generateMetadata, {
|
|
272
272
|
params: asyncParams,
|
|
273
273
|
searchParams: makeThenableParams(searchParams, searchParamsObserver)
|
|
274
274
|
});
|
|
@@ -12,6 +12,12 @@ export declare enum RedirectType {
|
|
|
12
12
|
push = "push",
|
|
13
13
|
replace = "replace"
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether `error` was thrown by redirect(), notFound() or another navigation
|
|
17
|
+
* function in the render that caught it, rather than decoded from an RSC
|
|
18
|
+
* render's digest.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isThrownNavigationError(error: unknown): boolean;
|
|
15
21
|
/**
|
|
16
22
|
* The omitted redirect type is resolved by the catch site: push for Server
|
|
17
23
|
* Actions and replace for ordinary SSR/RSC rendering.
|
|
@@ -25,14 +25,24 @@ let RedirectType = /* @__PURE__ */ function(RedirectType) {
|
|
|
25
25
|
RedirectType["replace"] = "replace";
|
|
26
26
|
return RedirectType;
|
|
27
27
|
}({});
|
|
28
|
+
const THROWN_NAVIGATION_ERROR_MARKER = Symbol.for("vinext.navigationError.thrown");
|
|
28
29
|
var VinextNavigationError = class extends Error {
|
|
29
30
|
digest;
|
|
31
|
+
[THROWN_NAVIGATION_ERROR_MARKER] = true;
|
|
30
32
|
constructor(message, digest) {
|
|
31
33
|
super(message);
|
|
32
34
|
this.digest = digest;
|
|
33
35
|
}
|
|
34
36
|
};
|
|
35
37
|
/**
|
|
38
|
+
* Whether `error` was thrown by redirect(), notFound() or another navigation
|
|
39
|
+
* function in the render that caught it, rather than decoded from an RSC
|
|
40
|
+
* render's digest.
|
|
41
|
+
*/
|
|
42
|
+
function isThrownNavigationError(error) {
|
|
43
|
+
return typeof error === "object" && error !== null && Reflect.get(error, THROWN_NAVIGATION_ERROR_MARKER) === true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
36
46
|
* The omitted redirect type is resolved by the catch site: push for Server
|
|
37
47
|
* Actions and replace for ordinary SSR/RSC rendering.
|
|
38
48
|
*/
|
|
@@ -103,4 +113,4 @@ function unstable_rethrow(error) {
|
|
|
103
113
|
if (error instanceof Error && "cause" in error) unstable_rethrow(error.cause);
|
|
104
114
|
}
|
|
105
115
|
//#endregion
|
|
106
|
-
export { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow };
|
|
116
|
+
export { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, isThrownNavigationError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow };
|
|
@@ -49,6 +49,13 @@ export type CachedRscResponse = {
|
|
|
49
49
|
mountedSlotsHeader?: string | null;
|
|
50
50
|
paramsHeader: string | null;
|
|
51
51
|
preparedElements?: AppElements;
|
|
52
|
+
/**
|
|
53
|
+
* Streamed `redirect()` side-channel headers. A replayed snapshot must keep
|
|
54
|
+
* them so the navigation follows the redirect instead of decoding the
|
|
55
|
+
* redirect payload as a page.
|
|
56
|
+
*/
|
|
57
|
+
redirectHeader?: string;
|
|
58
|
+
redirectTypeHeader?: string;
|
|
52
59
|
renderedPathAndSearch: string | null;
|
|
53
60
|
serverStaleTime?: ServerStaleTime;
|
|
54
61
|
url: string;
|
package/dist/shims/navigation.js
CHANGED
|
@@ -2,27 +2,27 @@ import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
|
2
2
|
import { isExternalUrl } from "../utils/external-url.js";
|
|
3
3
|
import { stripBasePath } from "../utils/base-path.js";
|
|
4
4
|
import { NEXT_ROUTER_PREFETCH_HEADER, NEXT_ROUTER_SEGMENT_PREFETCH_HEADER, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_RSC_RENDER_MODE_HEADER } from "../server/app-rsc-vary.js";
|
|
5
|
-
import { NEXT_ROUTER_STALE_TIME_HEADER, VINEXT_DYNAMIC_STALE_TIME_HEADER, VINEXT_PARAMS_HEADER, VINEXT_RENDERED_PATH_AND_SEARCH_HEADER, VINEXT_RSC_COMPLETION_METADATA_HEADER, VINEXT_STALE_TIME_PENDING_HEADER } from "../server/headers.js";
|
|
5
|
+
import { NEXT_ROUTER_STALE_TIME_HEADER, VINEXT_DYNAMIC_STALE_TIME_HEADER, VINEXT_PARAMS_HEADER, VINEXT_RENDERED_PATH_AND_SEARCH_HEADER, VINEXT_RSC_COMPLETION_METADATA_HEADER, VINEXT_RSC_REDIRECT_HEADER, VINEXT_RSC_REDIRECT_TYPE_HEADER, VINEXT_STALE_TIME_PENDING_HEADER } from "../server/headers.js";
|
|
6
6
|
import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
7
7
|
import { APP_RSC_RENDER_MODE_PREFETCH_DYNAMIC_SHELL, APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "../server/app-rsc-render-mode.js";
|
|
8
|
-
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
9
|
-
import "../server/app-elements.js";
|
|
10
8
|
import { getPprFallbackShellState, markPprFallbackShellDynamicBoundary } from "./ppr-fallback-shell.js";
|
|
11
9
|
import { AppRouterContext } from "./internal/app-router-context.js";
|
|
12
10
|
import { resolveDirectHybridClientRouteOwner } from "./internal/hybrid-client-route-owner-direct.js";
|
|
13
11
|
import { isHashOnlyBrowserUrlChange, toCanonicalBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
|
|
14
12
|
import { retryScrollTo, scrollToHashTarget, scrollToHashTargetOnNextFrame } from "./hash-scroll.js";
|
|
13
|
+
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
14
|
+
import "../server/app-elements.js";
|
|
15
15
|
import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
|
|
16
16
|
import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
|
|
17
17
|
import { clearAppNavigationFailureTarget, stageAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
|
|
18
18
|
import { beginAppRouterScrollIntent, clearAppRouterScrollIntent, consumeAppRouterScrollIntent, getPendingAppRouterScrollIntent, isLatestAppRouterScrollIntent } from "./app-router-scroll-state.js";
|
|
19
19
|
import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam, stripRscSuffix } from "../server/app-rsc-cache-busting.js";
|
|
20
|
-
import { getNavigationRuntime, hasAppNavigationRuntime } from "../client/navigation-runtime.js";
|
|
21
20
|
import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
|
|
21
|
+
import { getNavigationRuntime, hasAppNavigationRuntime } from "../client/navigation-runtime.js";
|
|
22
22
|
import { UnrecognizedActionError, unstable_isUnrecognizedActionError } from "./unrecognized-action-error.js";
|
|
23
23
|
import { PUBLIC_INITIAL_BFCACHE_ID } from "../server/app-bfcache-id.js";
|
|
24
|
-
import { createExternalHistoryStatePreservingMetadata, createHashOnlyHistoryStatePreservingNavigationMetadata, isAppOwnedHistoryState } from "../server/app-history-state.js";
|
|
25
24
|
import { resolveManifestNavigationInterceptionContext } from "../server/app-browser-interception-context.js";
|
|
25
|
+
import { createExternalHistoryStatePreservingMetadata, createHashOnlyHistoryStatePreservingNavigationMetadata, isAppOwnedHistoryState } from "../server/app-history-state.js";
|
|
26
26
|
import { hasPendingAppRouterPageRedirect } from "../server/app-browser-mpa-navigation.js";
|
|
27
27
|
import { extractRscCompletionMetadata } from "../server/rsc-completion-metadata.js";
|
|
28
28
|
import { navigationPlanner } from "../server/navigation-planner.js";
|
|
@@ -662,6 +662,8 @@ function createCachedRscResponseSnapshot(response, buffer, responseUrl = null) {
|
|
|
662
662
|
kind: "resolved",
|
|
663
663
|
seconds: extracted.metadata.serverStaleTimeSeconds
|
|
664
664
|
} : parsedServerStaleTime;
|
|
665
|
+
const redirectHeader = response.headers.get(VINEXT_RSC_REDIRECT_HEADER);
|
|
666
|
+
const redirectTypeHeader = response.headers.get(VINEXT_RSC_REDIRECT_TYPE_HEADER);
|
|
665
667
|
return {
|
|
666
668
|
compatibilityIdHeader: response.headers.get(VINEXT_RSC_COMPATIBILITY_ID_HEADER),
|
|
667
669
|
buffer: extracted.buffer,
|
|
@@ -670,6 +672,8 @@ function createCachedRscResponseSnapshot(response, buffer, responseUrl = null) {
|
|
|
670
672
|
...dynamicStaleTimeSeconds !== void 0 ? { dynamicStaleTimeSeconds } : {},
|
|
671
673
|
mountedSlotsHeader: response.headers.get(VINEXT_MOUNTED_SLOTS_HEADER),
|
|
672
674
|
paramsHeader: response.headers.get(VINEXT_PARAMS_HEADER),
|
|
675
|
+
...redirectHeader === null ? {} : { redirectHeader },
|
|
676
|
+
...redirectTypeHeader === null ? {} : { redirectTypeHeader },
|
|
673
677
|
renderedPathAndSearch: parseRenderedPathAndSearchHeader(response.headers.get(VINEXT_RENDERED_PATH_AND_SEARCH_HEADER)),
|
|
674
678
|
...serverStaleTime === void 0 ? {} : { serverStaleTime },
|
|
675
679
|
url: responseUrl ?? response.url
|
|
@@ -739,6 +743,8 @@ function restoreRscResponse(cached, copy = true) {
|
|
|
739
743
|
if (cached.serverStaleTime?.kind === "pending") headers.set(VINEXT_STALE_TIME_PENDING_HEADER, "1");
|
|
740
744
|
else if (cached.serverStaleTime !== void 0) headers.set(NEXT_ROUTER_STALE_TIME_HEADER, String(cached.serverStaleTime.seconds));
|
|
741
745
|
if (cached.paramsHeader != null) headers.set(VINEXT_PARAMS_HEADER, cached.paramsHeader);
|
|
746
|
+
if (cached.redirectHeader !== void 0) headers.set(VINEXT_RSC_REDIRECT_HEADER, cached.redirectHeader);
|
|
747
|
+
if (cached.redirectTypeHeader !== void 0) headers.set(VINEXT_RSC_REDIRECT_TYPE_HEADER, cached.redirectTypeHeader);
|
|
742
748
|
if (cached.renderedPathAndSearch != null) headers.set(VINEXT_RENDERED_PATH_AND_SEARCH_HEADER, encodeURIComponent(cached.renderedPathAndSearch));
|
|
743
749
|
const response = new Response(copy ? cached.buffer.slice(0) : cached.buffer, {
|
|
744
750
|
status: 200,
|
|
@@ -826,7 +832,7 @@ function prefetchRscResponse(rscUrl, fetchPromise, interceptionContext = null, m
|
|
|
826
832
|
entry.size = snapshot.buffer.byteLength;
|
|
827
833
|
adjustPrefetchCacheByteSize(cache, entry.size - previousSize);
|
|
828
834
|
entry.expiresAt = resolvePrefetchedRscResponseExpiresAt(entry.timestamp, entry.snapshot, behavior.fallbackTtlMs ?? PREFETCH_CACHE_TTL, behavior.searchAgnosticShell === true ? "ignore" : behavior.dynamicStaleTime ?? (behavior.optimisticRouteShell === true ? "ignore" : "verbatim"));
|
|
829
|
-
if (behavior.prepareSnapshot) try {
|
|
835
|
+
if (behavior.prepareSnapshot && snapshot.redirectHeader === void 0) try {
|
|
830
836
|
const preparedElements = await behavior.prepareSnapshot(snapshot);
|
|
831
837
|
if (cache.get(cacheKey) !== entry) return;
|
|
832
838
|
entry.preparedElements = preparedElements;
|
|
@@ -1781,6 +1787,7 @@ if (!isServer) {
|
|
|
1781
1787
|
}
|
|
1782
1788
|
});
|
|
1783
1789
|
window.history.pushState = function patchedPushState(data, unused, url) {
|
|
1790
|
+
getNavigationRuntime()?.functions.flushCommittingNavigationUrl?.();
|
|
1784
1791
|
if (isAppOwnedHistoryState(data)) {
|
|
1785
1792
|
const previousHistoryState = window.history.state;
|
|
1786
1793
|
state.originalPushState.call(window.history, data, unused, url);
|
|
@@ -1792,10 +1799,12 @@ if (!isServer) {
|
|
|
1792
1799
|
getNavigationRuntime()?.functions.claimCurrentHistoryTreeSnapshot?.("push", previousHistoryState);
|
|
1793
1800
|
if (state.suppressUrlNotifyCount === 0) {
|
|
1794
1801
|
resetStaleLinkStatus();
|
|
1802
|
+
if (url) getNavigationRuntime()?.functions.discardPendingNavigation?.();
|
|
1795
1803
|
commitClientNavigationState();
|
|
1796
1804
|
}
|
|
1797
1805
|
};
|
|
1798
1806
|
window.history.replaceState = function patchedReplaceState(data, unused, url) {
|
|
1807
|
+
getNavigationRuntime()?.functions.flushCommittingNavigationUrl?.();
|
|
1799
1808
|
if (isAppOwnedHistoryState(data)) {
|
|
1800
1809
|
const previousHistoryState = window.history.state;
|
|
1801
1810
|
state.originalReplaceState.call(window.history, data, unused, url);
|
|
@@ -1807,6 +1816,7 @@ if (!isServer) {
|
|
|
1807
1816
|
getNavigationRuntime()?.functions.claimCurrentHistoryTreeSnapshot?.("replace", previousHistoryState);
|
|
1808
1817
|
if (state.suppressUrlNotifyCount === 0) {
|
|
1809
1818
|
resetStaleLinkStatus();
|
|
1819
|
+
if (url) getNavigationRuntime()?.functions.discardPendingNavigation?.();
|
|
1810
1820
|
commitClientNavigationState();
|
|
1811
1821
|
}
|
|
1812
1822
|
};
|
|
@@ -44,6 +44,15 @@ export type ExecutionContextLike = {
|
|
|
44
44
|
isInternalPagesRevalidation?: boolean;
|
|
45
45
|
/** Marks a build-secret-authorized Worker request that may run prerender discovery hooks. */
|
|
46
46
|
isPrerenderPathDiscovery?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Installed only by the prerender server: records the page's special error
|
|
49
|
+
* that escaped the shell, with the headers to store, for the build.
|
|
50
|
+
*/
|
|
51
|
+
recordPrerenderSpecialError?: (marker: PrerenderSpecialErrorMarker) => void;
|
|
52
|
+
};
|
|
53
|
+
export type PrerenderSpecialErrorMarker = {
|
|
54
|
+
headers: Record<string, string>;
|
|
55
|
+
status: number;
|
|
47
56
|
};
|
|
48
57
|
/**
|
|
49
58
|
* Run `fn` with the given `ExecutionContext` available via
|
|
@@ -4,7 +4,8 @@ import "./navigation.js";
|
|
|
4
4
|
import { CacheLifeConfig, CacheState } from "./cache-request-state.js";
|
|
5
5
|
import { RootParamsState } from "./root-params.js";
|
|
6
6
|
import { FetchCacheState } from "./fetch-cache.js";
|
|
7
|
-
import { HeadersAccessPhase,
|
|
7
|
+
import { HeadersAccessPhase, VinextHeadersShimState } from "./internal/headers-state.js";
|
|
8
|
+
import { HeadersContext } from "./headers.js";
|
|
8
9
|
import { RouterState, SSRContext } from "./router-state.js";
|
|
9
10
|
import { PrivateCacheState } from "./cache-runtime.js";
|
|
10
11
|
import { HeadState } from "./head-state.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getOrCreateAls } from "./internal/als-registry.js";
|
|
2
2
|
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
3
|
-
import { _recordUseCacheRootParamRead } from "./cache-
|
|
3
|
+
import { _recordUseCacheRootParamRead } from "./internal/cache-context-accessor.js";
|
|
4
4
|
//#region src/shims/root-params.ts
|
|
5
5
|
function createRootParamsUsageError(message) {
|
|
6
6
|
return new Error(message);
|
package/dist/shims/server.js
CHANGED
|
@@ -48,15 +48,65 @@ function _throwIfInsideCacheScope(apiName) {
|
|
|
48
48
|
throw error;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Workers can hand a GET/HEAD a non-null body (e.g. a GET sent with
|
|
53
|
+
* Content-Length). Next.js nulls GET/HEAD bodies before user code runs, so a
|
|
54
|
+
* NextRequest never carries one either.
|
|
55
|
+
*/
|
|
56
|
+
function hasGetOrHeadBody(request) {
|
|
57
|
+
return (request.method === "GET" || request.method === "HEAD") && request.body !== null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The Request constructor rejects such a body when it reads a Request init as
|
|
61
|
+
* a dictionary, as it does for the route handler's tracking Proxy, so rebuild
|
|
62
|
+
* the init without it. Every other standard field, plus workerd's `cf` and
|
|
63
|
+
* `fetcher`, is copied so a framed GET builds the same Request as an unframed
|
|
64
|
+
* one. (`duplex` only applies to a body.)
|
|
65
|
+
*/
|
|
66
|
+
function requestInitFromRequest(request) {
|
|
67
|
+
if (!hasGetOrHeadBody(request)) return request;
|
|
68
|
+
const cf = Reflect.get(request, "cf");
|
|
69
|
+
const fetcher = Reflect.get(request, "fetcher");
|
|
70
|
+
return {
|
|
71
|
+
method: request.method,
|
|
72
|
+
headers: request.headers,
|
|
73
|
+
body: null,
|
|
74
|
+
cache: request.cache,
|
|
75
|
+
credentials: request.credentials,
|
|
76
|
+
integrity: request.integrity,
|
|
77
|
+
keepalive: request.keepalive,
|
|
78
|
+
mode: request.mode,
|
|
79
|
+
redirect: request.redirect,
|
|
80
|
+
referrer: request.referrer,
|
|
81
|
+
referrerPolicy: request.referrerPolicy,
|
|
82
|
+
signal: request.signal,
|
|
83
|
+
...cf !== void 0 ? { cf } : {},
|
|
84
|
+
...fetcher !== void 0 ? { fetcher } : {}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A Request input passes its body on unless the init replaces it, so drop a
|
|
89
|
+
* GET/HEAD input's body when the init keeps the input's method and body. This
|
|
90
|
+
* covers the requests vinext hands to middleware, route handlers and edge API
|
|
91
|
+
* routes.
|
|
92
|
+
*/
|
|
93
|
+
function initWithoutInputBody(input, init) {
|
|
94
|
+
if (init instanceof Request || init.method !== void 0 || init.body !== void 0 || !hasGetOrHeadBody(input)) return init;
|
|
95
|
+
return {
|
|
96
|
+
...init,
|
|
97
|
+
body: null
|
|
98
|
+
};
|
|
99
|
+
}
|
|
51
100
|
var NextRequest = class extends Request {
|
|
52
101
|
_nextUrl;
|
|
53
102
|
_url;
|
|
54
103
|
_cookies;
|
|
55
104
|
constructor(input, init) {
|
|
56
105
|
validateURL(typeof input !== "string" && "url" in input ? input.url : String(input));
|
|
57
|
-
const { nextConfig: _nextConfig, ...
|
|
106
|
+
const { nextConfig: _nextConfig, ...plainInit } = init ?? {};
|
|
107
|
+
const requestInit = init instanceof Request ? requestInitFromRequest(init) : plainInit;
|
|
58
108
|
if (input instanceof Request) {
|
|
59
|
-
super(input, requestInit);
|
|
109
|
+
super(input, initWithoutInputBody(input, requestInit));
|
|
60
110
|
const cfDescriptor = Reflect.getOwnPropertyDescriptor(input, "cf");
|
|
61
111
|
if (cfDescriptor) Object.defineProperty(this, "cf", cfDescriptor);
|
|
62
112
|
else {
|
|
@@ -5,5 +5,9 @@ export type ThenableParamsObserver = Readonly<{
|
|
|
5
5
|
observeParamAccess: (keys: readonly string[]) => void;
|
|
6
6
|
observeReactPromiseStatus?: boolean;
|
|
7
7
|
}>;
|
|
8
|
+
/** Serialize backing values without reading a framework fallback-key proxy. */
|
|
9
|
+
export declare function getFallbackParamsSnapshot(value: unknown): Promise<Record<string, unknown>> | undefined;
|
|
10
|
+
/** Reattach only framework metadata; argument values always come from the decoder. */
|
|
11
|
+
export declare function restoreThenableParams<T extends Record<string, unknown>>(decoded: T, original: unknown): ThenableParams<T>;
|
|
8
12
|
export declare function makeThenableParams<T extends Record<string, unknown>>(obj: T, observer?: ThenableParamsObserver): ThenableParams<T>;
|
|
9
13
|
//#endregion
|
|
@@ -4,6 +4,20 @@ import { isOwnPropertyCheck, isWellKnownProperty } from "./internal/thenable-wel
|
|
|
4
4
|
function hasParamProperty(obj, prop) {
|
|
5
5
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
6
6
|
}
|
|
7
|
+
const paramsState = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function getParamsState(value) {
|
|
9
|
+
return value !== null && typeof value === "object" ? paramsState.get(value) : void 0;
|
|
10
|
+
}
|
|
11
|
+
/** Serialize backing values without reading a framework fallback-key proxy. */
|
|
12
|
+
function getFallbackParamsSnapshot(value) {
|
|
13
|
+
const state = getParamsState(value);
|
|
14
|
+
return state?.fallbackShellState ? Promise.resolve(state.plain) : void 0;
|
|
15
|
+
}
|
|
16
|
+
/** Reattach only framework metadata; argument values always come from the decoder. */
|
|
17
|
+
function restoreThenableParams(decoded, original) {
|
|
18
|
+
const state = getParamsState(original);
|
|
19
|
+
return createThenableParams(decoded, state?.observer, state?.fallbackShellState ?? null);
|
|
20
|
+
}
|
|
7
21
|
function observeParamKeys(observer, keys) {
|
|
8
22
|
if (observer) observer.observeParamAccess(keys);
|
|
9
23
|
}
|
|
@@ -81,8 +95,10 @@ function createThenableParamsProxy(promise, handler) {
|
|
|
81
95
|
return new Proxy(promise, handler);
|
|
82
96
|
}
|
|
83
97
|
function makeThenableParams(obj, observer) {
|
|
98
|
+
return createThenableParams(obj, observer, getPprFallbackShellState());
|
|
99
|
+
}
|
|
100
|
+
function createThenableParams(obj, observer, fallbackShellState) {
|
|
84
101
|
const plain = { ...obj };
|
|
85
|
-
const fallbackShellState = getPprFallbackShellState();
|
|
86
102
|
const fallbackParamNames = fallbackShellState && Object.keys(plain).some((key) => fallbackShellState.fallbackParamNames.has(key)) ? fallbackShellState.fallbackParamNames : null;
|
|
87
103
|
let fallbackShellPromise = null;
|
|
88
104
|
let fallbackShellPromiseController = null;
|
|
@@ -98,7 +114,7 @@ function makeThenableParams(obj, observer) {
|
|
|
98
114
|
function isFallbackParam(prop) {
|
|
99
115
|
return typeof prop === "string" && (fallbackParamNames?.has(prop) ?? false);
|
|
100
116
|
}
|
|
101
|
-
|
|
117
|
+
const params = createThenableParamsProxy(promise, {
|
|
102
118
|
get(target, prop, receiver) {
|
|
103
119
|
if (isPromiseContinuation(prop)) {
|
|
104
120
|
const value = Reflect.get(target, prop, receiver);
|
|
@@ -150,6 +166,12 @@ function makeThenableParams(obj, observer) {
|
|
|
150
166
|
return Reflect.ownKeys(plain).filter((prop) => !isWellKnownProperty(prop));
|
|
151
167
|
}
|
|
152
168
|
});
|
|
169
|
+
paramsState.set(params, {
|
|
170
|
+
plain,
|
|
171
|
+
observer,
|
|
172
|
+
fallbackShellState: fallbackParamNames ? fallbackShellState : null
|
|
173
|
+
});
|
|
174
|
+
return params;
|
|
153
175
|
}
|
|
154
176
|
//#endregion
|
|
155
|
-
export { makeThenableParams };
|
|
177
|
+
export { getFallbackParamsSnapshot, makeThenableParams, restoreThenableParams };
|
|
@@ -2,7 +2,7 @@ import { ExecutionContextLike } from "./request-context.js";
|
|
|
2
2
|
import { CacheState } from "./cache-request-state.js";
|
|
3
3
|
import { RootParamsState } from "./root-params.js";
|
|
4
4
|
import { FetchCacheState } from "./fetch-cache.js";
|
|
5
|
-
import { VinextHeadersShimState } from "./headers.js";
|
|
5
|
+
import { VinextHeadersShimState } from "./internal/headers-state.js";
|
|
6
6
|
import { RouterState } from "./router-state.js";
|
|
7
7
|
import { markFullyBufferedBody, preserveFullyBufferedBodyMetadata } from "../server/fully-buffered-response.js";
|
|
8
8
|
import { PrivateCacheState } from "./cache-runtime.js";
|
|
@@ -17,6 +17,7 @@ function createRequestContext(opts) {
|
|
|
17
17
|
return {
|
|
18
18
|
headersContext: null,
|
|
19
19
|
actionRevalidationKind: 0,
|
|
20
|
+
cacheLifeSink: null,
|
|
20
21
|
pendingRevalidatedTags: /* @__PURE__ */ new Set(),
|
|
21
22
|
pendingRevalidations: /* @__PURE__ */ new Set(),
|
|
22
23
|
dynamicUsageDetected: false,
|
|
@@ -25,5 +25,6 @@
|
|
|
25
25
|
* (introduced in vercel/next.js#93601).
|
|
26
26
|
*/
|
|
27
27
|
export declare function encodeCacheTag(tag: string): string;
|
|
28
|
+
/** Validate raw public tag types and lengths before header encoding. */
|
|
28
29
|
export declare function encodeCacheTags(tags: readonly string[]): string[];
|
|
29
30
|
//#endregion
|
|
@@ -26,11 +26,21 @@
|
|
|
26
26
|
*/
|
|
27
27
|
const OUT_OF_CLASS_CHAR = /[^\t\x20-\x7e]/;
|
|
28
28
|
const OUT_OF_CLASS_RUN = /[^\t\x20-\x7e]+/g;
|
|
29
|
+
const MAX_TAG_LENGTH = 256;
|
|
29
30
|
function encodeCacheTag(tag) {
|
|
30
31
|
return OUT_OF_CLASS_CHAR.test(tag) ? tag.replace(OUT_OF_CLASS_RUN, (run) => encodeURIComponent(run)) : tag;
|
|
31
32
|
}
|
|
33
|
+
/** Validate raw public tag types and lengths before header encoding. */
|
|
32
34
|
function encodeCacheTags(tags) {
|
|
33
|
-
|
|
35
|
+
const encoded = [];
|
|
36
|
+
for (const tag of tags) {
|
|
37
|
+
if (typeof tag !== "string" || tag.length > MAX_TAG_LENGTH) {
|
|
38
|
+
console.warn(`[vinext] Cache tags must be strings of at most ${MAX_TAG_LENGTH} characters; invalid tag ignored.`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
encoded.push(encodeCacheTag(tag));
|
|
42
|
+
}
|
|
43
|
+
return encoded;
|
|
34
44
|
}
|
|
35
45
|
//#endregion
|
|
36
46
|
export { encodeCacheTag, encodeCacheTags };
|
package/dist/utils/mdx-scan.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export declare const mdxScanCache: Map<string, boolean>;
|
|
|
5
5
|
* Check if the project has .mdx files in app/ or pages/ directories.
|
|
6
6
|
*/
|
|
7
7
|
export declare function hasMdxFiles(root: string, appDir: string | null, pagesDir: string | null): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Whether page extensions discover MDX sources, including compound extensions
|
|
10
|
+
* such as `page.mdx`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function pageExtensionsIncludeMdx(pageExtensions: readonly string[]): boolean;
|
|
8
13
|
/**
|
|
9
14
|
* Load a reader that keeps only the ESM of an MDX module, so the JavaScript
|
|
10
15
|
* export helpers can read it. It takes the ESM nodes from the MDX parser that
|
package/dist/utils/mdx-scan.js
CHANGED
|
@@ -33,6 +33,13 @@ function scanDirForMdx(dir) {
|
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
+
* Whether page extensions discover MDX sources, including compound extensions
|
|
37
|
+
* such as `page.mdx`.
|
|
38
|
+
*/
|
|
39
|
+
function pageExtensionsIncludeMdx(pageExtensions) {
|
|
40
|
+
return pageExtensions.some((extension) => extension.toLowerCase().split(".").at(-1) === "mdx");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
36
43
|
* Load a reader that keeps only the ESM of an MDX module, so the JavaScript
|
|
37
44
|
* export helpers can read it. It takes the ESM nodes from the MDX parser that
|
|
38
45
|
* `@mdx-js/rollup` compiles with, resolved beside the plugin vinext
|
|
@@ -57,4 +64,4 @@ async function loadMdxEsmReader(root) {
|
|
|
57
64
|
return (source) => processor.parse(source).children.flatMap((node) => node.type === "mdxjsEsm" && typeof node.value === "string" ? [node.value] : []).join("\n\n");
|
|
58
65
|
}
|
|
59
66
|
//#endregion
|
|
60
|
-
export { hasMdxFiles, loadMdxEsmReader, mdxScanCache };
|
|
67
|
+
export { hasMdxFiles, loadMdxEsmReader, mdxScanCache, pageExtensionsIncludeMdx };
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
//#region src/utils/regex-safety.d.ts
|
|
2
2
|
export type RegexSafetyIssue = "nested repetition" | "ambiguous alternatives under repetition" | "ambiguous sequence expansion" | "overlapping sequential repetition" | "analysis budget exceeded";
|
|
3
|
+
/**
|
|
4
|
+
* Whether a RegExp source declares a named group, which turns `\k<name>` into
|
|
5
|
+
* a backreference. Escaped characters and character classes cannot open one.
|
|
6
|
+
*/
|
|
7
|
+
export declare function mayHaveNamedGroups(pattern: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* `namedGroups` must describe the whole compiled RegExp when `pattern` is only
|
|
10
|
+
* a fragment of it. It defaults to scanning `pattern` itself.
|
|
11
|
+
*/
|
|
3
12
|
export declare function analyzeRegexSafety(pattern: string, options?: {
|
|
4
13
|
ignoreCase?: boolean;
|
|
14
|
+
namedGroups?: boolean;
|
|
5
15
|
}): RegexSafetyIssue | null;
|
|
6
16
|
export declare function regexAtomsMayOverlap(left: string, right: string, ignoreCase?: boolean): boolean;
|
|
7
17
|
//#endregion
|