vinext 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_LICENSES.md +26 -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 +3 -7
- package/dist/build/prerender.d.ts +8 -1
- package/dist/build/prerender.js +134 -38
- 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/client/browser-globals.d.ts +4 -0
- package/dist/client/browser-globals.js +5 -0
- package/dist/client/navigation-runtime.d.ts +0 -1
- package/dist/client/navigation-runtime.js +2 -2
- package/dist/config/dotenv.js +14 -3
- package/dist/entries/app-rsc-entry.js +3 -2
- package/dist/index.js +142 -71
- 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/commonjs-syntax.d.ts +16 -0
- package/dist/plugins/commonjs-syntax.js +22 -0
- 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/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 +4 -2
- package/dist/server/app-browser-hydration.d.ts +1 -1
- package/dist/server/app-browser-hydration.js +2 -2
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-state.js +1 -1
- package/dist/server/app-browser-stream.d.ts +1 -1
- package/dist/server/app-history-state.d.ts +0 -1
- package/dist/server/app-history-state.js +2 -5
- package/dist/server/app-page-cache-render.js +2 -1
- package/dist/server/app-page-render.js +2 -1
- package/dist/server/app-page-search-params-observation.js +1 -1
- package/dist/server/app-page-stream.js +1 -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-independent-entry.js +4 -7
- 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 +10 -3
- 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 +5 -9
- 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 +1 -0
- package/dist/server/app-rsc-handler.js +18 -7
- package/dist/server/app-rsc-request-normalization.d.ts +1 -1
- package/dist/server/app-rsc-request-normalization.js +3 -2
- package/dist/server/app-rsc-response-finalizer.js +4 -1
- package/dist/server/app-rsc-route-matching.js +1 -1
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-ssr-entry.js +3 -3
- package/dist/server/app-ssr-search-params-gate.js +1 -1
- package/dist/server/app-ssr-stream.js +1 -1
- package/dist/server/cache-control.js +3 -11
- package/dist/server/cacheability-request.js +49 -49
- package/dist/server/config-headers.js +1 -1
- package/dist/server/dev-server.js +11 -3
- package/dist/server/headers.d.ts +2 -0
- package/dist/server/headers.js +5 -1
- package/dist/server/http-error-responses.js +1 -0
- package/dist/server/isr-cache.d.ts +2 -0
- package/dist/server/isr-cache.js +6 -1
- package/dist/server/metadata-route-response.js +94 -37
- 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 +29 -11
- 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 +6 -4
- package/dist/server/prerender-manifest.d.ts +6 -0
- package/dist/server/prerender-manifest.js +1 -1
- package/dist/server/prod-server.js +3 -13
- package/dist/server/response-stage-cacheability.js +1 -1
- 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-request-state.d.ts +3 -14
- package/dist/shims/cache-request-state.js +2 -13
- package/dist/shims/cache-runtime.js +4 -2
- package/dist/shims/cache.d.ts +2 -1
- package/dist/shims/cache.js +4 -2
- package/dist/shims/cacheability-classification.d.ts +1 -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.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.js +4 -3
- package/dist/shims/headers.d.ts +6 -69
- package/dist/shims/headers.js +37 -181
- 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 +74 -0
- package/dist/shims/internal/headers-state.js +157 -0
- package/dist/shims/navigation.js +2 -2
- 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/unified-request-context.d.ts +1 -1
- package/dist/utils/encode-cache-tag.d.ts +1 -0
- package/dist/utils/encode-cache-tag.js +11 -1
- package/dist/utils/vite-cli-invocation.js +8 -1
- package/package.json +6 -2
- package/dist/server/metadata-route-cache-policy.d.ts +0 -5
- package/dist/server/metadata-route-cache-policy.js +0 -6
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/shims/internal/cache-context-accessor.ts
|
|
2
|
+
let getCacheContext = null;
|
|
3
|
+
function _registerCacheContextAccessor(fn) {
|
|
4
|
+
getCacheContext = fn;
|
|
5
|
+
}
|
|
6
|
+
function getRegisteredCacheContext() {
|
|
7
|
+
return getCacheContext?.() ?? null;
|
|
8
|
+
}
|
|
9
|
+
/** Record a root-param dependency on the active public `"use cache"` scope. */
|
|
10
|
+
function _recordUseCacheRootParamRead(name) {
|
|
11
|
+
const context = getRegisteredCacheContext();
|
|
12
|
+
if (context && context.variant !== "private") context.readRootParamNames?.add(name);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { _recordUseCacheRootParamRead, _registerCacheContextAccessor, getRegisteredCacheContext };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { RenderRequestApiKind } from "../../server/cache-proof.js";
|
|
2
|
+
import { HeadersContext } from "../headers.js";
|
|
3
|
+
//#region src/shims/internal/headers-state.d.ts
|
|
4
|
+
export type HeadersAccessPhase = "render" | "action" | "route-handler";
|
|
5
|
+
/**
|
|
6
|
+
* Whether the current render has used a dynamic API. Unlike
|
|
7
|
+
* `dynamicUsageDetected`, nothing clears it, and one object is shared by every
|
|
8
|
+
* child scope of the request, so usage inside isolated scopes (such as the
|
|
9
|
+
* layout probe) stays visible to later readers.
|
|
10
|
+
*/
|
|
11
|
+
export type RenderDynamicLatch = {
|
|
12
|
+
dynamic: boolean;
|
|
13
|
+
listeners: Set<() => void>;
|
|
14
|
+
};
|
|
15
|
+
export declare function createRenderDynamicLatch(): RenderDynamicLatch;
|
|
16
|
+
export type VinextHeadersShimState = {
|
|
17
|
+
headersContext: HeadersContext | null;
|
|
18
|
+
dynamicUsageDetected: boolean;
|
|
19
|
+
renderDynamicLatch: RenderDynamicLatch;
|
|
20
|
+
renderRequestApiUsage: Set<RenderRequestApiKind>;
|
|
21
|
+
connectionProbe: ConnectionProbeState | null;
|
|
22
|
+
/** Error recorded by throwIfInsideCacheScope for dev diagnostics, persists even if caught by user code. */
|
|
23
|
+
invalidDynamicUsageError: unknown;
|
|
24
|
+
pendingSetCookies: string[];
|
|
25
|
+
draftModeCookieHeader: string | null;
|
|
26
|
+
phase: HeadersAccessPhase;
|
|
27
|
+
};
|
|
28
|
+
export type ConnectionProbeState = {
|
|
29
|
+
active: boolean;
|
|
30
|
+
dynamicUsageTarget: VinextHeadersShimState;
|
|
31
|
+
interrupted: boolean;
|
|
32
|
+
interrupt: () => void;
|
|
33
|
+
pending: Promise<never>;
|
|
34
|
+
};
|
|
35
|
+
export type ConnectionProbeResult<T> = {
|
|
36
|
+
completed: true;
|
|
37
|
+
result: T;
|
|
38
|
+
} | {
|
|
39
|
+
completed: false;
|
|
40
|
+
};
|
|
41
|
+
export declare const headersShimAls: import("node:async_hooks").AsyncLocalStorage<VinextHeadersShimState>;
|
|
42
|
+
export declare function getHeadersShimState(): VinextHeadersShimState;
|
|
43
|
+
/**
|
|
44
|
+
* Dynamic usage flag — set when a component calls connection(), cookies(),
|
|
45
|
+
* headers(), or noStore() during rendering. When true, ISR caching is
|
|
46
|
+
* bypassed and the response gets Cache-Control: no-store.
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* Mark the current render as requiring dynamic (uncached) rendering.
|
|
50
|
+
* Called by connection(), cookies(), headers(), and noStore().
|
|
51
|
+
*/
|
|
52
|
+
export declare function markDynamicUsage(): void;
|
|
53
|
+
/** Whether the current render has used a dynamic API at any point so far. */
|
|
54
|
+
export declare function isRenderDynamicLatched(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Call `listener` once when the current render first uses a dynamic API.
|
|
57
|
+
* Returns an unsubscribe function. The listener never runs if the render is
|
|
58
|
+
* already latched; check `isRenderDynamicLatched()` first.
|
|
59
|
+
*/
|
|
60
|
+
export declare function onRenderDynamicLatched(listener: () => void): () => void;
|
|
61
|
+
export declare function markRenderRequestApiUsage(kind: RenderRequestApiKind): void;
|
|
62
|
+
export declare function throwIfStaticGenerationAccessError(): void;
|
|
63
|
+
/** Whether work is executing inside a cache boundary that owns its reuse. */
|
|
64
|
+
export declare function isInsideAnyCacheScope(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Throw if the current execution is inside a "use cache" or unstable_cache()
|
|
67
|
+
* scope. Called by dynamic request APIs (headers, cookies, connection) to
|
|
68
|
+
* prevent request-specific data from being frozen into cached results.
|
|
69
|
+
*
|
|
70
|
+
* @param apiName - The name of the API being called (e.g. "connection()")
|
|
71
|
+
*/
|
|
72
|
+
export declare function throwIfInsideCacheScope(apiName: string): void;
|
|
73
|
+
export declare function getHeadersAccessPhase(): HeadersAccessPhase;
|
|
74
|
+
//#endregion
|
|
@@ -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/navigation.js
CHANGED
|
@@ -17,12 +17,12 @@ import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE,
|
|
|
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";
|
|
@@ -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 {
|
|
@@ -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";
|
|
@@ -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 };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { findViteConfigPath } from "./project.js";
|
|
3
|
+
import fs from "node:fs";
|
|
3
4
|
//#region src/utils/vite-cli-invocation.ts
|
|
4
5
|
let buildClaimed = false;
|
|
5
6
|
const valued = new Set("--config -c --mode -m --logLevel -l --filter -f --configLoader --port --outDir --target --assetsDir --assetsInlineLimit".split(" "));
|
|
@@ -72,9 +73,15 @@ function findViteRoot(command, args) {
|
|
|
72
73
|
shouldPreflight: preflight
|
|
73
74
|
};
|
|
74
75
|
}
|
|
76
|
+
function isViteEntry(entry) {
|
|
77
|
+
return entry.endsWith("/vite/bin/vite.js") || entry.endsWith("/vite/node/cli.js") || entry.endsWith("/dist/vite/node/cli.js");
|
|
78
|
+
}
|
|
75
79
|
function commandArguments(argv) {
|
|
76
80
|
const entry = toSlash(argv[1] ?? "");
|
|
77
|
-
|
|
81
|
+
let vite = isViteEntry(entry);
|
|
82
|
+
if (!vite && entry && path.basename(entry) !== "vp") try {
|
|
83
|
+
vite = isViteEntry(toSlash(fs.realpathSync.native(entry)));
|
|
84
|
+
} catch {}
|
|
78
85
|
let args = argv.slice(2);
|
|
79
86
|
if (!vite) {
|
|
80
87
|
if (path.basename(entry) !== "vp") return void 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vinext",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Run Next.js apps on Vite. Drop-in replacement for the next CLI.",
|
|
5
5
|
"homepage": "https://vinext.dev/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -90,6 +90,10 @@
|
|
|
90
90
|
"types": "./dist/server/pages-router-entry.d.ts",
|
|
91
91
|
"import": "./dist/server/pages-router-entry.js"
|
|
92
92
|
},
|
|
93
|
+
"./internal/client/vinext-next-data": {
|
|
94
|
+
"types": "./dist/client/vinext-next-data.d.ts",
|
|
95
|
+
"import": "./dist/client/vinext-next-data.js"
|
|
96
|
+
},
|
|
93
97
|
"./internal/server/headers": {
|
|
94
98
|
"types": "./dist/server/headers.d.ts",
|
|
95
99
|
"import": "./dist/server/headers.js"
|
|
@@ -222,7 +226,7 @@
|
|
|
222
226
|
"magic-string": "^0.30.21",
|
|
223
227
|
"vite-plugin-commonjs": "^0.10.4",
|
|
224
228
|
"web-vitals": "^4.2.4",
|
|
225
|
-
"@vinext/types": "^1.0.
|
|
229
|
+
"@vinext/types": "^1.0.1"
|
|
226
230
|
},
|
|
227
231
|
"devDependencies": {
|
|
228
232
|
"@types/node": "^25.9.2",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region src/server/metadata-route-cache-policy.ts
|
|
2
|
-
function isMetadataResponseCacheable(response) {
|
|
3
|
-
return !(response.headers.get("cache-control")?.toLowerCase() ?? "").split(",").map((directive) => directive.trim().split("=", 1)[0]).some((directive) => directive === "no-cache" || directive === "no-store");
|
|
4
|
-
}
|
|
5
|
-
//#endregion
|
|
6
|
-
export { isMetadataResponseCacheable };
|