vinext 1.0.1 → 1.2.0

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