@qzsy/vinext 0.1.12 → 0.1.81

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 (231) hide show
  1. package/README.md +19 -5
  2. package/dist/build/inject-pregenerated-paths.d.ts +4 -0
  3. package/dist/build/inject-pregenerated-paths.js +18 -0
  4. package/dist/build/pages-client-assets-module.d.ts +11 -0
  5. package/dist/build/pages-client-assets-module.js +27 -0
  6. package/dist/build/prerender.d.ts +2 -1
  7. package/dist/build/prerender.js +11 -4
  8. package/dist/build/report.d.ts +2 -1
  9. package/dist/build/report.js +2 -1
  10. package/dist/build/run-prerender.d.ts +7 -0
  11. package/dist/build/run-prerender.js +9 -0
  12. package/dist/build/standalone.js +2 -0
  13. package/dist/check.d.ts +18 -0
  14. package/dist/check.js +77 -19
  15. package/dist/cli-dev-config.d.ts +12 -0
  16. package/dist/cli-dev-config.js +23 -0
  17. package/dist/cli.js +64 -28
  18. package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
  19. package/dist/{server → client}/dev-error-overlay-store.js +1 -1
  20. package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
  21. package/dist/{server → client}/dev-error-overlay.js +2 -2
  22. package/dist/cloudflare/deploy-config.d.ts +51 -0
  23. package/dist/cloudflare/deploy-config.js +153 -0
  24. package/dist/cloudflare/index.d.ts +1 -1
  25. package/dist/cloudflare/index.js +1 -1
  26. package/dist/cloudflare/project.d.ts +41 -0
  27. package/dist/cloudflare/project.js +243 -0
  28. package/dist/cloudflare/tpr.js +1 -1
  29. package/dist/config/config-matchers.js +14 -10
  30. package/dist/config/next-config.d.ts +6 -3
  31. package/dist/config/next-config.js +47 -1
  32. package/dist/config/server-external-packages.d.ts +4 -0
  33. package/dist/config/server-external-packages.js +91 -0
  34. package/dist/deploy.d.ts +2 -122
  35. package/dist/deploy.js +20 -793
  36. package/dist/entries/app-rsc-entry.d.ts +2 -1
  37. package/dist/entries/app-rsc-entry.js +70 -12
  38. package/dist/entries/app-rsc-manifest.js +8 -0
  39. package/dist/entries/pages-client-entry.d.ts +1 -0
  40. package/dist/entries/pages-client-entry.js +2 -1
  41. package/dist/entries/pages-server-entry.js +6 -2
  42. package/dist/image/image-adapters-virtual.d.ts +59 -0
  43. package/dist/image/image-adapters-virtual.js +50 -0
  44. package/dist/index.d.ts +12 -0
  45. package/dist/index.js +160 -160
  46. package/dist/init-cloudflare.d.ts +43 -0
  47. package/dist/init-cloudflare.js +1000 -0
  48. package/dist/init-platform.d.ts +38 -0
  49. package/dist/init-platform.js +150 -0
  50. package/dist/init.d.ts +14 -37
  51. package/dist/init.js +205 -95
  52. package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
  53. package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
  54. package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
  55. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
  56. package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
  57. package/dist/plugins/ast-scope.d.ts +16 -0
  58. package/dist/plugins/ast-scope.js +62 -0
  59. package/dist/plugins/ast-utils.js +3 -0
  60. package/dist/plugins/css-module-imports.d.ts +14 -0
  61. package/dist/plugins/css-module-imports.js +59 -0
  62. package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
  63. package/dist/plugins/ignore-dynamic-requests.js +530 -0
  64. package/dist/plugins/middleware-server-only.d.ts +8 -6
  65. package/dist/plugins/middleware-server-only.js +8 -7
  66. package/dist/plugins/optimize-imports.js +1 -1
  67. package/dist/plugins/typeof-window.d.ts +1 -1
  68. package/dist/plugins/typeof-window.js +28 -56
  69. package/dist/routing/app-route-graph.d.ts +13 -2
  70. package/dist/routing/app-route-graph.js +116 -32
  71. package/dist/routing/app-router.d.ts +5 -0
  72. package/dist/routing/app-router.js +5 -0
  73. package/dist/routing/file-matcher.d.ts +8 -0
  74. package/dist/routing/file-matcher.js +10 -1
  75. package/dist/routing/pages-router.js +2 -2
  76. package/dist/server/app-browser-action-result.d.ts +2 -1
  77. package/dist/server/app-browser-action-result.js +5 -1
  78. package/dist/server/app-browser-entry.js +17 -12
  79. package/dist/server/app-browser-history-controller.d.ts +2 -1
  80. package/dist/server/app-browser-history-controller.js +6 -2
  81. package/dist/server/app-browser-interception-context.d.ts +1 -0
  82. package/dist/server/app-browser-interception-context.js +4 -2
  83. package/dist/server/app-browser-navigation-controller.js +1 -0
  84. package/dist/server/app-browser-server-action-client.js +2 -3
  85. package/dist/server/app-browser-state.d.ts +1 -0
  86. package/dist/server/app-browser-state.js +3 -2
  87. package/dist/server/app-fallback-renderer.d.ts +3 -2
  88. package/dist/server/app-fallback-renderer.js +12 -7
  89. package/dist/server/app-middleware.d.ts +2 -3
  90. package/dist/server/app-middleware.js +3 -2
  91. package/dist/server/app-optimistic-routing.js +1 -1
  92. package/dist/server/app-page-boundary-render.d.ts +1 -0
  93. package/dist/server/app-page-boundary-render.js +12 -3
  94. package/dist/server/app-page-cache-finalizer.d.ts +1 -0
  95. package/dist/server/app-page-cache-finalizer.js +10 -3
  96. package/dist/server/app-page-cache-render.d.ts +1 -0
  97. package/dist/server/app-page-cache-render.js +8 -4
  98. package/dist/server/app-page-cache.d.ts +1 -0
  99. package/dist/server/app-page-cache.js +4 -1
  100. package/dist/server/app-page-dispatch.d.ts +11 -3
  101. package/dist/server/app-page-dispatch.js +55 -15
  102. package/dist/server/app-page-element-builder.d.ts +5 -1
  103. package/dist/server/app-page-element-builder.js +57 -20
  104. package/dist/server/app-page-head.d.ts +12 -0
  105. package/dist/server/app-page-head.js +42 -19
  106. package/dist/server/app-page-params.d.ts +2 -1
  107. package/dist/server/app-page-params.js +8 -1
  108. package/dist/server/app-page-probe.d.ts +1 -0
  109. package/dist/server/app-page-probe.js +6 -1
  110. package/dist/server/app-page-render-identity.d.ts +1 -0
  111. package/dist/server/app-page-render-identity.js +1 -1
  112. package/dist/server/app-page-render.d.ts +4 -1
  113. package/dist/server/app-page-render.js +8 -3
  114. package/dist/server/app-page-request.d.ts +22 -1
  115. package/dist/server/app-page-request.js +89 -13
  116. package/dist/server/app-page-route-wiring.d.ts +6 -1
  117. package/dist/server/app-page-route-wiring.js +31 -15
  118. package/dist/server/app-page-search-params-observation.d.ts +4 -2
  119. package/dist/server/app-page-search-params-observation.js +11 -7
  120. package/dist/server/app-page-segment-state.js +2 -0
  121. package/dist/server/app-route-handler-dispatch.js +1 -0
  122. package/dist/server/app-route-handler-execution.js +7 -2
  123. package/dist/server/app-route-handler-response.js +1 -0
  124. package/dist/server/app-route-handler-runtime.js +1 -1
  125. package/dist/server/app-route-module-loader.d.ts +2 -0
  126. package/dist/server/app-route-module-loader.js +1 -0
  127. package/dist/server/app-router-entry.d.ts +12 -0
  128. package/dist/server/app-router-entry.js +22 -8
  129. package/dist/server/app-router-image-optimization.d.ts +37 -0
  130. package/dist/server/app-router-image-optimization.js +40 -0
  131. package/dist/server/app-rsc-errors.js +7 -1
  132. package/dist/server/app-rsc-handler.js +27 -14
  133. package/dist/server/app-rsc-route-matching.d.ts +7 -0
  134. package/dist/server/app-rsc-route-matching.js +36 -3
  135. package/dist/server/app-segment-config.d.ts +12 -0
  136. package/dist/server/app-segment-config.js +91 -5
  137. package/dist/server/app-server-action-execution.d.ts +5 -0
  138. package/dist/server/app-server-action-execution.js +106 -33
  139. package/dist/server/app-ssr-entry.js +12 -1
  140. package/dist/server/app-static-generation.d.ts +1 -0
  141. package/dist/server/app-static-generation.js +1 -0
  142. package/dist/server/client-trace-metadata.js +26 -0
  143. package/dist/server/default-global-not-found-module.d.ts +14 -0
  144. package/dist/server/default-global-not-found-module.js +14 -0
  145. package/dist/server/dev-response-headers.d.ts +19 -0
  146. package/dist/server/dev-response-headers.js +78 -0
  147. package/dist/server/dev-server.js +8 -15
  148. package/dist/server/dev-stack-sourcemap.d.ts +1 -1
  149. package/dist/server/dev-stack-sourcemap.js +1 -1
  150. package/dist/server/headers.d.ts +7 -15
  151. package/dist/server/headers.js +6 -15
  152. package/dist/server/image-optimization.d.ts +51 -1
  153. package/dist/server/image-optimization.js +52 -2
  154. package/dist/server/isr-cache.d.ts +1 -1
  155. package/dist/server/isr-cache.js +2 -2
  156. package/dist/server/middleware-runtime.js +6 -1
  157. package/dist/server/navigation-planner.d.ts +1 -0
  158. package/dist/server/navigation-planner.js +14 -3
  159. package/dist/server/pages-asset-tags.d.ts +4 -6
  160. package/dist/server/pages-asset-tags.js +12 -12
  161. package/dist/server/pages-client-assets.d.ts +12 -0
  162. package/dist/server/pages-client-assets.js +10 -0
  163. package/dist/server/pages-page-data.d.ts +23 -1
  164. package/dist/server/pages-page-data.js +43 -24
  165. package/dist/server/pages-page-handler.d.ts +2 -1
  166. package/dist/server/pages-page-handler.js +10 -4
  167. package/dist/server/pages-request-pipeline.d.ts +2 -0
  168. package/dist/server/pages-request-pipeline.js +25 -1
  169. package/dist/server/prerender-manifest.d.ts +3 -1
  170. package/dist/server/prerender-route-params.js +1 -1
  171. package/dist/server/prod-server.d.ts +1 -1
  172. package/dist/server/prod-server.js +47 -25
  173. package/dist/server/request-log.d.ts +5 -14
  174. package/dist/server/request-log.js +7 -1
  175. package/dist/server/request-pipeline.js +1 -0
  176. package/dist/server/seed-cache.js +4 -4
  177. package/dist/server/server-action-logger.d.ts +39 -0
  178. package/dist/server/server-action-logger.js +104 -0
  179. package/dist/server/worker-utils.d.ts +2 -1
  180. package/dist/server/worker-utils.js +7 -1
  181. package/dist/shims/app-router-scroll-state.d.ts +1 -0
  182. package/dist/shims/app-router-scroll-state.js +1 -0
  183. package/dist/shims/app-router-scroll.js +2 -1
  184. package/dist/shims/cache.js +19 -15
  185. package/dist/shims/cdn-cache.js +1 -1
  186. package/dist/shims/dynamic-preload-chunks.js +2 -1
  187. package/dist/shims/error-boundary.d.ts +19 -1
  188. package/dist/shims/error-boundary.js +11 -1
  189. package/dist/shims/form.d.ts +3 -1
  190. package/dist/shims/form.js +37 -43
  191. package/dist/shims/headers.d.ts +9 -1
  192. package/dist/shims/headers.js +31 -6
  193. package/dist/shims/image-optimization-url.d.ts +4 -0
  194. package/dist/shims/image-optimization-url.js +33 -1
  195. package/dist/shims/image.js +46 -13
  196. package/dist/shims/internal/app-route-detection.d.ts +2 -17
  197. package/dist/shims/internal/app-route-detection.js +4 -17
  198. package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
  199. package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
  200. package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -5
  201. package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
  202. package/dist/shims/internal/pages-router-components.d.ts +7 -0
  203. package/dist/shims/internal/pages-router-components.js +13 -0
  204. package/dist/shims/link.js +23 -16
  205. package/dist/shims/metadata.d.ts +3 -2
  206. package/dist/shims/metadata.js +8 -4
  207. package/dist/shims/navigation.js +4 -2
  208. package/dist/shims/root-params.d.ts +15 -1
  209. package/dist/shims/root-params.js +21 -1
  210. package/dist/shims/router.d.ts +2 -5
  211. package/dist/shims/router.js +41 -22
  212. package/dist/shims/server.js +3 -2
  213. package/dist/typegen.js +6 -5
  214. package/dist/utils/client-runtime-metadata.d.ts +2 -18
  215. package/dist/utils/client-runtime-metadata.js +31 -22
  216. package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
  217. package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
  218. package/dist/utils/domain-locale.d.ts +6 -3
  219. package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
  220. package/dist/{server → utils}/middleware-request-headers.js +2 -2
  221. package/dist/utils/path.d.ts +2 -1
  222. package/dist/utils/path.js +1 -1
  223. package/dist/utils/project.d.ts +9 -1
  224. package/dist/utils/project.js +21 -4
  225. package/dist/utils/protocol-headers.d.ts +17 -0
  226. package/dist/utils/protocol-headers.js +17 -0
  227. package/dist/utils/react-version.d.ts +4 -0
  228. package/dist/utils/react-version.js +44 -0
  229. package/package.json +29 -23
  230. package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
  231. /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
@@ -1,22 +1,7 @@
1
1
  import { removeTrailingSlash, stripBasePath } from "../../utils/base-path.js";
2
2
  import { getLocalePathPrefix } from "../../utils/domain-locale.js";
3
- import { resolveHybridClientRouteOwner } from "./hybrid-client-route-owner.js";
3
+ import { getPagesRouterComponentsMap } from "./pages-router-components.js";
4
4
  //#region src/shims/internal/app-route-detection.ts
5
- const _COMPONENTS_KEY = Symbol.for("vinext.pagesRouter.components");
6
- /**
7
- * Get-or-create the Pages Router `components` map. Returns the same object
8
- * on every call so `router.components` and `window.next.router.components`
9
- * have referential identity.
10
- */
11
- function getPagesRouterComponentsMap() {
12
- const globalState = globalThis;
13
- let components = globalState[_COMPONENTS_KEY];
14
- if (!components) {
15
- components = {};
16
- globalState[_COMPONENTS_KEY] = components;
17
- }
18
- return components;
19
- }
20
5
  /**
21
6
  * Resolve a prefetch href to a same-origin pathname (basePath-stripped),
22
7
  * suitable as the key used by Next.js for `router.components[urlPathname]`.
@@ -50,8 +35,10 @@ function resolveSameOriginPathname(href, basePath) {
50
35
  * first (e.g. `link.tsx` normalises to match `trailingSlash` config before
51
36
  * calling, while `router.prefetch()` passes the raw user-supplied URL).
52
37
  */
53
- function markAppRouteDetectedOnPrefetch(href, basePath) {
38
+ async function markAppRouteDetectedOnPrefetch(href, basePath) {
54
39
  if (typeof window === "undefined") return;
40
+ if (!window.__VINEXT_LINK_PREFETCH_ROUTES__?.length) return;
41
+ const { resolveHybridClientRouteOwner } = await import("./hybrid-client-route-owner.js");
55
42
  if (resolveHybridClientRouteOwner(href, basePath) !== "app") return;
56
43
  const rawPathname = resolveSameOriginPathname(href, basePath);
57
44
  if (rawPathname === null) return;
@@ -0,0 +1,23 @@
1
+ import { VinextLinkPrefetchRoute, VinextPagesLinkPrefetchRoute } from "../../client/vinext-next-data.js";
2
+
3
+ //#region src/shims/internal/hybrid-client-route-owner-direct.d.ts
4
+ type HybridClientOwner = "app" | "document" | "pages";
5
+ type HybridClientRouteMatches = {
6
+ appMatch: VinextLinkPrefetchRoute | null;
7
+ pagesMatch: VinextPagesLinkPrefetchRoute | null;
8
+ };
9
+ declare global {
10
+ interface Window {
11
+ __VINEXT_LINK_PREFETCH_ROUTES__?: VinextLinkPrefetchRoute[];
12
+ __VINEXT_PAGES_LINK_PREFETCH_ROUTES__?: VinextPagesLinkPrefetchRoute[];
13
+ }
14
+ }
15
+ declare function resolveSameOriginPathname(href: string, basePath: string): string | null;
16
+ declare function matchDirectHybridClientRoutes(href: string, basePath: string): HybridClientRouteMatches;
17
+ declare function resolveMatchedHybridClientRouteOwner({
18
+ appMatch,
19
+ pagesMatch
20
+ }: HybridClientRouteMatches): HybridClientOwner | null;
21
+ declare function resolveDirectHybridClientRouteOwner(href: string, basePath: string): HybridClientOwner | null;
22
+ //#endregion
23
+ export { HybridClientOwner, matchDirectHybridClientRoutes, resolveDirectHybridClientRouteOwner, resolveMatchedHybridClientRouteOwner, resolveSameOriginPathname };
@@ -0,0 +1,51 @@
1
+ import { compareHybridRoutePatterns } from "../../routing/utils.js";
2
+ import { stripBasePath } from "../../utils/base-path.js";
3
+ import { createRouteTrieCache, matchRouteWithTrie } from "../../routing/route-matching.js";
4
+ import { getLocalePathPrefix } from "../../utils/domain-locale.js";
5
+ //#region src/shims/internal/hybrid-client-route-owner-direct.ts
6
+ const appRouteTrieCache = createRouteTrieCache();
7
+ const pagesRouteTrieCache = createRouteTrieCache();
8
+ function patternFromParts(parts) {
9
+ return "/" + parts.join("/");
10
+ }
11
+ function resolveSameOriginPathname(href, basePath) {
12
+ if (typeof window === "undefined") return null;
13
+ let url;
14
+ try {
15
+ url = new URL(href, window.location.href);
16
+ } catch {
17
+ return null;
18
+ }
19
+ if (url.origin !== window.location.origin) return null;
20
+ const pathname = stripBasePath(url.pathname, basePath);
21
+ const locale = getLocalePathPrefix(pathname, window.__VINEXT_LOCALES__);
22
+ if (!locale) return pathname;
23
+ const localePrefixLength = locale.length + 1;
24
+ return pathname.length === localePrefixLength ? "/" : pathname.slice(localePrefixLength);
25
+ }
26
+ function matchDirectHybridClientRoutes(href, basePath) {
27
+ const pathname = resolveSameOriginPathname(href, basePath);
28
+ if (pathname === null) return {
29
+ appMatch: null,
30
+ pagesMatch: null
31
+ };
32
+ const appRoutes = window.__VINEXT_LINK_PREFETCH_ROUTES__;
33
+ const pagesRoutes = window.__VINEXT_PAGES_LINK_PREFETCH_ROUTES__;
34
+ return {
35
+ appMatch: appRoutes ? matchRouteWithTrie(pathname, appRoutes, appRouteTrieCache)?.route ?? null : null,
36
+ pagesMatch: pagesRoutes ? matchRouteWithTrie(pathname, pagesRoutes, pagesRouteTrieCache)?.route ?? null : null
37
+ };
38
+ }
39
+ function resolveMatchedHybridClientRouteOwner({ appMatch, pagesMatch }) {
40
+ if (appMatch === null && pagesMatch === null) return null;
41
+ if (pagesMatch === null) return appMatch.documentOnly ? "document" : "app";
42
+ if (appMatch === null) return pagesMatch.documentOnly ? "document" : "pages";
43
+ const owner = compareHybridRoutePatterns(patternFromParts(pagesMatch.patternParts), pagesMatch.isDynamic, patternFromParts(appMatch.patternParts), appMatch.isDynamic);
44
+ return (owner === "app" ? appMatch : pagesMatch).documentOnly ? "document" : owner;
45
+ }
46
+ function resolveDirectHybridClientRouteOwner(href, basePath) {
47
+ if (typeof window === "undefined") return null;
48
+ return resolveMatchedHybridClientRouteOwner(matchDirectHybridClientRoutes(href, basePath));
49
+ }
50
+ //#endregion
51
+ export { matchDirectHybridClientRoutes, resolveDirectHybridClientRouteOwner, resolveMatchedHybridClientRouteOwner, resolveSameOriginPathname };
@@ -1,12 +1,9 @@
1
1
  import { NextRewrite } from "../../config/next-config.js";
2
- import { VinextLinkPrefetchRoute, VinextPagesLinkPrefetchRoute } from "../../client/vinext-next-data.js";
2
+ import { HybridClientOwner } from "./hybrid-client-route-owner-direct.js";
3
3
 
4
4
  //#region src/shims/internal/hybrid-client-route-owner.d.ts
5
- type HybridClientOwner = "app" | "document" | "pages";
6
5
  declare global {
7
6
  interface Window {
8
- __VINEXT_LINK_PREFETCH_ROUTES__?: VinextLinkPrefetchRoute[];
9
- __VINEXT_PAGES_LINK_PREFETCH_ROUTES__?: VinextPagesLinkPrefetchRoute[];
10
7
  __VINEXT_CLIENT_REWRITES__?: {
11
8
  afterFiles: NextRewrite[];
12
9
  beforeFiles: NextRewrite[];
@@ -28,4 +25,4 @@ declare global {
28
25
  */
29
26
  declare function resolveHybridClientRouteOwner(href: string, basePath: string): HybridClientOwner | null;
30
27
  //#endregion
31
- export { HybridClientOwner, resolveHybridClientRouteOwner };
28
+ export { type HybridClientOwner, resolveHybridClientRouteOwner };
@@ -1,8 +1,5 @@
1
- import { compareHybridRoutePatterns } from "../../routing/utils.js";
2
- import { stripBasePath } from "../../utils/base-path.js";
3
- import { createRouteTrieCache, matchRouteWithTrie } from "../../routing/route-matching.js";
4
1
  import { isExternalUrl, matchRewrite, parseCookies } from "../../config/config-matchers.js";
5
- import { getLocalePathPrefix } from "../../utils/domain-locale.js";
2
+ import { matchDirectHybridClientRoutes, resolveMatchedHybridClientRouteOwner, resolveSameOriginPathname } from "./hybrid-client-route-owner-direct.js";
6
3
  import { mergeRewriteQuery } from "../../utils/query.js";
7
4
  //#region src/shims/internal/hybrid-client-route-owner.ts
8
5
  /**
@@ -52,45 +49,6 @@ function resolveClientRewrite(href, basePath, rewrites, continueAfterMatch = fal
52
49
  kind: "rewrite"
53
50
  } : null;
54
51
  }
55
- const appRouteTrieCache = createRouteTrieCache();
56
- const pagesRouteTrieCache = createRouteTrieCache();
57
- /**
58
- * Build a `/`-joined pattern from a manifest's `patternParts`. Mirrors the
59
- * server-side route-graph shape (`{ pattern: string }`) so the
60
- * `compareHybridRoutePatterns` segment-rank comparator can score both Pages
61
- * and App patterns. The
62
- * `patternParts` array never includes an empty string for the static `/`
63
- * route (the App catch-all handles the bare path), so the simple join is
64
- * safe for everything the route trie actually matches.
65
- */
66
- function patternFromParts(parts) {
67
- return "/" + parts.join("/");
68
- }
69
- function resolveSameOriginPathname(href, basePath) {
70
- if (typeof window === "undefined") return null;
71
- let url;
72
- try {
73
- url = new URL(href, window.location.href);
74
- } catch {
75
- return null;
76
- }
77
- if (url.origin !== window.location.origin) return null;
78
- const pathname = stripBasePath(url.pathname, basePath);
79
- const locale = getLocalePathPrefix(pathname, window.__VINEXT_LOCALES__);
80
- if (!locale) return pathname;
81
- const localePrefixLength = locale.length + 1;
82
- return pathname.length === localePrefixLength ? "/" : pathname.slice(localePrefixLength);
83
- }
84
- function matchAppRoute(href, basePath, routes) {
85
- const pathname = resolveSameOriginPathname(href, basePath);
86
- if (pathname === null) return null;
87
- return matchRouteWithTrie(pathname, routes, appRouteTrieCache)?.route ?? null;
88
- }
89
- function matchPagesRoute(href, basePath, routes) {
90
- const pathname = resolveSameOriginPathname(href, basePath);
91
- if (pathname === null) return null;
92
- return matchRouteWithTrie(pathname, routes, pagesRouteTrieCache)?.route ?? null;
93
- }
94
52
  /**
95
53
  * Decide which router should own a soft-navigated URL. Returns:
96
54
  * - "app" → the App Router runtime handles the navigation (RSC fetch).
@@ -105,39 +63,30 @@ function matchPagesRoute(href, basePath, routes) {
105
63
  */
106
64
  function resolveHybridClientRouteOwner(href, basePath) {
107
65
  if (typeof window === "undefined") return null;
108
- const appRoutes = window.__VINEXT_LINK_PREFETCH_ROUTES__;
109
- const pagesRoutes = window.__VINEXT_PAGES_LINK_PREFETCH_ROUTES__;
110
66
  const rewrites = window.__VINEXT_CLIENT_REWRITES__;
111
67
  if (rewrites) {
112
68
  const beforeFilesRewrite = resolveClientRewrite(href, basePath, rewrites.beforeFiles, true);
113
69
  if (beforeFilesRewrite?.kind === "document") return "document";
114
70
  if (beforeFilesRewrite?.kind === "rewrite") href = beforeFilesRewrite.href;
115
71
  }
116
- let appMatch = appRoutes ? matchAppRoute(href, basePath, appRoutes) : null;
117
- let pagesMatch = pagesRoutes ? matchPagesRoute(href, basePath, pagesRoutes) : null;
118
- if (rewrites && (appMatch === null || appMatch.isDynamic) && (pagesMatch === null || pagesMatch.isDynamic)) for (const rewrite of rewrites.afterFiles) {
72
+ let matches = matchDirectHybridClientRoutes(href, basePath);
73
+ if (rewrites && (matches.appMatch === null || matches.appMatch.isDynamic) && (matches.pagesMatch === null || matches.pagesMatch.isDynamic)) for (const rewrite of rewrites.afterFiles) {
119
74
  const afterFilesRewrite = resolveClientRewrite(href, basePath, [rewrite]);
120
75
  if (afterFilesRewrite?.kind === "document") return "document";
121
76
  if (afterFilesRewrite?.kind !== "rewrite") continue;
122
77
  href = afterFilesRewrite.href;
123
- appMatch = appRoutes ? matchAppRoute(href, basePath, appRoutes) : null;
124
- pagesMatch = pagesRoutes ? matchPagesRoute(href, basePath, pagesRoutes) : null;
125
- if (appMatch || pagesMatch) break;
78
+ matches = matchDirectHybridClientRoutes(href, basePath);
79
+ if (matches.appMatch || matches.pagesMatch) break;
126
80
  }
127
- if (rewrites && appMatch === null && pagesMatch === null) for (const rewrite of rewrites.fallback) {
81
+ if (rewrites && matches.appMatch === null && matches.pagesMatch === null) for (const rewrite of rewrites.fallback) {
128
82
  const fallbackRewrite = resolveClientRewrite(href, basePath, [rewrite]);
129
83
  if (fallbackRewrite?.kind === "document") return "document";
130
84
  if (fallbackRewrite?.kind !== "rewrite") continue;
131
85
  href = fallbackRewrite.href;
132
- appMatch = appRoutes ? matchAppRoute(href, basePath, appRoutes) : null;
133
- pagesMatch = pagesRoutes ? matchPagesRoute(href, basePath, pagesRoutes) : null;
134
- if (appMatch || pagesMatch) break;
86
+ matches = matchDirectHybridClientRoutes(href, basePath);
87
+ if (matches.appMatch || matches.pagesMatch) break;
135
88
  }
136
- if (appMatch === null && pagesMatch === null) return null;
137
- if (pagesMatch === null) return appMatch.documentOnly ? "document" : "app";
138
- if (appMatch === null) return pagesMatch.documentOnly ? "document" : "pages";
139
- const owner = compareHybridRoutePatterns(patternFromParts(pagesMatch.patternParts), pagesMatch.isDynamic, patternFromParts(appMatch.patternParts), appMatch.isDynamic);
140
- return (owner === "app" ? appMatch : pagesMatch).documentOnly ? "document" : owner;
89
+ return resolveMatchedHybridClientRouteOwner(matches);
141
90
  }
142
91
  //#endregion
143
92
  export { resolveHybridClientRouteOwner };
@@ -0,0 +1,7 @@
1
+ //#region src/shims/internal/pages-router-components.d.ts
2
+ type PagesRouterComponentsMap = Record<string, {
3
+ __appRouter: true;
4
+ } | Record<string, unknown>>;
5
+ declare function getPagesRouterComponentsMap(): PagesRouterComponentsMap;
6
+ //#endregion
7
+ export { PagesRouterComponentsMap, getPagesRouterComponentsMap };
@@ -0,0 +1,13 @@
1
+ //#region src/shims/internal/pages-router-components.ts
2
+ const COMPONENTS_KEY = Symbol.for("vinext.pagesRouter.components");
3
+ function getPagesRouterComponentsMap() {
4
+ const globalState = globalThis;
5
+ let components = globalState[COMPONENTS_KEY];
6
+ if (!components) {
7
+ components = {};
8
+ globalState[COMPONENTS_KEY] = components;
9
+ }
10
+ return components;
11
+ }
12
+ //#endregion
13
+ export { getPagesRouterComponentsMap };
@@ -1,24 +1,18 @@
1
1
  "use client";
2
2
  import { stripBasePath } from "../utils/base-path.js";
3
3
  import { createRouteTrieCache, matchRouteWithTrie } from "../routing/route-matching.js";
4
- import { VINEXT_MOUNTED_SLOTS_HEADER } from "../server/headers.js";
5
4
  import { isDangerousScheme, reportBlockedDangerousNavigation } from "./url-safety.js";
6
- import { AppElementsWire } from "../server/app-elements-wire.js";
7
- import { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "../server/app-rsc-render-mode.js";
8
- import "../server/app-elements.js";
9
5
  import { addLocalePrefix, getDomainLocaleUrl } from "../utils/domain-locale.js";
10
6
  import { prefetchPagesData, resolvePagesDataNavigationTarget } from "./internal/pages-data-target.js";
11
- import { appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
12
- import { resolveHybridClientRouteOwner } from "./internal/hybrid-client-route-owner.js";
13
7
  import { markAppRouteDetectedOnPrefetch } from "./internal/app-route-detection.js";
14
8
  import { isAbsoluteOrProtocolRelativeUrl, normalizePathTrailingSlash, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
9
+ import { appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
15
10
  import { interpolateDynamicRouteHref } from "./internal/interpolate-as.js";
16
11
  import { getCurrentBrowserLocale } from "./client-locale.js";
17
12
  import { getCurrentRoutePathnameForWarning } from "./internal/route-pattern-for-warning.js";
18
- import { createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam, stripRscSuffix } from "../server/app-rsc-cache-busting.js";
13
+ import { isBotUserAgent } from "../utils/html-limited-bots.js";
19
14
  import { getNavigationRuntime, hasAppNavigationRuntime, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
20
15
  import { navigatePagesRouterLinkWithFallback, resolvePagesRouterQueryOnlyHref } from "../client/pages-router-link-navigation.js";
21
- import { getMountedSlotsHeader, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, navigateClientSide, prefetchRscResponse } from "./navigation.js";
22
16
  import { getI18nContext } from "./i18n-context.js";
23
17
  import { canLinkIntentPrefetch, canLinkPrefetch, getLinkPrefetchHref } from "./link-prefetch.js";
24
18
  import { clearLinkForCurrentNavigation, notifyLinkNavigationStart, setLinkForCurrentNavigation } from "./internal/link-status-registry.js";
@@ -211,6 +205,17 @@ function prefetchUrl(href, mode, priority = "low") {
211
205
  } : window.requestIdleCallback ?? ((fn) => setTimeout(fn, 100)))(() => {
212
206
  (async () => {
213
207
  if (hasAppNavigationRuntime()) {
208
+ if (isBotUserAgent(window.navigator?.userAgent ?? "")) return;
209
+ const [navigation, { AppElementsWire }, rscCacheBusting, { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL }, { VINEXT_MOUNTED_SLOTS_HEADER }, { resolveHybridClientRouteOwner }] = await Promise.all([
210
+ import("./navigation.js"),
211
+ import("../server/app-elements.js"),
212
+ import("../server/app-rsc-cache-busting.js"),
213
+ import("../server/app-rsc-render-mode.js"),
214
+ import("../server/headers.js"),
215
+ import("./internal/hybrid-client-route-owner.js")
216
+ ]);
217
+ const { getPrefetchInterceptionContext, getPrefetchCache, getPrefetchedUrls, getMountedSlotsHeader, hasPrefetchCacheEntryForNavigation, prefetchRscResponse } = navigation;
218
+ const { createRscRequestHeaders, createRscRequestUrl } = rscCacheBusting;
214
219
  const hybridOwner = resolveHybridClientRouteOwner(prefetchHref, __basePath);
215
220
  if (hybridOwner === "pages" || hybridOwner === "document") return;
216
221
  const autoPrefetch = mode === "auto" ? resolveAutoAppRoutePrefetch(prefetchHref) : {
@@ -272,7 +277,7 @@ function prefetchUrl(href, mode, priority = "low") {
272
277
  const dataTarget = resolvePagesDataNavigationTarget(fullHref, __basePath);
273
278
  if (dataTarget) prefetchPagesData(dataTarget);
274
279
  else {
275
- markAppRouteDetectedOnPrefetch(fullHref, __basePath);
280
+ await markAppRouteDetectedOnPrefetch(fullHref, __basePath);
276
281
  const link = document.createElement("link");
277
282
  link.rel = "prefetch";
278
283
  link.href = fullHref;
@@ -285,8 +290,10 @@ function prefetchUrl(href, mode, priority = "low") {
285
290
  });
286
291
  });
287
292
  }
288
- function promotePrefetchEntriesForNavigation(href) {
293
+ async function promotePrefetchEntriesForNavigation(href) {
289
294
  if (typeof window === "undefined") return;
295
+ if (!hasAppNavigationRuntime()) return;
296
+ const [{ getPrefetchCache }, { stripRscCacheBustingSearchParam, stripRscSuffix }] = await Promise.all([import("./navigation.js"), import("../server/app-rsc-cache-busting.js")]);
290
297
  let target;
291
298
  try {
292
299
  target = new URL(toBrowserNavigationHref(href, window.location.href, __basePath), window.location.href);
@@ -553,12 +560,14 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
553
560
  onNavigate(navEvent);
554
561
  if (navEvent.defaultPrevented) return;
555
562
  } catch {}
556
- if (HAS_PAGES_ROUTER && hasAppNavigationRuntime && ["pages", "document"].includes(resolveHybridClientRouteOwner(navigateHref, __basePath) ?? "")) {
563
+ const hybridOwner = HAS_PAGES_ROUTER && hasAppNavigationRuntime ? (await import("./internal/hybrid-client-route-owner.js")).resolveHybridClientRouteOwner(navigateHref, __basePath) : null;
564
+ if (HAS_PAGES_ROUTER && hasAppNavigationRuntime && ["pages", "document"].includes(hybridOwner ?? "")) {
557
565
  if (replace) window.location.replace(absoluteFullHref);
558
566
  else window.location.assign(absoluteFullHref);
559
567
  return;
560
568
  }
561
569
  if (hasAppNavigationRuntime) {
570
+ const { navigateClientSide } = await import("./navigation.js");
562
571
  const setter = setPendingRef.current;
563
572
  if (setter) setLinkForCurrentNavigation(setter);
564
573
  setPending(true);
@@ -573,7 +582,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
573
582
  const Router = window.next?.appDir === true ? void 0 : window.next?.router;
574
583
  await navigatePagesRouterLinkWithFallback({
575
584
  router: Router && "reload" in Router ? Router : void 0,
576
- loadRouter: async () => (await import("next/router.js")).default,
585
+ loadRouter: async () => (await import("D:\\projects\\vinext\\node_modules\\.pnpm\\next@16.2.7_@opentelemetry+_a27effa3fabbfbd07255229e73bfb661\\node_modules\\next\\router.js")).default,
577
586
  navigation: {
578
587
  href: pagesHrefForLink,
579
588
  as: pagesAsForLink,
@@ -651,7 +660,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
651
660
  onClick: (event) => {
652
661
  if (childOnClick) childOnClick(event);
653
662
  if (event.defaultPrevented) return;
654
- handleClick(event, { skipLinkOnClick: true });
663
+ return handleClick(event, { skipLinkOnClick: true });
655
664
  },
656
665
  onMouseEnter: (event) => {
657
666
  if (childOnMouseEnter) childOnMouseEnter(event);
@@ -673,9 +682,7 @@ const Link = forwardRef(function Link({ href, as, replace = false, prefetch: pre
673
682
  children: /* @__PURE__ */ jsx("a", {
674
683
  ref: setRefs,
675
684
  href: fullHref,
676
- onClick: (event) => {
677
- handleClick(event);
678
- },
685
+ onClick: handleClick,
679
686
  onMouseEnter: handleMouseEnter,
680
687
  onTouchStart: handleTouchStart,
681
688
  ...anchorProps,
@@ -1,3 +1,4 @@
1
+ import { ThenableParamsObserver } from "./thenable-params.js";
1
2
  import React from "react";
2
3
 
3
4
  //#region src/shims/metadata.d.ts
@@ -18,7 +19,7 @@ type Viewport = {
18
19
  * Resolve viewport config from a module. Handles both static `viewport` export
19
20
  * and async `generateViewport()` function.
20
21
  */
21
- declare function resolveModuleViewport(mod: Record<string, unknown>, params: Record<string, string | string[]>): Promise<Viewport | null>;
22
+ declare function resolveModuleViewport(mod: Record<string, unknown>, params: Record<string, string | string[]>, searchParams?: Record<string, string | string[]>, searchParamsObserver?: ThenableParamsObserver): Promise<Viewport | null>;
22
23
  /**
23
24
  * Merge viewport configs from multiple sources (layouts + page).
24
25
  * Later entries override earlier ones.
@@ -267,7 +268,7 @@ declare function mergeMetadataEntries(entries: readonly MetadataMergeEntry[]): M
267
268
  * resolution approach. If not provided, defaults to a promise that resolves
268
269
  * to an empty object (so `await parent` never throws).
269
270
  */
270
- declare function resolveModuleMetadata(mod: Record<string, unknown>, params?: Record<string, string | string[]>, searchParams?: Record<string, string | string[]>, parent?: Promise<Metadata>): Promise<Metadata | null>;
271
+ declare function resolveModuleMetadata(mod: Record<string, unknown>, params?: Record<string, string | string[]>, searchParams?: Record<string, string | string[]>, parent?: Promise<Metadata>, searchParamsObserver?: ThenableParamsObserver): Promise<Metadata | null>;
271
272
  type MetadataHeadProps = {
272
273
  metadata: Metadata;
273
274
  pathname?: string;
@@ -13,10 +13,14 @@ import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
13
13
  * Resolve viewport config from a module. Handles both static `viewport` export
14
14
  * and async `generateViewport()` function.
15
15
  */
16
- async function resolveModuleViewport(mod, params) {
16
+ async function resolveModuleViewport(mod, params, searchParams, searchParamsObserver) {
17
17
  if (typeof mod.generateViewport === "function") {
18
18
  const asyncParams = makeThenableParams(params);
19
- return await mod.generateViewport({ params: asyncParams });
19
+ const props = searchParams === void 0 ? { params: asyncParams } : {
20
+ params: asyncParams,
21
+ searchParams: makeThenableParams(searchParams, searchParamsObserver)
22
+ };
23
+ return await mod.generateViewport(props);
20
24
  }
21
25
  if (mod.viewport && typeof mod.viewport === "object") return mod.viewport;
22
26
  return null;
@@ -213,12 +217,12 @@ function mergeMetadataEntries(entries) {
213
217
  * resolution approach. If not provided, defaults to a promise that resolves
214
218
  * to an empty object (so `await parent` never throws).
215
219
  */
216
- async function resolveModuleMetadata(mod, params = {}, searchParams, parent = Promise.resolve({})) {
220
+ async function resolveModuleMetadata(mod, params = {}, searchParams, parent = Promise.resolve({}), searchParamsObserver) {
217
221
  if (typeof mod.generateMetadata === "function") {
218
222
  const asyncParams = makeThenableParams(params);
219
223
  const props = searchParams === void 0 ? { params: asyncParams } : {
220
224
  params: asyncParams,
221
- searchParams: makeThenableParams(searchParams)
225
+ searchParams: makeThenableParams(searchParams, searchParamsObserver)
222
226
  };
223
227
  return await (mod.generateMetadata.length >= 2 ? mod.generateMetadata(props, parent) : mod.generateMetadata(props));
224
228
  }
@@ -5,11 +5,11 @@ import { AppElementsWire } from "../server/app-elements-wire.js";
5
5
  import "../server/app-elements.js";
6
6
  import { markPprFallbackShellDynamicBoundary } from "./ppr-fallback-shell.js";
7
7
  import { AppRouterContext } from "./internal/app-router-context.js";
8
- import { resolveHybridClientRouteOwner } from "./internal/hybrid-client-route-owner.js";
9
8
  import { isAbsoluteOrProtocolRelativeUrl, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
10
9
  import { retryScrollTo, scrollToHashTarget } from "./hash-scroll.js";
11
10
  import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
12
11
  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";
12
+ import { isBotUserAgent } from "../utils/html-limited-bots.js";
13
13
  import { clearAppNavigationFailureTarget, stageAppNavigationFailureTarget } from "../client/app-nav-failure-handler.js";
14
14
  import { beginAppRouterScrollIntent, clearAppRouterScrollIntent, consumeAppRouterScrollIntent, getPendingAppRouterScrollIntent } from "./app-router-scroll-state.js";
15
15
  import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam } from "../server/app-rsc-cache-busting.js";
@@ -22,6 +22,7 @@ import { hasPendingAppRouterPageRedirect } from "../server/app-browser-mpa-navig
22
22
  import { navigationPlanner } from "../server/navigation-planner.js";
23
23
  import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
24
24
  import { getPagesNavigationContext } from "./internal/pages-router-accessor.js";
25
+ import { resolveHybridClientRouteOwner } from "./internal/hybrid-client-route-owner.js";
25
26
  import { UnrecognizedActionError, unstable_isUnrecognizedActionError } from "./unrecognized-action-error.js";
26
27
  import * as React$1 from "react";
27
28
  //#region src/shims/navigation.ts
@@ -41,7 +42,7 @@ function useChildSegments(parallelRoutesKey = "children") {
41
42
  const ctx = getLayoutSegmentContext();
42
43
  if (!ctx) return [];
43
44
  try {
44
- return React$1.useContext(ctx)[parallelRoutesKey] ?? [];
45
+ return (React$1.useContext(ctx)[parallelRoutesKey] ?? []).filter((segment) => !segment.startsWith("__PAGE__"));
45
46
  } catch {
46
47
  return [];
47
48
  }
@@ -1033,6 +1034,7 @@ const _appRouter = {
1033
1034
  prefetch(href, options) {
1034
1035
  assertSafeNavigationUrl(href);
1035
1036
  if (isServer) return;
1037
+ if (isBotUserAgent(window.navigator?.userAgent ?? "")) return;
1036
1038
  try {
1037
1039
  new URL(withBasePath(href, __basePath), window.location.href);
1038
1040
  } catch {
@@ -3,10 +3,24 @@ type RootParams = Record<string, string | string[] | undefined>;
3
3
  type RootParamsState = {
4
4
  rootParams: RootParams | null;
5
5
  };
6
+ type RootParamsUsage = {
7
+ kind: "route";
8
+ } | {
9
+ kind: "server-action";
10
+ } | {
11
+ kind: "route-handler";
12
+ routePattern: string;
13
+ };
14
+ type RootParamsUsageController = {
15
+ transitionToRender(): void;
16
+ };
6
17
  declare function pickRootParams(params: RootParams, rootParamNames: readonly string[] | null | undefined): RootParams;
7
18
  declare function setRootParams(params: RootParams | null): void;
8
19
  declare function getRootParam(name: string): Promise<string | string[] | undefined>;
20
+ declare function runWithRootParamsUsage<T>(usage: RootParamsUsage, fn: () => Promise<T>, controller?: RootParamsUsageController): Promise<T>;
21
+ declare function runWithRootParamsUsage<T>(usage: RootParamsUsage, fn: () => T | Promise<T>, controller?: RootParamsUsageController): T | Promise<T>;
22
+ declare function createRootParamsUsageController(): RootParamsUsageController;
9
23
  declare function runWithRootParamsScope<T>(params: RootParams, fn: () => Promise<T>): Promise<T>;
10
24
  declare function runWithRootParamsScope<T>(params: RootParams, fn: () => T | Promise<T>): T | Promise<T>;
11
25
  //#endregion
12
- export { RootParams, RootParamsState, getRootParam, pickRootParams, runWithRootParamsScope, setRootParams };
26
+ export { RootParams, RootParamsState, RootParamsUsage, RootParamsUsageController, createRootParamsUsageController, getRootParam, pickRootParams, runWithRootParamsScope, runWithRootParamsUsage, setRootParams };
@@ -1,9 +1,13 @@
1
1
  import { getOrCreateAls } from "./internal/als-registry.js";
2
2
  import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
3
3
  //#region src/shims/root-params.ts
4
+ function createRootParamsUsageError(message) {
5
+ return new Error(message);
6
+ }
4
7
  const _FALLBACK_KEY = Symbol.for("vinext.rootParams.fallback");
5
8
  const _g = globalThis;
6
9
  const _als = getOrCreateAls("vinext.rootParams.als");
10
+ const _usageAls = getOrCreateAls("vinext.rootParams.usage.als");
7
11
  const _fallbackState = _g[_FALLBACK_KEY] ??= { rootParams: null };
8
12
  function getState() {
9
13
  if (isInsideUnifiedScope()) return getRequestContext();
@@ -18,8 +22,24 @@ function setRootParams(params) {
18
22
  getState().rootParams = params;
19
23
  }
20
24
  function getRootParam(name) {
25
+ const usage = _usageAls.getStore();
26
+ if (usage?.kind === "server-action" && usage.phase === "active") throw createRootParamsUsageError(`\`import('next/root-params').${name}()\` was used inside a Server Action. This is not supported. Functions from 'next/root-params' can only be called in the context of a route.`);
27
+ if (usage?.kind === "route-handler" && usage.phase === "active") throw createRootParamsUsageError(`Route ${usage.routePattern} used \`import('next/root-params').${name}()\` inside a Route Handler. Support for this API in Route Handlers is planned for a future version of Next.js.`);
21
28
  return Promise.resolve(getState().rootParams?.[name]);
22
29
  }
30
+ function runWithRootParamsUsage(usage, fn, controller) {
31
+ const state = {
32
+ ...usage,
33
+ phase: "active"
34
+ };
35
+ if (controller) controller.transitionToRender = () => {
36
+ if (usage.kind === "server-action") state.phase = "render";
37
+ };
38
+ return _usageAls.run(state, fn);
39
+ }
40
+ function createRootParamsUsageController() {
41
+ return { transitionToRender() {} };
42
+ }
23
43
  function runWithRootParamsScope(params, fn) {
24
44
  if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((ctx) => {
25
45
  ctx.rootParams = params;
@@ -27,4 +47,4 @@ function runWithRootParamsScope(params, fn) {
27
47
  else return _als.run({ rootParams: params }, fn);
28
48
  }
29
49
  //#endregion
30
- export { getRootParam, pickRootParams, runWithRootParamsScope, setRootParams };
50
+ export { createRootParamsUsageController, getRootParam, pickRootParams, runWithRootParamsScope, runWithRootParamsUsage, setRootParams };
@@ -1,4 +1,5 @@
1
1
  import { VinextNextData } from "../client/vinext-next-data.js";
2
+ import { PagesRouterComponentsMap } from "./internal/pages-router-components.js";
2
3
  import { UrlQuery } from "../utils/query.js";
3
4
  import { ComponentType, ReactElement } from "react";
4
5
 
@@ -174,11 +175,7 @@ type ExcludeRouterProps<P> = Pick<P, Exclude<keyof P, keyof WithRouterProps>>;
174
175
  */
175
176
  declare function withRouter<P extends WithRouterProps>(ComposedComponent: ComponentType<P>): ComponentType<ExcludeRouterProps<P>>;
176
177
  declare const RouterMethods: {
177
- /** See `_components` comment above for the dual role this map plays. */components: {
178
- [x: string]: {
179
- __appRouter: true;
180
- } | Record<string, unknown>;
181
- };
178
+ /** See `_components` comment above for the dual role this map plays. */components: PagesRouterComponentsMap;
182
179
  push: (url: string | UrlObject, as?: string, options?: TransitionOptions) => Promise<boolean>;
183
180
  replace: (url: string | UrlObject, as?: string, options?: TransitionOptions) => Promise<boolean>;
184
181
  back: () => void;