vinext 0.1.4 → 0.1.6

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 (176) hide show
  1. package/README.md +2 -2
  2. package/dist/build/css-url-assets.d.ts +1 -1
  3. package/dist/build/css-url-assets.js +9 -7
  4. package/dist/build/google-fonts/find-font-files-in-css.d.ts +16 -0
  5. package/dist/build/google-fonts/find-font-files-in-css.js +28 -0
  6. package/dist/build/prerender.js +2 -1
  7. package/dist/build/report.d.ts +1 -2
  8. package/dist/build/report.js +2 -11
  9. package/dist/build/run-prerender.js +1 -1
  10. package/dist/cache/cache-adapters-virtual.js +1 -1
  11. package/dist/check.js +3 -3
  12. package/dist/client/pages-router-link-navigation.d.ts +10 -0
  13. package/dist/client/pages-router-link-navigation.js +3 -3
  14. package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +1 -1
  15. package/dist/deploy.js +3 -3
  16. package/dist/entries/app-rsc-entry.js +25 -20
  17. package/dist/entries/app-rsc-manifest.js +76 -46
  18. package/dist/entries/pages-server-entry.js +3 -1
  19. package/dist/index.js +254 -198
  20. package/dist/init.d.ts +5 -4
  21. package/dist/init.js +27 -8
  22. package/dist/plugins/css-data-url.js +30 -26
  23. package/dist/plugins/extensionless-dynamic-import.js +27 -24
  24. package/dist/plugins/fonts.js +3 -1
  25. package/dist/plugins/import-meta-url.js +21 -15
  26. package/dist/plugins/instrumentation-client.js +1 -1
  27. package/dist/plugins/middleware-export-validation.d.ts +5 -0
  28. package/dist/plugins/middleware-export-validation.js +36 -0
  29. package/dist/plugins/middleware-server-only.js +7 -6
  30. package/dist/plugins/og-asset-ownership.d.ts +27 -0
  31. package/dist/plugins/og-asset-ownership.js +285 -0
  32. package/dist/plugins/og-assets.js +66 -46
  33. package/dist/plugins/optimize-imports.js +9 -3
  34. package/dist/plugins/remove-console.d.ts +7 -1
  35. package/dist/plugins/remove-console.js +4 -1
  36. package/dist/plugins/require-context.js +21 -20
  37. package/dist/plugins/strip-server-exports.d.ts +7 -1
  38. package/dist/plugins/strip-server-exports.js +4 -1
  39. package/dist/server/accept-encoding.d.ts +29 -0
  40. package/dist/server/accept-encoding.js +95 -0
  41. package/dist/server/app-bfcache-identity.d.ts +26 -0
  42. package/dist/server/app-bfcache-identity.js +127 -0
  43. package/dist/server/app-browser-entry.js +17 -11
  44. package/dist/server/app-browser-rsc-redirect.d.ts +2 -1
  45. package/dist/server/app-browser-rsc-redirect.js +8 -1
  46. package/dist/server/app-browser-state.d.ts +2 -21
  47. package/dist/server/app-browser-state.js +4 -128
  48. package/dist/server/app-browser-stream.js +1 -1
  49. package/dist/server/app-browser-visible-commit.js +3 -2
  50. package/dist/server/app-fallback-renderer.d.ts +1 -1
  51. package/dist/server/app-layout-param-observation.d.ts +1 -1
  52. package/dist/server/app-layout-param-observation.js +1 -1
  53. package/dist/server/app-middleware.d.ts +1 -0
  54. package/dist/server/app-middleware.js +3 -1
  55. package/dist/server/app-page-boundary-render.d.ts +1 -1
  56. package/dist/server/app-page-boundary.js +1 -1
  57. package/dist/server/app-page-cache-finalizer.d.ts +62 -0
  58. package/dist/server/app-page-cache-finalizer.js +122 -0
  59. package/dist/server/app-page-cache-render.d.ts +2 -2
  60. package/dist/server/app-page-cache-render.js +1 -1
  61. package/dist/server/app-page-cache.d.ts +2 -53
  62. package/dist/server/app-page-cache.js +5 -131
  63. package/dist/server/app-page-dispatch.d.ts +4 -4
  64. package/dist/server/app-page-dispatch.js +10 -8
  65. package/dist/server/app-page-head.js +2 -2
  66. package/dist/server/app-page-probe.js +3 -2
  67. package/dist/server/app-page-render-observation.js +2 -2
  68. package/dist/server/app-page-render.d.ts +3 -3
  69. package/dist/server/app-page-render.js +3 -2
  70. package/dist/server/app-page-request.d.ts +7 -0
  71. package/dist/server/app-page-request.js +19 -1
  72. package/dist/server/app-page-stream.d.ts +2 -9
  73. package/dist/server/app-page-stream.js +1 -35
  74. package/dist/server/app-prerender-endpoints.d.ts +3 -3
  75. package/dist/server/app-prerender-endpoints.js +3 -4
  76. package/dist/server/app-request-context.d.ts +1 -2
  77. package/dist/server/app-request-context.js +2 -1
  78. package/dist/server/app-route-handler-dispatch.js +3 -2
  79. package/dist/server/app-route-handler-execution.d.ts +1 -1
  80. package/dist/server/app-route-handler-execution.js +1 -1
  81. package/dist/server/app-route-handler-response.d.ts +1 -1
  82. package/dist/server/app-route-module-loader.d.ts +62 -14
  83. package/dist/server/app-route-module-loader.js +61 -10
  84. package/dist/server/app-router-entry.js +2 -1
  85. package/dist/server/app-rsc-handler.d.ts +7 -6
  86. package/dist/server/app-rsc-handler.js +51 -40
  87. package/dist/server/app-rsc-response-finalizer.js +1 -1
  88. package/dist/server/app-rsc-route-matching.d.ts +9 -0
  89. package/dist/server/app-rsc-route-matching.js +13 -0
  90. package/dist/server/app-server-action-execution.d.ts +1 -1
  91. package/dist/server/app-server-action-execution.js +5 -4
  92. package/dist/server/app-ssr-entry.d.ts +1 -1
  93. package/dist/server/app-ssr-entry.js +9 -7
  94. package/dist/server/app-ssr-router-instance.d.ts +6 -0
  95. package/dist/server/app-ssr-router-instance.js +24 -0
  96. package/dist/server/app-ssr-stream.js +1 -1
  97. package/dist/server/artifact-compatibility.js +1 -1
  98. package/dist/server/client-reuse-manifest.js +1 -1
  99. package/dist/server/defer-until-stream-consumed.d.ts +7 -0
  100. package/dist/server/defer-until-stream-consumed.js +34 -0
  101. package/dist/server/dev-server.js +1 -1
  102. package/dist/server/headers.d.ts +5 -1
  103. package/dist/server/headers.js +5 -1
  104. package/dist/server/instrumentation.js +1 -1
  105. package/dist/server/isr-cache.d.ts +1 -1
  106. package/dist/server/isr-cache.js +1 -1
  107. package/dist/server/isr-decision.d.ts +1 -1
  108. package/dist/server/metadata-route-response.d.ts +3 -3
  109. package/dist/server/middleware-matcher.js +8 -6
  110. package/dist/server/middleware-runtime.d.ts +2 -1
  111. package/dist/server/middleware-runtime.js +21 -10
  112. package/dist/server/middleware.d.ts +2 -2
  113. package/dist/server/middleware.js +26 -11
  114. package/dist/server/open-redirect.d.ts +12 -0
  115. package/dist/server/open-redirect.js +21 -0
  116. package/dist/server/pages-page-data.d.ts +1 -1
  117. package/dist/server/pages-page-response.d.ts +1 -1
  118. package/dist/server/pages-page-response.js +2 -2
  119. package/dist/server/pages-request-pipeline.d.ts +3 -1
  120. package/dist/server/pages-request-pipeline.js +4 -2
  121. package/dist/server/prod-server.d.ts +1 -1
  122. package/dist/server/prod-server.js +87 -73
  123. package/dist/server/request-pipeline.d.ts +1 -24
  124. package/dist/server/request-pipeline.js +1 -33
  125. package/dist/server/seed-cache.d.ts +1 -1
  126. package/dist/shims/cache-handler.d.ts +106 -0
  127. package/dist/shims/cache-handler.js +176 -0
  128. package/dist/shims/cache-request-state.d.ts +47 -0
  129. package/dist/shims/cache-request-state.js +126 -0
  130. package/dist/shims/cache-runtime.d.ts +2 -2
  131. package/dist/shims/cache-runtime.js +3 -14
  132. package/dist/shims/cache.d.ts +3 -231
  133. package/dist/shims/cache.js +17 -383
  134. package/dist/shims/cdn-cache.d.ts +1 -1
  135. package/dist/shims/cdn-cache.js +1 -1
  136. package/dist/shims/error-boundary-navigation.d.ts +7 -0
  137. package/dist/shims/error-boundary-navigation.js +44 -0
  138. package/dist/shims/error-boundary.js +10 -8
  139. package/dist/shims/error.js +2 -1
  140. package/dist/shims/fetch-cache.js +1 -1
  141. package/dist/shims/font-google-base.d.ts +1 -0
  142. package/dist/shims/font-google-base.js +6 -21
  143. package/dist/shims/form.js +1 -1
  144. package/dist/shims/image.js +67 -9
  145. package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -0
  146. package/dist/shims/internal/app-page-props-cache-key.js +16 -0
  147. package/dist/shims/internal/interpolate-as.d.ts +25 -0
  148. package/dist/shims/internal/interpolate-as.js +196 -0
  149. package/dist/shims/internal/navigation-untracked.js +2 -1
  150. package/dist/shims/layout-segment-context.d.ts +1 -1
  151. package/dist/shims/layout-segment-context.js +2 -1
  152. package/dist/shims/link.js +26 -3
  153. package/dist/shims/navigation-context-state.d.ts +40 -0
  154. package/dist/shims/navigation-context-state.js +116 -0
  155. package/dist/shims/navigation-errors.d.ts +55 -0
  156. package/dist/shims/navigation-errors.js +110 -0
  157. package/dist/shims/navigation-server.d.ts +3 -0
  158. package/dist/shims/navigation-server.js +3 -0
  159. package/dist/shims/navigation-state.d.ts +1 -2
  160. package/dist/shims/navigation-state.js +2 -1
  161. package/dist/shims/navigation.d.ts +3 -291
  162. package/dist/shims/navigation.js +13 -444
  163. package/dist/shims/navigation.react-server.d.ts +2 -2
  164. package/dist/shims/navigation.react-server.js +4 -2
  165. package/dist/shims/request-state-types.d.ts +3 -3
  166. package/dist/shims/router.d.ts +1 -3
  167. package/dist/shims/router.js +62 -18
  168. package/dist/shims/script.js +1 -1
  169. package/dist/shims/slot.js +3 -1
  170. package/dist/shims/unified-request-context.d.ts +2 -2
  171. package/dist/typegen.js +2 -10
  172. package/dist/utils/project.d.ts +7 -1
  173. package/dist/utils/project.js +16 -2
  174. package/dist/utils/virtual-module.d.ts +5 -0
  175. package/dist/utils/virtual-module.js +0 -0
  176. package/package.json +7 -3
@@ -19,6 +19,7 @@ import { installWindowNext } from "../client/window-next.js";
19
19
  import { getWindowOrigin, isAbsoluteOrProtocolRelativeUrl, isHashOnlyBrowserUrlChange, normalizePathTrailingSlash, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
20
20
  import { scrollToHashTarget } from "./hash-scroll.js";
21
21
  import { installPagesRouterRuntime, setPagesRouterPopStateHandler, setStampInitialHistoryState } from "./pages-router-runtime.js";
22
+ import { interpolateDynamicRouteHref } from "./internal/interpolate-as.js";
22
23
  import { getCurrentBrowserLocale } from "./client-locale.js";
23
24
  import { Component, Fragment, createElement, useContext, useEffect, useLayoutEffect, useMemo, useState } from "react";
24
25
  //#region src/shims/router.ts
@@ -1118,7 +1119,7 @@ async function navigateClientHtml(url, fetchUrl, controller, navId, assertStillC
1118
1119
  * fixups). The JSON path derives its own URL from the browser-facing `url`
1119
1120
  * because the data endpoint speaks the unprefixed path.
1120
1121
  */
1121
- async function navigateClient(url, fetchUrl = url, options = {}) {
1122
+ async function navigateClient(url, fetchUrl = url, options = {}, routeUrl = url) {
1122
1123
  if (typeof window === "undefined") return;
1123
1124
  const previousAbortController = routerRuntimeState.activeAbortController;
1124
1125
  if (previousAbortController) queueMicrotask(() => previousAbortController.abort());
@@ -1135,7 +1136,7 @@ async function navigateClient(url, fetchUrl = url, options = {}) {
1135
1136
  else {
1136
1137
  let browserUrl = url;
1137
1138
  let htmlFetchUrl = fetchUrl;
1138
- let dataTarget = resolvePagesDataNavigationTarget(browserUrl, __basePath);
1139
+ let dataTarget = resolvePagesDataNavigationTarget(routeUrl, __basePath);
1139
1140
  let middlewareDataResponse;
1140
1141
  if (!dataTarget) {
1141
1142
  let middlewareEffect;
@@ -1178,9 +1179,9 @@ async function navigateClient(url, fetchUrl = url, options = {}) {
1178
1179
  * - "failed" — genuine error, caller should return false (hard nav is already
1179
1180
  * scheduled as recovery)
1180
1181
  */
1181
- async function runNavigateClient(fullUrl, resolvedUrl, fetchUrl = fullUrl, options = {}) {
1182
+ async function runNavigateClient(fullUrl, resolvedUrl, fetchUrl = fullUrl, options = {}, routeUrl = fullUrl) {
1182
1183
  try {
1183
- await navigateClient(fullUrl, fetchUrl, options);
1184
+ await navigateClient(fullUrl, fetchUrl, options, routeUrl);
1184
1185
  return "completed";
1185
1186
  } catch (err) {
1186
1187
  routerEvents.emit("routeChangeError", err, resolvedUrl, { shallow: false });
@@ -1252,9 +1253,9 @@ function updateHistory(mode, fullUrl, navState) {
1252
1253
  const previousKey = getRouterStateKey(window.history.state);
1253
1254
  const key = mode === "push" ? createHistoryKey() : previousKey ?? routerRuntimeState.currentHistoryKey ?? createHistoryKey();
1254
1255
  const state = {
1255
- url: navState?.url ?? fullUrl,
1256
- as: navState?.as ?? fullUrl,
1257
- options: navState?.options ?? {},
1256
+ url: navState.url,
1257
+ as: navState.as,
1258
+ options: navState.options,
1258
1259
  __N: true,
1259
1260
  key
1260
1261
  };
@@ -1300,8 +1301,13 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
1300
1301
  assertSafeNavigationUrl(resolveUrl(url));
1301
1302
  if (as !== void 0) assertSafeNavigationUrl(String(as));
1302
1303
  const navigationLocale = resolveTransitionLocale(options?.locale);
1303
- let resolved = resolveNavigationTarget(url, as, navigationLocale, as === void 0 && options?.locale !== void 0 && typeof url !== "string" && url.pathname === void 0 && (url.query !== void 0 && Object.keys(url.query).length > 0 || typeof url.search === "string" && url.search.length > 0 || typeof url.hash === "string" && url.hash.length > 0));
1304
- if (as === void 0 && (typeof url === "string" && options?._vinextInterpolateDynamicRoute === true || typeof url !== "string" && url.pathname === void 0 && (url.query !== void 0 && Object.keys(url.query).length > 0 || typeof url.search === "string" && url.search.length > 0))) resolved = interpolateCurrentDynamicRoute(resolved);
1304
+ const replaceInheritedLocale = as === void 0 && options?.locale !== void 0 && typeof url !== "string" && url.pathname === void 0 && (url.query !== void 0 && Object.keys(url.query).length > 0 || typeof url.search === "string" && url.search.length > 0 || typeof url.hash === "string" && url.hash.length > 0);
1305
+ let resolved = resolveNavigationTarget(url, as, navigationLocale, replaceInheritedLocale);
1306
+ let resolvedRoute = applyNavigationLocale(resolveUrl(url), navigationLocale, replaceInheritedLocale);
1307
+ if (as === void 0 && (typeof url === "string" && options?._vinextInterpolateDynamicRoute === true || typeof url !== "string" && url.pathname === void 0 && (url.query !== void 0 && Object.keys(url.query).length > 0 || typeof url.search === "string" && url.search.length > 0))) {
1308
+ resolved = interpolateCurrentDynamicRoute(resolved);
1309
+ resolvedRoute = interpolateCurrentDynamicRoute(resolvedRoute);
1310
+ }
1305
1311
  if (isExternalUrl(resolved)) {
1306
1312
  const localPath = toSameOriginAppPath(resolved, __basePath);
1307
1313
  if (localPath == null) {
@@ -1311,10 +1317,36 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
1311
1317
  }
1312
1318
  resolved = localPath;
1313
1319
  }
1320
+ if (isExternalUrl(resolvedRoute)) {
1321
+ const localPath = toSameOriginAppPath(resolvedRoute, __basePath);
1322
+ if (localPath != null) resolvedRoute = localPath;
1323
+ }
1314
1324
  resolved = normalizePathTrailingSlash(resolved, __trailingSlash);
1325
+ resolvedRoute = normalizePathTrailingSlash(resolvedRoute, __trailingSlash);
1326
+ let interpolatedRoute = resolvedRoute;
1327
+ if (resolvedRoute.includes("[")) {
1328
+ const projection = interpolateDynamicRouteHref(resolvedRoute, resolved, typeof url === "string" ? void 0 : url.query);
1329
+ if (projection?.href) {
1330
+ interpolatedRoute = projection.href;
1331
+ if (as === void 0 && stripHash(resolved).split("?", 1)[0] === projection.routePathname) {
1332
+ const remaining = new URLSearchParams();
1333
+ const consumed = new Set(projection.params);
1334
+ for (const [k, v] of Object.entries(projection.query)) {
1335
+ if (consumed.has(k)) continue;
1336
+ if (v === void 0) continue;
1337
+ if (Array.isArray(v)) v.forEach((entry) => remaining.append(k, entry));
1338
+ else remaining.append(k, v);
1339
+ }
1340
+ const searchStr = remaining.toString();
1341
+ const hashStr = extractHash(resolved);
1342
+ resolved = normalizePathTrailingSlash(`${projection.href.split(/[?#]/, 1)[0]}${searchStr ? `?${searchStr}` : ""}${hashStr}`, __trailingSlash);
1343
+ }
1344
+ } else interpolatedRoute = resolved;
1345
+ }
1315
1346
  const full = normalizePathTrailingSlash(toBrowserNavigationHref(resolved, window.location.href, __basePath), __trailingSlash);
1347
+ const fullRouteUrl = interpolatedRoute !== resolved ? normalizePathTrailingSlash(toBrowserNavigationHref(interpolatedRoute, window.location.href, __basePath), __trailingSlash) : full;
1316
1348
  const errorRouteHtmlFetchUrl = resolvePagesErrorHtmlFetchUrl(url, navigationLocale);
1317
- const htmlFetchUrl = errorRouteHtmlFetchUrl ?? getPagesHtmlFetchUrl(full, navigationLocale);
1349
+ const htmlFetchUrl = errorRouteHtmlFetchUrl ?? getPagesHtmlFetchUrl(fullRouteUrl, navigationLocale);
1318
1350
  const shallow = options?.shallow ?? false;
1319
1351
  const doScroll = options?.scroll !== false;
1320
1352
  const hash = extractHash(resolved);
@@ -1330,15 +1362,17 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
1330
1362
  mode,
1331
1363
  scroll: scrollTarget
1332
1364
  };
1365
+ const currentLocale = getCurrentUrlLocale();
1366
+ if (mode === "push" && interpolatedRoute !== resolved && stripHash(full) === routerRuntimeState.lastPathnameAndSearch && navigationLocale === currentLocale) mode = "replace";
1333
1367
  const navStateOptions = { shallow };
1334
1368
  if (navigationLocale !== void 0) navStateOptions.locale = navigationLocale;
1335
1369
  const resolvedNoHash = stripHash(resolved);
1336
1370
  const navState = {
1337
- url: resolvedNoHash,
1371
+ url: stripHash(interpolatedRoute),
1338
1372
  as: resolvedNoHash,
1339
1373
  options: navStateOptions
1340
1374
  };
1341
- if (options?._h !== 1 && isHashOnlyChange(full)) {
1375
+ if (options?._h !== 1 && interpolatedRoute === resolved && isHashOnlyChange(full)) {
1342
1376
  if (mode === "push") saveScrollPosition();
1343
1377
  const eventUrl = resolveHashUrl(full);
1344
1378
  routerEvents.emit("hashChangeStart", eventUrl, { shallow });
@@ -1363,7 +1397,7 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
1363
1397
  routerEvents.emit("beforeHistoryChange", resolved, { shallow });
1364
1398
  updateHistory(mode, full, navState);
1365
1399
  if (!shallow) {
1366
- const result = await runNavigateClient(full, resolved, htmlFetchUrl, navigateOptions);
1400
+ const result = await runNavigateClient(full, resolved, htmlFetchUrl, navigateOptions, fullRouteUrl);
1367
1401
  if (result === "cancelled") return true;
1368
1402
  if (result === "failed") return false;
1369
1403
  } else if (doScroll) if (hash) scrollToHashTarget(hash);
@@ -1479,7 +1513,7 @@ function PagesRouterProvider({ children }) {
1479
1513
  return AppRouterContext ? createElement(AppRouterContext.Provider, { value: appRouter }, content) : content;
1480
1514
  }
1481
1515
  function isNextRouterState(state) {
1482
- return typeof state === "object" && state !== null && "__N" in state && state.__N === true;
1516
+ return typeof state === "object" && state !== null && "__N" in state && state.__N === true && "url" in state && typeof state.url === "string" && "as" in state && typeof state.as === "string" && "options" in state && typeof state.options === "object" && state.options !== null;
1483
1517
  }
1484
1518
  function getRouterStateKey(state) {
1485
1519
  if (!isNextRouterState(state)) return void 0;
@@ -1508,11 +1542,16 @@ function handlePagesRouterPopState(e) {
1508
1542
  };
1509
1543
  }
1510
1544
  if (routerRuntimeState.beforePopStateCb !== void 0) {
1511
- if (!routerRuntimeState.beforePopStateCb({
1545
+ const beforePopStateState = isNextRouterState(state) ? {
1546
+ url: state.url,
1547
+ as: state.as,
1548
+ options: state.options
1549
+ } : {
1512
1550
  url: appUrl,
1513
1551
  as: appUrl,
1514
1552
  options: { shallow: false }
1515
- })) return;
1553
+ };
1554
+ if (!routerRuntimeState.beforePopStateCb({ ...beforePopStateState })) return;
1516
1555
  }
1517
1556
  if (targetKey !== void 0) routerRuntimeState.currentHistoryKey = targetKey;
1518
1557
  routerRuntimeState.lastPathnameAndSearch = browserUrl;
@@ -1524,7 +1563,8 @@ function handlePagesRouterPopState(e) {
1524
1563
  dispatchNavigateEvent();
1525
1564
  return;
1526
1565
  }
1527
- const effectiveLocale = (isNextRouterState(state) ? state.options?.locale : void 0) ?? window.__VINEXT_LOCALE__;
1566
+ const stateLocale = isNextRouterState(state) ? state.options?.locale : void 0;
1567
+ const effectiveLocale = typeof stateLocale === "string" ? stateLocale : window.__VINEXT_LOCALE__;
1528
1568
  const fullAppUrl = appUrl + window.location.hash;
1529
1569
  routerEvents.emit("routeChangeStart", fullAppUrl, { shallow: false });
1530
1570
  routerEvents.emit("beforeHistoryChange", fullAppUrl, { shallow: false });
@@ -1533,7 +1573,11 @@ function handlePagesRouterPopState(e) {
1533
1573
  x: 0,
1534
1574
  y: 0
1535
1575
  } : readScrollPosition(state);
1536
- if (await runNavigateClient(browserUrl, fullAppUrl, getPagesHtmlFetchUrl(browserUrl, effectiveLocale), { scroll: scrollTarget }) === "completed") {
1576
+ const stateRouteUrl = (() => {
1577
+ if (isNextRouterState(state) && typeof state.url === "string" && typeof state.as === "string" && state.url !== state.as) return normalizePathTrailingSlash(withBasePath(state.url, __basePath), __trailingSlash);
1578
+ return browserUrl;
1579
+ })();
1580
+ if (await runNavigateClient(browserUrl, fullAppUrl, getPagesHtmlFetchUrl(stateRouteUrl, effectiveLocale), { scroll: scrollTarget }, stateRouteUrl) === "completed") {
1537
1581
  routerEvents.emit("routeChangeComplete", fullAppUrl, { shallow: false });
1538
1582
  dispatchNavigateEvent();
1539
1583
  }
@@ -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";
package/dist/typegen.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { findDir } from "./utils/project.js";
1
2
  import { decodeRouteSegment, isInvisibleSegment } from "./routing/utils.js";
2
3
  import { patternToNextFormat } from "./routing/route-validation.js";
3
4
  import { compareStrings } from "./utils/compare.js";
@@ -15,7 +16,7 @@ import "./.next/types/routes.d.ts";
15
16
  `;
16
17
  async function generateRouteTypes(options) {
17
18
  const root = path.resolve(options.root);
18
- const appDir = options.appDir ? path.resolve(options.appDir) : await findAppDir(root);
19
+ const appDir = options.appDir ? path.resolve(options.appDir) : findDir(root, "app", path.join("src", "app"));
19
20
  const outPath = path.join(root, ".next", "types", "routes.d.ts");
20
21
  const content = appDir ? renderRouteTypes(await collectRouteTypeModel(appDir, options.pageExtensions)) : renderRouteTypes(emptyRouteTypeModel());
21
22
  await fs.mkdir(path.dirname(outPath), { recursive: true });
@@ -84,15 +85,6 @@ async function collectRouteTypeModel(appDir, pageExtensions) {
84
85
  for (const slotNames of model.layoutSlots.values()) slotNames.sort(compareStrings);
85
86
  return model;
86
87
  }
87
- async function findAppDir(root) {
88
- for (const rel of ["app", path.join("src", "app")]) {
89
- const candidate = path.join(root, rel);
90
- try {
91
- if ((await fs.stat(candidate)).isDirectory()) return candidate;
92
- } catch {}
93
- }
94
- return null;
95
- }
96
88
  function renderRouteTypes(model) {
97
89
  const allRoutes = uniqueSorted([
98
90
  ...model.pageRoutes,
@@ -62,9 +62,15 @@ declare function findInNodeModules(start: string, subPath: string): string | nul
62
62
  * Check if a vite.config file exists in the project root.
63
63
  */
64
64
  declare function hasViteConfig(root: string): boolean;
65
+ /**
66
+ * Return the first candidate directory (resolved against `root`) that exists,
67
+ * or null. Used to locate conventional `app`/`pages` directories that may live
68
+ * at the root or under `src/`.
69
+ */
70
+ declare function findDir(root: string, ...candidates: string[]): string | null;
65
71
  /**
66
72
  * Check if the project uses App Router (has an app/ directory).
67
73
  */
68
74
  declare function hasAppDir(root: string): boolean;
69
75
  //#endregion
70
- export { detectPackageManager, detectPackageManagerName, ensureESModule, ensureViteConfigCompatibility, findInNodeModules, hasAppDir, hasViteConfig, renameCJSConfigs };
76
+ export { detectPackageManager, detectPackageManagerName, ensureESModule, ensureViteConfigCompatibility, findDir, findInNodeModules, hasAppDir, hasViteConfig, renameCJSConfigs };
@@ -190,10 +190,24 @@ function hasViteConfig(root) {
190
190
  return fs.existsSync(path.join(root, "vite.config.ts")) || fs.existsSync(path.join(root, "vite.config.js")) || fs.existsSync(path.join(root, "vite.config.mjs"));
191
191
  }
192
192
  /**
193
+ * Return the first candidate directory (resolved against `root`) that exists,
194
+ * or null. Used to locate conventional `app`/`pages` directories that may live
195
+ * at the root or under `src/`.
196
+ */
197
+ function findDir(root, ...candidates) {
198
+ for (const candidate of candidates) {
199
+ const full = path.join(root, candidate);
200
+ try {
201
+ if (fs.statSync(full).isDirectory()) return full;
202
+ } catch {}
203
+ }
204
+ return null;
205
+ }
206
+ /**
193
207
  * Check if the project uses App Router (has an app/ directory).
194
208
  */
195
209
  function hasAppDir(root) {
196
- return fs.existsSync(path.join(root, "app")) || fs.existsSync(path.join(root, "src", "app"));
210
+ return findDir(root, "app", path.join("src", "app")) !== null;
197
211
  }
198
212
  //#endregion
199
- export { detectPackageManager, detectPackageManagerName, ensureESModule, ensureViteConfigCompatibility, findInNodeModules, hasAppDir, hasViteConfig, renameCJSConfigs };
213
+ export { detectPackageManager, detectPackageManagerName, ensureESModule, ensureViteConfigCompatibility, findDir, findInNodeModules, hasAppDir, hasViteConfig, renameCJSConfigs };
@@ -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.6",
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"
@@ -99,8 +103,8 @@
99
103
  "@vitejs/plugin-react": "^6.0.1",
100
104
  "@vitejs/plugin-rsc": "^0.5.27",
101
105
  "react-server-dom-webpack": "^19.2.7",
102
- "vite": "npm:@voidzero-dev/vite-plus-core@0.1.24",
103
- "vite-plus": "0.1.24",
106
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.2.1",
107
+ "vite-plus": "0.2.1",
104
108
  "@vinext/cloudflare": "0.1.2"
105
109
  },
106
110
  "peerDependencies": {