vinext 0.0.23 → 0.0.24

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.
@@ -1 +1 @@
1
- {"version":3,"file":"app-dev-server.d.ts","sourceRoot":"","sources":["../../src/server/app-dev-server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAKtF;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE;QACT,WAAW,EAAE,WAAW,EAAE,CAAC;QAC3B,UAAU,EAAE,WAAW,EAAE,CAAC;QAC1B,QAAQ,EAAE,WAAW,EAAE,CAAC;KACzB,CAAC;IACF,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IACvB,4GAA4G;IAC5G,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,uGAAuG;IACvG,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,QAAQ,EAAE,EAClB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,EAC9B,cAAc,CAAC,EAAE,iBAAiB,EAAE,EACpC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,EAC/B,QAAQ,CAAC,EAAE,MAAM,EACjB,aAAa,CAAC,EAAE,OAAO,EACvB,MAAM,CAAC,EAAE,eAAe,GACvB,MAAM,CAgvER;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAibzC;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CA+T7C"}
1
+ {"version":3,"file":"app-dev-server.d.ts","sourceRoot":"","sources":["../../src/server/app-dev-server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAKtF;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE;QACT,WAAW,EAAE,WAAW,EAAE,CAAC;QAC3B,UAAU,EAAE,WAAW,EAAE,CAAC;QAC1B,QAAQ,EAAE,WAAW,EAAE,CAAC;KACzB,CAAC;IACF,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IACvB,4GAA4G;IAC5G,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,uGAAuG;IACvG,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,QAAQ,EAAE,EAClB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,EAC9B,cAAc,CAAC,EAAE,iBAAiB,EAAE,EACpC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,EAC/B,QAAQ,CAAC,EAAE,MAAM,EACjB,aAAa,CAAC,EAAE,OAAO,EACvB,MAAM,CAAC,EAAE,eAAe,GACvB,MAAM,CAqxER;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAibzC;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CA+T7C"}
@@ -196,7 +196,7 @@ import {
196
196
  } from "@vitejs/plugin-rsc/rsc";
197
197
  import { createElement, Suspense, Fragment } from "react";
198
198
  import { setNavigationContext as _setNavigationContextOrig, getNavigationContext as _getNavigationContext } from "next/navigation";
199
- import { setHeadersContext, headersContextFromRequest, getDraftModeCookieHeader, getAndClearPendingCookies, consumeDynamicUsage, markDynamicUsage, runWithHeadersContext, applyMiddlewareRequestHeaders } from "next/headers";
199
+ import { setHeadersContext, headersContextFromRequest, getDraftModeCookieHeader, getAndClearPendingCookies, consumeDynamicUsage, markDynamicUsage, runWithHeadersContext, applyMiddlewareRequestHeaders, getHeadersContext } from "next/headers";
200
200
  import { NextRequest } from "next/server";
201
201
  import { ErrorBoundary, NotFoundBoundary } from "vinext/error-boundary";
202
202
  import { LayoutSegmentProvider } from "vinext/layout-segment-context";
@@ -1051,6 +1051,28 @@ function __buildRequestContext(request) {
1051
1051
  };
1052
1052
  }
1053
1053
 
1054
+ /**
1055
+ * Build a request context from the live ALS HeadersContext, which reflects
1056
+ * any x-middleware-request-* header mutations applied by middleware.
1057
+ * Used for afterFiles and fallback rewrite has/missing evaluation — these
1058
+ * run after middleware in the App Router execution order.
1059
+ */
1060
+ function __buildPostMwRequestContext(request) {
1061
+ const url = new URL(request.url);
1062
+ const ctx = getHeadersContext();
1063
+ if (!ctx) return __buildRequestContext(request);
1064
+ // ctx.cookies is a Map<string, string> (HeadersContext), but RequestContext
1065
+ // requires a plain Record<string, string> for has/missing cookie evaluation
1066
+ // (config-matchers.ts uses obj[key] not Map.get()). Convert here.
1067
+ const cookiesRecord = Object.fromEntries(ctx.cookies);
1068
+ return {
1069
+ headers: ctx.headers,
1070
+ cookies: cookiesRecord,
1071
+ query: url.searchParams,
1072
+ host: ctx.headers.get("host") || url.host,
1073
+ };
1074
+ }
1075
+
1054
1076
  function __sanitizeDestination(dest) {
1055
1077
  if (dest.startsWith("http://") || dest.startsWith("https://")) return dest;
1056
1078
  dest = dest.replace(/^[\\\\/]+/, "/");
@@ -1185,7 +1207,16 @@ async function __proxyExternalRequest(request, externalUrl) {
1185
1207
  console.error("[vinext] External rewrite proxy error:", e); return new Response("Bad Gateway", { status: 502 });
1186
1208
  }
1187
1209
  const respHeaders = new Headers();
1188
- upstream.headers.forEach(function(value, key) { if (!__hopByHopHeaders.has(key.toLowerCase())) respHeaders.append(key, value); });
1210
+ // Node.js fetch() auto-decompresses response bodies, while Workers fetch()
1211
+ // preserves wire encoding. Only strip encoding/length on Node.js to avoid
1212
+ // double-decompression errors without breaking Workers parity.
1213
+ const __isNodeRuntime = typeof process !== "undefined" && !!(process.versions && process.versions.node);
1214
+ upstream.headers.forEach(function(value, key) {
1215
+ var lower = key.toLowerCase();
1216
+ if (__hopByHopHeaders.has(lower)) return;
1217
+ if (__isNodeRuntime && (lower === "content-encoding" || lower === "content-length")) return;
1218
+ respHeaders.append(key, value);
1219
+ });
1189
1220
  return new Response(upstream.body, { status: upstream.status, statusText: upstream.statusText, headers: respHeaders });
1190
1221
  }
1191
1222
 
@@ -1344,21 +1375,6 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1344
1375
  }
1345
1376
  }
1346
1377
 
1347
- // ── Apply beforeFiles rewrites from next.config.js ────────────────────
1348
- if (__configRewrites.beforeFiles && __configRewrites.beforeFiles.length) {
1349
- // Strip .rsc suffix before matching rewrite rules — same reason as redirects above.
1350
- const __rewritePathname = pathname.endsWith(".rsc") ? pathname.slice(0, -4) : pathname;
1351
- const __rewritten = __applyConfigRewrites(__rewritePathname, __configRewrites.beforeFiles, __reqCtx);
1352
- if (__rewritten) {
1353
- if (__isExternalUrl(__rewritten)) {
1354
- setHeadersContext(null);
1355
- setNavigationContext(null);
1356
- return __proxyExternalRequest(request, __rewritten);
1357
- }
1358
- pathname = __rewritten;
1359
- }
1360
- }
1361
-
1362
1378
  const isRscRequest = pathname.endsWith(".rsc") || request.headers.get("accept")?.includes("text/x-component");
1363
1379
  let cleanPathname = pathname.replace(/\\.rsc$/, "");
1364
1380
 
@@ -1452,6 +1468,27 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1452
1468
  }
1453
1469
  ` : ""}
1454
1470
 
1471
+ // Build post-middleware request context for afterFiles/fallback rewrites.
1472
+ // These run after middleware in the App Router execution order and should
1473
+ // evaluate has/missing conditions against middleware-modified headers.
1474
+ // When no middleware is present, this falls back to __buildRequestContext.
1475
+ const __postMwReqCtx = __buildPostMwRequestContext(request);
1476
+
1477
+ // ── Apply beforeFiles rewrites from next.config.js ────────────────────
1478
+ // In App Router execution order, beforeFiles runs after middleware so that
1479
+ // has/missing conditions can evaluate against middleware-modified headers.
1480
+ if (__configRewrites.beforeFiles && __configRewrites.beforeFiles.length) {
1481
+ const __rewritten = __applyConfigRewrites(cleanPathname, __configRewrites.beforeFiles, __postMwReqCtx);
1482
+ if (__rewritten) {
1483
+ if (__isExternalUrl(__rewritten)) {
1484
+ setHeadersContext(null);
1485
+ setNavigationContext(null);
1486
+ return __proxyExternalRequest(request, __rewritten);
1487
+ }
1488
+ cleanPathname = __rewritten;
1489
+ }
1490
+ }
1491
+
1455
1492
  // ── Image optimization passthrough (dev mode — no transformation) ───────
1456
1493
  if (cleanPathname === "/_vinext/image") {
1457
1494
  const __rawImgUrl = url.searchParams.get("url");
@@ -1677,7 +1714,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1677
1714
 
1678
1715
  // ── Apply afterFiles rewrites from next.config.js ──────────────────────
1679
1716
  if (__configRewrites.afterFiles && __configRewrites.afterFiles.length) {
1680
- const __afterRewritten = __applyConfigRewrites(cleanPathname, __configRewrites.afterFiles, __reqCtx);
1717
+ const __afterRewritten = __applyConfigRewrites(cleanPathname, __configRewrites.afterFiles, __postMwReqCtx);
1681
1718
  if (__afterRewritten) {
1682
1719
  if (__isExternalUrl(__afterRewritten)) {
1683
1720
  setHeadersContext(null);
@@ -1692,7 +1729,7 @@ async function _handleRequest(request, __reqCtx, _mwCtx) {
1692
1729
 
1693
1730
  // ── Fallback rewrites from next.config.js (if no route matched) ───────
1694
1731
  if (!match && __configRewrites.fallback && __configRewrites.fallback.length) {
1695
- const __fallbackRewritten = __applyConfigRewrites(cleanPathname, __configRewrites.fallback, __reqCtx);
1732
+ const __fallbackRewritten = __applyConfigRewrites(cleanPathname, __configRewrites.fallback, __postMwReqCtx);
1696
1733
  if (__fallbackRewritten) {
1697
1734
  if (__isExternalUrl(__fallbackRewritten)) {
1698
1735
  setHeadersContext(null);