vinext 0.1.4 → 0.1.5

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 (126) hide show
  1. package/dist/build/css-url-assets.d.ts +1 -1
  2. package/dist/build/css-url-assets.js +9 -7
  3. package/dist/build/prerender.js +2 -1
  4. package/dist/cache/cache-adapters-virtual.js +1 -1
  5. package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +1 -1
  6. package/dist/entries/app-rsc-entry.js +24 -20
  7. package/dist/entries/pages-server-entry.js +2 -1
  8. package/dist/index.js +187 -146
  9. package/dist/plugins/css-data-url.js +30 -26
  10. package/dist/plugins/extensionless-dynamic-import.js +27 -24
  11. package/dist/plugins/import-meta-url.js +21 -15
  12. package/dist/plugins/instrumentation-client.js +1 -1
  13. package/dist/plugins/middleware-server-only.js +7 -6
  14. package/dist/plugins/og-assets.js +48 -46
  15. package/dist/plugins/optimize-imports.js +9 -3
  16. package/dist/plugins/remove-console.d.ts +7 -1
  17. package/dist/plugins/remove-console.js +4 -1
  18. package/dist/plugins/require-context.js +21 -20
  19. package/dist/plugins/strip-server-exports.d.ts +7 -1
  20. package/dist/plugins/strip-server-exports.js +4 -1
  21. package/dist/server/app-bfcache-identity.d.ts +26 -0
  22. package/dist/server/app-bfcache-identity.js +127 -0
  23. package/dist/server/app-browser-entry.js +14 -11
  24. package/dist/server/app-browser-navigation-controller.js +1 -1
  25. package/dist/server/app-browser-state.d.ts +2 -21
  26. package/dist/server/app-browser-state.js +4 -128
  27. package/dist/server/app-browser-stream.js +1 -1
  28. package/dist/server/app-browser-visible-commit.js +3 -2
  29. package/dist/server/app-fallback-renderer.d.ts +1 -1
  30. package/dist/server/app-layout-param-observation.d.ts +1 -1
  31. package/dist/server/app-layout-param-observation.js +1 -1
  32. package/dist/server/app-middleware.js +2 -1
  33. package/dist/server/app-page-boundary-render.d.ts +1 -1
  34. package/dist/server/app-page-boundary.js +1 -1
  35. package/dist/server/app-page-cache-finalizer.d.ts +62 -0
  36. package/dist/server/app-page-cache-finalizer.js +122 -0
  37. package/dist/server/app-page-cache-render.d.ts +2 -2
  38. package/dist/server/app-page-cache-render.js +1 -1
  39. package/dist/server/app-page-cache.d.ts +2 -53
  40. package/dist/server/app-page-cache.js +5 -131
  41. package/dist/server/app-page-dispatch.d.ts +2 -2
  42. package/dist/server/app-page-dispatch.js +10 -8
  43. package/dist/server/app-page-probe.js +3 -2
  44. package/dist/server/app-page-render-observation.js +2 -2
  45. package/dist/server/app-page-render.d.ts +3 -3
  46. package/dist/server/app-page-render.js +3 -2
  47. package/dist/server/app-page-stream.d.ts +2 -9
  48. package/dist/server/app-page-stream.js +1 -35
  49. package/dist/server/app-request-context.d.ts +1 -2
  50. package/dist/server/app-request-context.js +2 -1
  51. package/dist/server/app-route-handler-dispatch.js +3 -2
  52. package/dist/server/app-route-handler-execution.d.ts +1 -1
  53. package/dist/server/app-route-handler-execution.js +1 -1
  54. package/dist/server/app-route-handler-response.d.ts +1 -1
  55. package/dist/server/app-router-entry.js +2 -1
  56. package/dist/server/app-rsc-handler.js +22 -16
  57. package/dist/server/app-rsc-response-finalizer.js +1 -1
  58. package/dist/server/app-server-action-execution.d.ts +1 -1
  59. package/dist/server/app-server-action-execution.js +5 -4
  60. package/dist/server/app-ssr-entry.d.ts +1 -1
  61. package/dist/server/app-ssr-entry.js +11 -9
  62. package/dist/server/app-ssr-router-instance.d.ts +6 -0
  63. package/dist/server/app-ssr-router-instance.js +24 -0
  64. package/dist/server/app-ssr-stream.js +1 -1
  65. package/dist/server/artifact-compatibility.js +1 -1
  66. package/dist/server/client-reuse-manifest.js +1 -1
  67. package/dist/server/defer-until-stream-consumed.d.ts +7 -0
  68. package/dist/server/defer-until-stream-consumed.js +34 -0
  69. package/dist/server/dev-server.js +1 -1
  70. package/dist/server/instrumentation.js +1 -1
  71. package/dist/server/isr-cache.d.ts +1 -1
  72. package/dist/server/isr-cache.js +1 -1
  73. package/dist/server/isr-decision.d.ts +1 -1
  74. package/dist/server/middleware-matcher.js +8 -6
  75. package/dist/server/middleware-runtime.js +2 -2
  76. package/dist/server/open-redirect.d.ts +12 -0
  77. package/dist/server/open-redirect.js +21 -0
  78. package/dist/server/pages-page-data.d.ts +1 -1
  79. package/dist/server/pages-page-response.d.ts +1 -1
  80. package/dist/server/pages-page-response.js +2 -2
  81. package/dist/server/prod-server.js +2 -1
  82. package/dist/server/request-pipeline.d.ts +1 -24
  83. package/dist/server/request-pipeline.js +1 -33
  84. package/dist/server/seed-cache.d.ts +1 -1
  85. package/dist/shims/cache-handler.d.ts +106 -0
  86. package/dist/shims/cache-handler.js +176 -0
  87. package/dist/shims/cache-request-state.d.ts +47 -0
  88. package/dist/shims/cache-request-state.js +126 -0
  89. package/dist/shims/cache-runtime.d.ts +2 -2
  90. package/dist/shims/cache-runtime.js +3 -14
  91. package/dist/shims/cache.d.ts +3 -231
  92. package/dist/shims/cache.js +17 -383
  93. package/dist/shims/cdn-cache.d.ts +1 -1
  94. package/dist/shims/cdn-cache.js +1 -1
  95. package/dist/shims/error-boundary-navigation.d.ts +7 -0
  96. package/dist/shims/error-boundary-navigation.js +44 -0
  97. package/dist/shims/error-boundary.js +10 -8
  98. package/dist/shims/error.js +2 -1
  99. package/dist/shims/fetch-cache.js +1 -1
  100. package/dist/shims/form.js +1 -1
  101. package/dist/shims/image.js +67 -9
  102. package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -0
  103. package/dist/shims/internal/app-page-props-cache-key.js +16 -0
  104. package/dist/shims/internal/navigation-untracked.js +2 -1
  105. package/dist/shims/layout-segment-context.d.ts +1 -1
  106. package/dist/shims/layout-segment-context.js +2 -1
  107. package/dist/shims/link.js +2 -2
  108. package/dist/shims/navigation-context-state.d.ts +40 -0
  109. package/dist/shims/navigation-context-state.js +116 -0
  110. package/dist/shims/navigation-errors.d.ts +55 -0
  111. package/dist/shims/navigation-errors.js +110 -0
  112. package/dist/shims/navigation-server.d.ts +3 -0
  113. package/dist/shims/navigation-server.js +3 -0
  114. package/dist/shims/navigation-state.d.ts +1 -2
  115. package/dist/shims/navigation-state.js +2 -1
  116. package/dist/shims/navigation.d.ts +3 -291
  117. package/dist/shims/navigation.js +14 -445
  118. package/dist/shims/navigation.react-server.d.ts +2 -2
  119. package/dist/shims/navigation.react-server.js +3 -1
  120. package/dist/shims/request-state-types.d.ts +3 -3
  121. package/dist/shims/script.js +1 -1
  122. package/dist/shims/slot.js +3 -1
  123. package/dist/shims/unified-request-context.d.ts +2 -2
  124. package/dist/utils/virtual-module.d.ts +5 -0
  125. package/dist/utils/virtual-module.js +0 -0
  126. package/package.json +5 -1
@@ -1,25 +1,27 @@
1
1
  import { stripBasePath } from "../utils/base-path.js";
2
2
  import { VINEXT_DYNAMIC_STALE_TIME_HEADER, VINEXT_MOUNTED_SLOTS_HEADER, VINEXT_PARAMS_HEADER } from "../server/headers.js";
3
3
  import { assertSafeNavigationUrl } from "./url-safety.js";
4
- import { markPprFallbackShellDynamicBoundary } from "./ppr-fallback-shell.js";
5
4
  import { AppElementsWire } from "../server/app-elements-wire.js";
6
5
  import "../server/app-elements.js";
6
+ import { markPprFallbackShellDynamicBoundary } from "./ppr-fallback-shell.js";
7
7
  import { AppRouterContext } from "./internal/app-router-context.js";
8
8
  import { resolveHybridClientRouteOwner } from "./internal/hybrid-client-route-owner.js";
9
9
  import { isAbsoluteOrProtocolRelativeUrl, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
10
10
  import { retryScrollTo, scrollToHashTarget } from "./hash-scroll.js";
11
+ import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
12
+ import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
13
+ import { clearAppNavigationFailureTarget, stageAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
14
+ import { beginAppRouterScrollIntent, clearAppRouterScrollIntent, consumeAppRouterScrollIntent, getPendingAppRouterScrollIntent } from "./app-router-scroll-state.js";
15
+ import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam } from "../server/app-rsc-cache-busting.js";
11
16
  import { getNavigationRuntime, hasAppNavigationRuntime } from "../client/navigation-runtime.js";
12
17
  import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
13
- import { clearAppNavigationFailureTarget, stageAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
14
18
  import { PUBLIC_INITIAL_BFCACHE_ID } from "../server/app-bfcache-id.js";
15
- import { resolveManifestNavigationInterceptionContext } from "../server/app-browser-interception-context.js";
16
19
  import { createExternalHistoryStatePreservingMetadata, createHashOnlyHistoryStatePreservingNavigationMetadata } from "../server/app-history-state.js";
17
- import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam } from "../server/app-rsc-cache-busting.js";
20
+ import { resolveManifestNavigationInterceptionContext } from "../server/app-browser-interception-context.js";
18
21
  import { hasPendingAppRouterPageRedirect } from "../server/app-browser-mpa-navigation.js";
19
22
  import { navigationPlanner } from "../server/navigation-planner.js";
20
23
  import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
21
24
  import { getPagesNavigationContext } from "./internal/pages-router-accessor.js";
22
- import { beginAppRouterScrollIntent, clearAppRouterScrollIntent, consumeAppRouterScrollIntent, getPendingAppRouterScrollIntent } from "./app-router-scroll-state.js";
23
25
  import { UnrecognizedActionError, unstable_isUnrecognizedActionError } from "./unrecognized-action-error.js";
24
26
  import * as React$1 from "react";
25
27
  //#region src/shims/navigation.ts
@@ -30,39 +32,6 @@ import * as React$1 from "react";
30
32
  * Server-side: reads from a request context set by the RSC handler.
31
33
  * Client-side: reads from browser Location API and provides navigation.
32
34
  */
33
- const _LAYOUT_SEGMENT_CTX_KEY = Symbol.for("vinext.layoutSegmentContext");
34
- const _SERVER_INSERTED_HTML_CTX_KEY = Symbol.for("vinext.serverInsertedHTMLContext");
35
- const _BFCACHE_ID_MAP_CTX_KEY = Symbol.for("vinext.bfcacheIdMapContext");
36
- const _BFCACHE_SEGMENT_ID_CTX_KEY = Symbol.for("vinext.bfcacheSegmentIdContext");
37
- function getServerInsertedHTMLContext() {
38
- if (typeof React$1.createContext !== "function") return null;
39
- const globalState = globalThis;
40
- if (!globalState[_SERVER_INSERTED_HTML_CTX_KEY]) globalState[_SERVER_INSERTED_HTML_CTX_KEY] = React$1.createContext(null);
41
- return globalState[_SERVER_INSERTED_HTML_CTX_KEY] ?? null;
42
- }
43
- const ServerInsertedHTMLContext = getServerInsertedHTMLContext();
44
- /**
45
- * Get or create the layout segment context.
46
- * Returns null in the RSC environment (createContext unavailable).
47
- */
48
- function getLayoutSegmentContext() {
49
- if (typeof React$1.createContext !== "function") return null;
50
- const globalState = globalThis;
51
- if (!globalState[_LAYOUT_SEGMENT_CTX_KEY]) globalState[_LAYOUT_SEGMENT_CTX_KEY] = React$1.createContext({ children: [] });
52
- return globalState[_LAYOUT_SEGMENT_CTX_KEY] ?? null;
53
- }
54
- function getBfcacheIdMapContext() {
55
- if (typeof React$1.createContext !== "function") return null;
56
- const globalState = globalThis;
57
- if (!globalState[_BFCACHE_ID_MAP_CTX_KEY]) globalState[_BFCACHE_ID_MAP_CTX_KEY] = React$1.createContext(null);
58
- return globalState[_BFCACHE_ID_MAP_CTX_KEY] ?? null;
59
- }
60
- function getBfcacheSegmentIdContext() {
61
- if (typeof React$1.createContext !== "function") return null;
62
- const globalState = globalThis;
63
- if (!globalState[_BFCACHE_SEGMENT_ID_CTX_KEY]) globalState[_BFCACHE_SEGMENT_ID_CTX_KEY] = React$1.createContext(null);
64
- return globalState[_BFCACHE_SEGMENT_ID_CTX_KEY] ?? null;
65
- }
66
35
  /**
67
36
  * Read the child segments for a parallel route below the current layout.
68
37
  * Returns [] if no context is available (RSC environment, outside React tree)
@@ -80,77 +49,7 @@ function useChildSegments(parallelRoutesKey = "children") {
80
49
  const _READONLY_SEARCH_PARAMS = Symbol("vinext.navigation.readonlySearchParams");
81
50
  const _READONLY_SEARCH_PARAMS_SOURCE = Symbol("vinext.navigation.readonlySearchParamsSource");
82
51
  const _READONLY_SEARCH_PARAMS_SOURCE_KEY = Symbol("vinext.navigation.readonlySearchParamsSourceKey");
83
- const GLOBAL_ACCESSORS_KEY = Symbol.for("vinext.navigation.globalAccessors");
84
- const _GLOBAL_ACCESSORS_KEY = GLOBAL_ACCESSORS_KEY;
85
- const _GLOBAL_HYDRATION_CONTEXT_KEY = Symbol.for("vinext.navigation.clientHydrationContext");
86
- function _getGlobalAccessors() {
87
- return globalThis[_GLOBAL_ACCESSORS_KEY];
88
- }
89
- function _getClientHydrationContext() {
90
- const globalState = globalThis;
91
- if (Object.prototype.hasOwnProperty.call(globalState, _GLOBAL_HYDRATION_CONTEXT_KEY)) return globalState[_GLOBAL_HYDRATION_CONTEXT_KEY] ?? null;
92
- }
93
- function _setClientHydrationContext(ctx) {
94
- globalThis[_GLOBAL_HYDRATION_CONTEXT_KEY] = ctx;
95
- }
96
- function clearClientHydrationContext() {
97
- if (typeof window !== "undefined") _setClientHydrationContext(null);
98
- }
99
- let _serverContext = null;
100
- let _serverInsertedHTMLCallbacks = [];
101
- let _getServerContext = () => {
102
- if (typeof window !== "undefined") {
103
- const hydrationContext = _getClientHydrationContext();
104
- return hydrationContext !== void 0 ? hydrationContext : _serverContext;
105
- }
106
- const g = _getGlobalAccessors();
107
- return g ? g.getServerContext() : _serverContext;
108
- };
109
- let _setServerContext = (ctx) => {
110
- if (typeof window !== "undefined") {
111
- _serverContext = ctx;
112
- _setClientHydrationContext(ctx);
113
- return;
114
- }
115
- const g = _getGlobalAccessors();
116
- if (g) g.setServerContext(ctx);
117
- else _serverContext = ctx;
118
- };
119
- let _getInsertedHTMLCallbacks = () => {
120
- const g = _getGlobalAccessors();
121
- return g ? g.getInsertedHTMLCallbacks() : _serverInsertedHTMLCallbacks;
122
- };
123
- let _clearInsertedHTMLCallbacks = () => {
124
- const g = _getGlobalAccessors();
125
- if (g) g.clearInsertedHTMLCallbacks();
126
- else _serverInsertedHTMLCallbacks = [];
127
- };
128
- /**
129
- * Register ALS-backed state accessors. Called by navigation-state.ts on import.
130
- * @internal
131
- */
132
- function _registerStateAccessors(accessors) {
133
- _getServerContext = accessors.getServerContext;
134
- _setServerContext = accessors.setServerContext;
135
- _getInsertedHTMLCallbacks = accessors.getInsertedHTMLCallbacks;
136
- _clearInsertedHTMLCallbacks = accessors.clearInsertedHTMLCallbacks;
137
- }
138
52
  const PAGES_NAVIGATION_NOTIFY_KEY = Symbol.for("vinext.navigation.pagesNavigationNotify");
139
- /**
140
- * Get the navigation context for the current SSR/RSC render.
141
- * Reads from AsyncLocalStorage when available (concurrent-safe),
142
- * otherwise falls back to module-level state.
143
- */
144
- function getNavigationContext() {
145
- return _getServerContext();
146
- }
147
- /**
148
- * Set the navigation context for the current SSR/RSC render.
149
- * Called by the framework entry before rendering each request.
150
- */
151
- function setNavigationContext(ctx) {
152
- _setServerContext(ctx);
153
- }
154
53
  const isServer = typeof window === "undefined";
155
54
  /** basePath from next.config.js, injected by the plugin at build time */
156
55
  const __basePath = process.env.__NEXT_ROUTER_BASEPATH ?? "";
@@ -625,7 +524,7 @@ let _cachedEmptyClientSearchParams = null;
625
524
  * be visible until the next commit.
626
525
  */
627
526
  function getSearchParamsSnapshot() {
628
- if (_getServerContext()) return getServerSearchParamsSnapshot();
527
+ if (getNavigationContext()) return getServerSearchParamsSnapshot();
629
528
  const pagesCtx = getPagesNavigationContext();
630
529
  if (pagesCtx) return getReadonlyPagesSearchParams(pagesCtx.searchParams);
631
530
  const cached = getClientNavigationState()?.cachedReadonlySearchParams;
@@ -651,7 +550,7 @@ function syncCommittedUrlStateFromLocation() {
651
550
  return changed;
652
551
  }
653
552
  function getServerSearchParamsSnapshot() {
654
- const ctx = _getServerContext();
553
+ const ctx = getNavigationContext();
655
554
  if (!ctx) {
656
555
  const pagesCtx = getPagesNavigationContext();
657
556
  if (pagesCtx) return getReadonlyPagesSearchParams(pagesCtx.searchParams);
@@ -776,14 +675,14 @@ function clearPendingPathname(navId) {
776
675
  }
777
676
  function getClientParamsSnapshot() {
778
677
  const state = getClientNavigationState();
779
- const ctx = _getServerContext();
678
+ const ctx = getNavigationContext();
780
679
  if (ctx) return ctx.params;
781
680
  const pagesCtx = getPagesNavigationContext();
782
681
  if (pagesCtx) return pagesCtx.params;
783
682
  return state?.clientParams ?? _EMPTY_PARAMS;
784
683
  }
785
684
  function getServerParamsSnapshot() {
786
- const ctx = _getServerContext();
685
+ const ctx = getNavigationContext();
787
686
  if (ctx) return ctx.params;
788
687
  const pagesCtx = getPagesNavigationContext();
789
688
  if (pagesCtx) return pagesCtx.params;
@@ -804,14 +703,14 @@ function subscribeToNavigation(cb) {
804
703
  function usePathname() {
805
704
  if (isServer) {
806
705
  markPprFallbackShellDynamicBoundary();
807
- const ctx = _getServerContext();
706
+ const ctx = getNavigationContext();
808
707
  if (ctx) return ctx.pathname;
809
708
  const pagesCtx = getPagesNavigationContext();
810
709
  return pagesCtx ? pagesCtx.pathname : "/";
811
710
  }
812
711
  const renderSnapshot = useClientNavigationRenderSnapshot();
813
712
  const pathname = React$1.useSyncExternalStore(subscribeToNavigation, getPathnameSnapshot, () => {
814
- const ctx = _getServerContext();
713
+ const ctx = getNavigationContext();
815
714
  if (ctx) return ctx.pathname;
816
715
  const pagesCtx = getPagesNavigationContext();
817
716
  return pagesCtx ? pagesCtx.pathname : "/";
@@ -1272,337 +1171,7 @@ function useSelectedLayoutSegments(parallelRoutesKey) {
1272
1171
  */
1273
1172
  function useServerInsertedHTML(callback) {
1274
1173
  if (typeof document !== "undefined") return;
1275
- _getInsertedHTMLCallbacks().push(callback);
1276
- }
1277
- /**
1278
- * Flush all collected useServerInsertedHTML callbacks.
1279
- * Returns an array of results (React elements or strings).
1280
- * Clears the callback list so the next render starts fresh.
1281
- *
1282
- * Called by the SSR entry after renderToReadableStream completes.
1283
- */
1284
- function flushServerInsertedHTML() {
1285
- const callbacks = _getInsertedHTMLCallbacks();
1286
- const results = [];
1287
- for (const cb of callbacks) try {
1288
- const result = cb();
1289
- if (result != null) results.push(result);
1290
- } catch {}
1291
- callbacks.length = 0;
1292
- return results;
1293
- }
1294
- /**
1295
- * Render collected useServerInsertedHTML callbacks without unregistering them.
1296
- *
1297
- * Streaming SSR needs to invoke the same style-registry callbacks after each
1298
- * Fizz flush. Libraries such as styled-components and Emotion clear their own
1299
- * per-flush buffers inside the callback; the registration itself must survive
1300
- * until the request stream is closed.
1301
- */
1302
- function renderServerInsertedHTML() {
1303
- const callbacks = _getInsertedHTMLCallbacks();
1304
- const results = [];
1305
- for (const cb of callbacks) try {
1306
- const result = cb();
1307
- if (result != null) results.push(result);
1308
- } catch {}
1309
- return results;
1310
- }
1311
- /**
1312
- * Clear all collected useServerInsertedHTML callbacks without flushing.
1313
- * Used for cleanup between requests.
1314
- */
1315
- function clearServerInsertedHTML() {
1316
- _clearInsertedHTMLCallbacks();
1317
- }
1318
- /**
1319
- * HTTP Access Fallback error code — shared prefix for notFound/forbidden/unauthorized.
1320
- * Matches Next.js 16's unified error handling approach.
1321
- */
1322
- const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
1323
- /**
1324
- * Check if an error is an HTTP Access Fallback error (notFound, forbidden, unauthorized).
1325
- */
1326
- function isHTTPAccessFallbackError(error) {
1327
- if (error && typeof error === "object" && "digest" in error) {
1328
- const digest = String(error.digest);
1329
- return digest === "NEXT_NOT_FOUND" || digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`);
1330
- }
1331
- return false;
1332
- }
1333
- /**
1334
- * Extract the HTTP status code from an HTTP Access Fallback error.
1335
- * Returns 404 for legacy NEXT_NOT_FOUND errors.
1336
- */
1337
- function getAccessFallbackHTTPStatus(error) {
1338
- if (error && typeof error === "object" && "digest" in error) {
1339
- const digest = String(error.digest);
1340
- if (digest === "NEXT_NOT_FOUND") return 404;
1341
- if (digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`)) return parseInt(digest.split(";")[1], 10);
1342
- }
1343
- return 404;
1344
- }
1345
- /**
1346
- * Enum matching Next.js RedirectType for type-safe redirect calls.
1347
- */
1348
- let RedirectType = /* @__PURE__ */ function(RedirectType) {
1349
- RedirectType["push"] = "push";
1350
- RedirectType["replace"] = "replace";
1351
- return RedirectType;
1352
- }({});
1353
- /**
1354
- * Internal error class used by redirect/notFound/forbidden/unauthorized.
1355
- * The `digest` field is the serialised control-flow signal read by the
1356
- * framework's error boundary and server-side request handlers.
1357
- */
1358
- var VinextNavigationError = class extends Error {
1359
- digest;
1360
- constructor(message, digest) {
1361
- super(message);
1362
- this.digest = digest;
1363
- }
1364
- };
1365
- /**
1366
- * Throw a redirect. Caught by the framework to send a redirect response.
1367
- *
1368
- * When `type` is omitted, the digest carries an empty sentinel so the
1369
- * catch site can resolve the default based on context:
1370
- * - Server Action context → "push" (Back button works after form submission)
1371
- * - SSR render context → "replace"
1372
- *
1373
- * This matches Next.js behavior where `redirect()` checks
1374
- * `actionAsyncStorage.getStore()?.isAction` at call time.
1375
- *
1376
- * @see https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect.ts
1377
- */
1378
- function redirect(url, type) {
1379
- throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type ?? ""};${encodeURIComponent(url)}`);
1380
- }
1381
- /**
1382
- * Trigger a permanent redirect (308).
1383
- *
1384
- * Accepts an optional `type` parameter matching Next.js's signature.
1385
- * Defaults to "replace" (not context-dependent like `redirect()`).
1386
- *
1387
- * @see https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect.ts
1388
- */
1389
- function permanentRedirect(url, type = "replace") {
1390
- throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type};${encodeURIComponent(url)};308`);
1391
- }
1392
- /**
1393
- * Trigger a not-found response (404). Caught by the framework.
1394
- */
1395
- function notFound() {
1396
- throw new VinextNavigationError("NEXT_NOT_FOUND", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);
1397
- }
1398
- /**
1399
- * Trigger a forbidden response (403). Caught by the framework.
1400
- * In Next.js, this is gated behind experimental.authInterrupts — we
1401
- * support it unconditionally for maximum compatibility.
1402
- */
1403
- function forbidden() {
1404
- throw new VinextNavigationError("NEXT_FORBIDDEN", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);
1405
- }
1406
- /**
1407
- * Trigger an unauthorized response (401). Caught by the framework.
1408
- * In Next.js, this is gated behind experimental.authInterrupts — we
1409
- * support it unconditionally for maximum compatibility.
1410
- */
1411
- function unauthorized() {
1412
- throw new VinextNavigationError("NEXT_UNAUTHORIZED", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);
1413
- }
1414
- /**
1415
- * Check whether an error was produced by `redirect()` or `permanentRedirect()`.
1416
- *
1417
- * **Note on vinext public surface:** Next.js does NOT expose `isRedirectError`
1418
- * from `next/navigation` — it's an internal predicate. vinext exposes it for
1419
- * symmetry with the already-public `isHTTPAccessFallbackError` and because
1420
- * `unstable_rethrow` consumers benefit from being able to narrow types.
1421
- * Treat it as a vinext-only extension.
1422
- *
1423
- * **Divergence from Next.js:** Next.js's internal `isRedirectError` performs
1424
- * full 4-segment validation — it splits the digest on `;`, checks `type` ∈
1425
- * {push, replace}, requires a non-empty destination, and validates the
1426
- * status code (303, 307, 308). See:
1427
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect-error.ts
1428
- *
1429
- * vinext instead uses a simple prefix check (`startsWith("NEXT_REDIRECT;")`).
1430
- * Reasons:
1431
- * 1. vinext emits two digest shapes — 3-part for `redirect()`
1432
- * (`NEXT_REDIRECT;{type};{encoded-url}`) and 4-part for
1433
- * `permanentRedirect()` (`NEXT_REDIRECT;{type};{encoded-url};308`).
1434
- * Strict validation would have to special-case both, and Next.js's
1435
- * validator (tuned to its 5-part canary digests) rejects them.
1436
- * 2. The `type` field is sometimes empty in vinext's redirect digests
1437
- * (context-dependent resolution; see `redirect()` above), which the
1438
- * strict check disallows.
1439
- *
1440
- * **Consequence:** A malformed digest such as `"NEXT_REDIRECT;garbage"`
1441
- * returns `true` here, whereas Next.js would return `false`. In practice,
1442
- * the only callers of this predicate are vinext-internal code paths
1443
- * (`unstable_rethrow`, `unstable_catchError`, the redirect error boundary)
1444
- * that see digests vinext itself emits — so the divergence does not surface
1445
- * in normal use. Maintainers extending the prefix logic should keep this
1446
- * predicate in lockstep with the corresponding `decode*` helpers in
1447
- * `shims/error-boundary.tsx`.
1448
- */
1449
- function isRedirectError(error) {
1450
- if (!error || typeof error !== "object") return false;
1451
- if (!("digest" in error)) return false;
1452
- if (typeof error.digest !== "string") return false;
1453
- return error.digest.startsWith("NEXT_REDIRECT;");
1454
- }
1455
- /**
1456
- * Parse a redirect error digest into its URL and type components.
1457
- *
1458
- * Supports two formats:
1459
- * - vinext's 3-part: `NEXT_REDIRECT;{type};{encoded-url}`
1460
- * - Next.js's 5-part: `NEXT_REDIRECT;{type};{url};{status};{isClient}`
1461
- *
1462
- * The URL segment is always percent-encoded on the write side
1463
- * (encodeURIComponent is used), so re-joining with ";" for the 5-part
1464
- * format is defensive — it correctly handles any unencoded ";" that
1465
- * might appear in an externally-sourced digest.
1466
- *
1467
- * Returns null for malformed digests that have an empty URL segment, or
1468
- * when the URL contains invalid percent-encoding.
1469
- */
1470
- function decodeRedirectError(digest) {
1471
- if (!digest.startsWith("NEXT_REDIRECT;")) return null;
1472
- const parts = digest.split(";");
1473
- const encodedTarget = parts.length >= 5 ? parts.slice(2, -2).join(";") : parts[2];
1474
- if (!encodedTarget) return null;
1475
- let url;
1476
- try {
1477
- url = decodeURIComponent(encodedTarget);
1478
- } catch {
1479
- return null;
1480
- }
1481
- const type = parts[1] === "push" ? "push" : "replace";
1482
- return {
1483
- url,
1484
- type
1485
- };
1486
- }
1487
- /**
1488
- * Returns true if the error is a Next.js navigation signal — either a redirect
1489
- * or an HTTP access fallback (notFound / forbidden / unauthorized).
1490
- *
1491
- * **Note on vinext public surface:** Like `isRedirectError`, Next.js does NOT
1492
- * expose this from `next/navigation`. vinext exposes it for symmetry — treat
1493
- * it as a vinext-only extension.
1494
- *
1495
- * Ported from Next.js:
1496
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/is-next-router-error.ts
1497
- */
1498
- function isNextRouterError(error) {
1499
- return isRedirectError(error) || isHTTPAccessFallbackError(error);
1500
- }
1501
- const _BAILOUT_TO_CSR_DIGEST = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
1502
- /**
1503
- * Error thrown to bail out of server rendering and fall back to client-side
1504
- * rendering. Used by `next/dynamic` with `ssr: false`.
1505
- *
1506
- * vinext does not yet emit this error itself — it's exposed so user code and
1507
- * third-party libraries that mimic `next/dynamic`'s bailout semantics can
1508
- * construct an error with the canonical digest that `unstable_rethrow`
1509
- * recognises.
1510
- *
1511
- * Ported 1:1 from Next.js:
1512
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/lazy-dynamic/bailout-to-csr.ts
1513
- */
1514
- var BailoutToCSRError = class extends Error {
1515
- digest = _BAILOUT_TO_CSR_DIGEST;
1516
- reason;
1517
- constructor(reason) {
1518
- super(`Bail out to client-side rendering: ${reason}`);
1519
- this.reason = reason;
1520
- }
1521
- };
1522
- /**
1523
- * Returns true if the error is a `BailoutToCSRError`. Matches Next.js's
1524
- * digest-based predicate, so any error from a foreign module instance of
1525
- * the class (or constructed manually with the canonical digest) is also
1526
- * detected.
1527
- *
1528
- * **Note on vinext public surface:** Next.js does NOT expose this from
1529
- * `next/navigation`. vinext exposes it for symmetry with `isRedirectError`
1530
- * — treat it as a vinext-only extension. The matching producer
1531
- * (`BailoutToCSRError`) is the public detection contract; Next.js exposes
1532
- * neither.
1533
- *
1534
- * Ported from Next.js:
1535
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/lazy-dynamic/bailout-to-csr.ts
1536
- */
1537
- function isBailoutToCSRError(error) {
1538
- if (!error || typeof error !== "object" || !("digest" in error)) return false;
1539
- return error.digest === _BAILOUT_TO_CSR_DIGEST;
1540
- }
1541
- const _DYNAMIC_SERVER_USAGE_DIGEST = "DYNAMIC_SERVER_USAGE";
1542
- /**
1543
- * Error thrown when dynamic server APIs (`cookies()`, `headers()`, etc.) are
1544
- * used inside a static/prerender context. Carries the `DYNAMIC_SERVER_USAGE`
1545
- * digest so `unstable_rethrow` can recognise and propagate it.
1546
- *
1547
- * vinext does not construct this error itself — exposed for the same
1548
- * "stable detection contract" reason as `BailoutToCSRError` above.
1549
- *
1550
- * Ported 1:1 from Next.js:
1551
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/hooks-server-context.ts
1552
- */
1553
- var DynamicServerError = class extends Error {
1554
- digest = _DYNAMIC_SERVER_USAGE_DIGEST;
1555
- description;
1556
- constructor(description) {
1557
- super(`Dynamic server usage: ${description}`);
1558
- this.description = description;
1559
- }
1560
- };
1561
- /**
1562
- * Returns true if the error is a `DynamicServerError` (or any error with the
1563
- * canonical `DYNAMIC_SERVER_USAGE` digest).
1564
- *
1565
- * **Note on vinext public surface:** Next.js does NOT expose this from
1566
- * `next/navigation`. vinext exposes it for symmetry — treat it as a
1567
- * vinext-only extension.
1568
- *
1569
- * Ported from Next.js:
1570
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/hooks-server-context.ts
1571
- */
1572
- function isDynamicServerError(error) {
1573
- if (!error || typeof error !== "object" || !("digest" in error)) return false;
1574
- return error.digest === _DYNAMIC_SERVER_USAGE_DIGEST;
1575
- }
1576
- /**
1577
- * Rethrow internal Next.js errors so they're handled by the framework.
1578
- *
1579
- * When wrapping an API that uses errors for control flow (redirect, notFound,
1580
- * cookies in static render, `next/dynamic` SSR bailout, etc.), call this
1581
- * inside `catch` blocks before doing your own error handling. If the error
1582
- * is a Next.js internal error, it's rethrown; otherwise this is a no-op
1583
- * (apart from recursing through `error.cause`).
1584
- *
1585
- * Recognises (matches Next.js's browser build + the subset of the server
1586
- * build that vinext can realistically encounter):
1587
- * - `isNextRouterError`: redirect / notFound / forbidden / unauthorized
1588
- * - `isBailoutToCSRError`: `next/dynamic` `ssr: false` bailout
1589
- * - `isDynamicServerError`: dynamic API used in static render
1590
- *
1591
- * vinext does not yet recognise four additional server-only Next.js
1592
- * categories — `isDynamicPostpone`, `isPostpone`,
1593
- * `isHangingPromiseRejectionError`, `isPrerenderInterruptedError` — because
1594
- * they signal PPR / prerender-controller events that vinext's render
1595
- * pipeline does not generate. User code cannot construct these in normal
1596
- * use; they will be added if/when vinext grows PPR support.
1597
- *
1598
- * Ported from Next.js:
1599
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/unstable-rethrow.ts
1600
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/unstable-rethrow.server.ts
1601
- * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/unstable-rethrow.browser.ts
1602
- */
1603
- function unstable_rethrow(error) {
1604
- if (isNextRouterError(error) || isBailoutToCSRError(error) || isDynamicServerError(error)) throw error;
1605
- if (error instanceof Error && "cause" in error) unstable_rethrow(error.cause);
1174
+ registerServerInsertedHTMLCallback(callback);
1606
1175
  }
1607
1176
  if (!isServer) {
1608
1177
  const state = getClientNavigationState();
@@ -1,6 +1,6 @@
1
1
  import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
2
- import { BailoutToCSRError, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, NavigationContext, RedirectType, SegmentMap, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getLayoutSegmentContext, getNavigationContext, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, renderServerInsertedHTML, setNavigationContext, unauthorized, unstable_rethrow } from "./navigation.js";
3
-
2
+ import { GLOBAL_ACCESSORS_KEY, NavigationContext, SegmentMap, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, getLayoutSegmentContext, getNavigationContext, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
3
+ import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
4
4
  //#region src/shims/navigation.react-server.d.ts
5
5
  declare function usePathname(): never;
6
6
  declare function useSearchParams(): never;
@@ -1,5 +1,7 @@
1
+ import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, getLayoutSegmentContext, getNavigationContext, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
2
+ import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
3
+ import "./navigation-server.js";
1
4
  import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
2
- import { BailoutToCSRError, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getLayoutSegmentContext, getNavigationContext, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, renderServerInsertedHTML, setNavigationContext, unauthorized, unstable_rethrow } from "./navigation.js";
3
5
  import { throwClientHookError } from "./client-hook-error.js";
4
6
  //#region src/shims/navigation.react-server.ts
5
7
  function usePathname() {
@@ -1,11 +1,11 @@
1
- import { PrivateCacheState } from "./cache-runtime.js";
1
+ import { CacheLifeConfig, CacheState } from "./cache-request-state.js";
2
2
  import { ExecutionContextLike } from "./request-context.js";
3
- import { CacheLifeConfig, CacheState } from "./cache.js";
4
- import { NavigationContext } from "./navigation.js";
3
+ import { NavigationContext } from "./navigation-context-state.js";
5
4
  import { RootParamsState } from "./root-params.js";
6
5
  import { FetchCacheState } from "./fetch-cache.js";
7
6
  import { HeadersAccessPhase, HeadersContext, VinextHeadersShimState } from "./headers.js";
8
7
  import { RouterState, SSRContext } from "./router-state.js";
8
+ import { PrivateCacheState } from "./cache-runtime.js";
9
9
  import { HeadState } from "./head-state.js";
10
10
  import { I18nState } from "./i18n-state.js";
11
11
  import { NavigationState } from "./navigation-state.js";
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { escapeInlineContent } from "./head.js";
3
- import { hasAppNavigationRuntimeBootstrap } from "../client/navigation-runtime.js";
4
3
  import { useScriptNonce } from "./script-nonce-context.js";
4
+ import { hasAppNavigationRuntimeBootstrap } from "../client/navigation-runtime.js";
5
5
  import { useBeforeInteractiveRegister } from "./before-interactive-context.js";
6
6
  import React, { useEffect, useRef } from "react";
7
7
  import * as ReactDOM from "react-dom";
@@ -1,7 +1,9 @@
1
1
  "use client";
2
2
  import { AppElementsWire, UNMATCHED_SLOT } from "../server/app-elements-wire.js";
3
3
  import "../server/app-elements.js";
4
- import { getBfcacheIdMapContext, getBfcacheSegmentIdContext, notFound } from "./navigation.js";
4
+ import { getBfcacheIdMapContext, getBfcacheSegmentIdContext } from "./navigation-context-state.js";
5
+ import { notFound } from "./navigation-errors.js";
6
+ import "./navigation-server.js";
5
7
  import * as React$1 from "react";
6
8
  import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
7
9
  //#region src/shims/slot.tsx
@@ -1,10 +1,10 @@
1
- import { PrivateCacheState } from "./cache-runtime.js";
1
+ import { CacheState } from "./cache-request-state.js";
2
2
  import { ExecutionContextLike } from "./request-context.js";
3
- import { CacheState } from "./cache.js";
4
3
  import { RootParamsState } from "./root-params.js";
5
4
  import { FetchCacheState } from "./fetch-cache.js";
6
5
  import { VinextHeadersShimState } from "./headers.js";
7
6
  import { RouterState } from "./router-state.js";
7
+ import { PrivateCacheState } from "./cache-runtime.js";
8
8
  import { HeadState } from "./head-state.js";
9
9
  import { I18nState } from "./i18n-state.js";
10
10
  import { NavigationState } from "./navigation-state.js";
@@ -0,0 +1,5 @@
1
+ //#region src/utils/virtual-module.d.ts
2
+ declare const VIRTUAL_PREFIX = "\0";
3
+ declare const VIRTUAL_MODULE_ID_RE: RegExp;
4
+ //#endregion
5
+ export { VIRTUAL_MODULE_ID_RE, VIRTUAL_PREFIX };
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vinext",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Run Next.js apps on Vite. Drop-in replacement for the next CLI.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -57,6 +57,10 @@
57
57
  "types": "./dist/server/app-router-entry.d.ts",
58
58
  "import": "./dist/server/app-router-entry.js"
59
59
  },
60
+ "./server/app-rsc-handler": {
61
+ "types": "./dist/server/app-rsc-handler.d.ts",
62
+ "import": "./dist/server/app-rsc-handler.js"
63
+ },
60
64
  "./config/config-matchers": {
61
65
  "types": "./dist/config/config-matchers.d.ts",
62
66
  "import": "./dist/config/config-matchers.js"