vinext 1.0.0-beta.6 → 1.0.0-beta.8

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 (179) hide show
  1. package/README.md +47 -3
  2. package/dist/build/action-owner-manifest.d.ts +42 -0
  3. package/dist/build/action-owner-manifest.js +110 -0
  4. package/dist/build/clean-output.js +1 -4
  5. package/dist/build/client-build-config.js +10 -11
  6. package/dist/build/prerender.d.ts +1 -1
  7. package/dist/build/prerender.js +12 -6
  8. package/dist/build/report.d.ts +1 -1
  9. package/dist/build/route-classification-manifest.d.ts +1 -1
  10. package/dist/build/static-export.d.ts +1 -1
  11. package/dist/client/app-nav-failure-handler.js +1 -0
  12. package/dist/client/navigation-runtime.d.ts +5 -3
  13. package/dist/client/navigation-runtime.js +4 -8
  14. package/dist/entries/app-browser-entry.d.ts +1 -1
  15. package/dist/entries/app-rsc-entry.d.ts +2 -1
  16. package/dist/entries/app-rsc-entry.js +111 -8
  17. package/dist/entries/pages-client-entry.d.ts +1 -1
  18. package/dist/entries/pages-server-entry.d.ts +1 -1
  19. package/dist/index.d.ts +3 -0
  20. package/dist/index.js +119 -26
  21. package/dist/plugins/action-owner-manifest.d.ts +14 -0
  22. package/dist/plugins/action-owner-manifest.js +84 -0
  23. package/dist/plugins/ast-utils.d.ts +30 -1
  24. package/dist/plugins/ast-utils.js +76 -1
  25. package/dist/plugins/css-module-imports.d.ts +2 -2
  26. package/dist/plugins/css-module-imports.js +5 -13
  27. package/dist/plugins/dynamic-preload-metadata.js +13 -34
  28. package/dist/plugins/environment.d.ts +11 -0
  29. package/dist/plugins/environment.js +7 -0
  30. package/dist/plugins/extensionless-dynamic-import.js +11 -35
  31. package/dist/plugins/fonts.js +8 -12
  32. package/dist/plugins/ignore-dynamic-requests.d.ts +2 -4
  33. package/dist/plugins/ignore-dynamic-requests.js +29 -59
  34. package/dist/plugins/import-meta-url.d.ts +15 -9
  35. package/dist/plugins/import-meta-url.js +310 -85
  36. package/dist/plugins/instrumentation-client.js +4 -5
  37. package/dist/plugins/middleware-export-validation.js +5 -17
  38. package/dist/plugins/middleware-server-only.js +2 -2
  39. package/dist/plugins/og-asset-ownership.js +18 -26
  40. package/dist/plugins/og-assets.js +2 -4
  41. package/dist/plugins/optimize-imports.js +2 -4
  42. package/dist/plugins/pages-node-externals.js +13 -40
  43. package/dist/plugins/remove-console.js +2 -4
  44. package/dist/plugins/require-condition-resolution.d.ts +16 -0
  45. package/dist/plugins/require-condition-resolution.js +167 -0
  46. package/dist/plugins/require-context.js +11 -46
  47. package/dist/plugins/sass.js +1 -1
  48. package/dist/plugins/server-externals-manifest.js +1 -23
  49. package/dist/plugins/strip-server-exports.js +13 -19
  50. package/dist/plugins/styled-jsx.js +17 -19
  51. package/dist/plugins/transform-result.d.ts +10 -0
  52. package/dist/plugins/transform-result.js +10 -0
  53. package/dist/plugins/transitive-externals.js +7 -21
  54. package/dist/plugins/typeof-window.d.ts +3 -8
  55. package/dist/plugins/typeof-window.js +5 -15
  56. package/dist/plugins/use-cache-callable.js +12 -22
  57. package/dist/plugins/wasm-module-import.js +1 -1
  58. package/dist/plugins/worker-image-imports.d.ts +12 -0
  59. package/dist/plugins/worker-image-imports.js +136 -0
  60. package/dist/routing/app-route-graph.d.ts +3 -2
  61. package/dist/routing/app-route-graph.js +1 -1
  62. package/dist/routing/route-pattern.d.ts +8 -1
  63. package/dist/routing/route-pattern.js +28 -1
  64. package/dist/routing/route-validation.js +7 -1
  65. package/dist/server/accept-encoding.d.ts +1 -2
  66. package/dist/server/accept-encoding.js +1 -4
  67. package/dist/server/app-action-forwarding.d.ts +18 -0
  68. package/dist/server/app-action-forwarding.js +140 -0
  69. package/dist/server/app-browser-entry.js +231 -50
  70. package/dist/server/app-browser-error.d.ts +1 -2
  71. package/dist/server/app-browser-error.js +1 -5
  72. package/dist/server/app-browser-history-controller.d.ts +16 -1
  73. package/dist/server/app-browser-history-controller.js +135 -18
  74. package/dist/server/app-browser-navigation-abort.d.ts +16 -0
  75. package/dist/server/app-browser-navigation-abort.js +29 -0
  76. package/dist/server/app-browser-navigation-controller.d.ts +4 -0
  77. package/dist/server/app-browser-navigation-controller.js +22 -6
  78. package/dist/server/app-browser-navigation-response.d.ts +11 -0
  79. package/dist/server/app-browser-navigation-response.js +8 -0
  80. package/dist/server/app-browser-popstate.d.ts +6 -1
  81. package/dist/server/app-browser-popstate.js +6 -2
  82. package/dist/server/app-browser-server-action-client.js +1 -1
  83. package/dist/server/app-browser-state.d.ts +2 -2
  84. package/dist/server/app-browser-state.js +3 -3
  85. package/dist/server/app-browser-stream.d.ts +0 -2
  86. package/dist/server/app-browser-supplemental-refresh.d.ts +49 -0
  87. package/dist/server/app-browser-supplemental-refresh.js +190 -0
  88. package/dist/server/app-browser-visible-commit.js +23 -12
  89. package/dist/server/app-elements-wire.d.ts +2 -0
  90. package/dist/server/app-elements-wire.js +7 -0
  91. package/dist/server/app-history-state.d.ts +22 -1
  92. package/dist/server/app-history-state.js +93 -9
  93. package/dist/server/app-optimistic-routing.d.ts +22 -1
  94. package/dist/server/app-optimistic-routing.js +137 -12
  95. package/dist/server/app-page-cache-finalizer.d.ts +3 -1
  96. package/dist/server/app-page-cache-finalizer.js +6 -6
  97. package/dist/server/app-page-cache.d.ts +2 -1
  98. package/dist/server/app-page-cache.js +2 -2
  99. package/dist/server/app-page-dispatch.d.ts +4 -1
  100. package/dist/server/app-page-dispatch.js +10 -1
  101. package/dist/server/app-page-element-builder.d.ts +1 -0
  102. package/dist/server/app-page-element-builder.js +1 -0
  103. package/dist/server/app-page-ppr-runtime.js +3 -2
  104. package/dist/server/app-page-render.d.ts +2 -1
  105. package/dist/server/app-page-render.js +6 -3
  106. package/dist/server/app-page-request.d.ts +2 -33
  107. package/dist/server/app-page-request.js +1 -27
  108. package/dist/server/app-page-route-wiring.d.ts +1 -0
  109. package/dist/server/app-page-route-wiring.js +4 -0
  110. package/dist/server/app-page-segment-state.d.ts +2 -2
  111. package/dist/server/app-page-segment-state.js +14 -8
  112. package/dist/server/app-ppr-fallback-shell.d.ts +2 -2
  113. package/dist/server/app-ppr-fallback-shell.js +3 -6
  114. package/dist/server/app-route-handler-dispatch.js +4 -1
  115. package/dist/server/app-route-handler-execution.js +1 -1
  116. package/dist/server/app-rsc-cache-busting.d.ts +2 -1
  117. package/dist/server/app-rsc-cache-busting.js +34 -8
  118. package/dist/server/app-rsc-handler.d.ts +4 -2
  119. package/dist/server/app-rsc-handler.js +57 -9
  120. package/dist/server/app-rsc-request-normalization.d.ts +2 -0
  121. package/dist/server/app-rsc-request-normalization.js +5 -1
  122. package/dist/server/app-rsc-route-matching.d.ts +4 -3
  123. package/dist/server/app-rsc-route-matching.js +14 -42
  124. package/dist/server/app-server-action-execution.d.ts +3 -0
  125. package/dist/server/app-server-action-execution.js +77 -2
  126. package/dist/server/app-ssr-entry.js +6 -6
  127. package/dist/server/app-ssr-stream.d.ts +1 -1
  128. package/dist/server/app-ssr-stream.js +2 -2
  129. package/dist/server/app-visited-response-cache.d.ts +6 -1
  130. package/dist/server/app-visited-response-cache.js +18 -2
  131. package/dist/server/dev-route-files.js +2 -5
  132. package/dist/server/dev-server.d.ts +5 -13
  133. package/dist/server/dev-server.js +22 -22
  134. package/dist/server/dev-stack-sourcemap.d.ts +1 -2
  135. package/dist/server/dev-stack-sourcemap.js +1 -4
  136. package/dist/server/headers.d.ts +5 -1
  137. package/dist/server/headers.js +5 -1
  138. package/dist/server/isr-cache.d.ts +6 -14
  139. package/dist/server/isr-cache.js +6 -27
  140. package/dist/server/middleware.d.ts +3 -16
  141. package/dist/server/middleware.js +2 -19
  142. package/dist/server/navigation-planner.d.ts +1 -0
  143. package/dist/server/navigation-planner.js +57 -9
  144. package/dist/server/navigation-trace.d.ts +1 -0
  145. package/dist/server/navigation-trace.js +1 -0
  146. package/dist/server/pages-data-route.d.ts +1 -10
  147. package/dist/server/pages-data-route.js +1 -12
  148. package/dist/server/pages-node-compat.d.ts +1 -4
  149. package/dist/server/pages-node-compat.js +1 -7
  150. package/dist/server/pages-readiness.js +4 -4
  151. package/dist/server/prerender-route-params.d.ts +1 -2
  152. package/dist/server/prerender-route-params.js +1 -4
  153. package/dist/server/prod-server.js +3 -1
  154. package/dist/shims/cache-runtime.js +39 -22
  155. package/dist/shims/cache.d.ts +1 -1
  156. package/dist/shims/dynamic.d.ts +3 -3
  157. package/dist/shims/dynamic.js +4 -6
  158. package/dist/shims/error.js +1 -1
  159. package/dist/shims/fetch-cache.d.ts +3 -1
  160. package/dist/shims/fetch-cache.js +23 -4
  161. package/dist/shims/internal/app-route-prefetch-policy.d.ts +6 -7
  162. package/dist/shims/internal/app-route-prefetch-policy.js +5 -4
  163. package/dist/shims/link.js +1 -1
  164. package/dist/shims/navigation.d.ts +12 -3
  165. package/dist/shims/navigation.js +46 -11
  166. package/dist/shims/navigation.react-server.js +1 -1
  167. package/dist/shims/request-state-types.d.ts +1 -1
  168. package/dist/shims/router.js +75 -4
  169. package/dist/shims/unified-request-context.d.ts +1 -1
  170. package/dist/shims/unified-request-context.js +1 -0
  171. package/dist/utils/built-asset-url.d.ts +1 -1
  172. package/dist/utils/built-asset-url.js +4 -2
  173. package/dist/utils/package-name.d.ts +11 -0
  174. package/dist/utils/package-name.js +18 -0
  175. package/dist/utils/path.d.ts +8 -1
  176. package/dist/utils/path.js +21 -1
  177. package/dist/utils/react-compiler-support.d.ts +20 -0
  178. package/dist/utils/react-compiler-support.js +29 -0
  179. package/package.json +3 -2
@@ -1,7 +1,10 @@
1
+ import { splitPathnameForRouteMatch } from "../routing/utils.js";
2
+ import { addBasePathToPathname, stripBasePath } from "../utils/base-path.js";
1
3
  import { VINEXT_CLIENT_REUSE_MANIFEST_HEADER, VINEXT_PARAMS_HEADER, VINEXT_RSC_REDIRECT_HEADER, VINEXT_RSC_REDIRECT_TYPE_HEADER } from "./headers.js";
2
4
  import { AppElementsWire } from "./app-elements-wire.js";
3
5
  import { getMountedSlotIdsHeader, resolveVisitedResponseInterceptionContext } from "./app-elements.js";
4
6
  import { AppRouterContext } from "../shims/internal/app-router-context.js";
7
+ import { matchRoutePattern } from "../routing/route-pattern.js";
5
8
  import { installWindowNext, setWindowNextInternalSourcePage } from "../client/window-next.js";
6
9
  import { retryScrollTo, scrollToHashTargetOnNextFrame } from "../shims/hash-scroll.js";
7
10
  import { getBfcacheIdMapContext, setNavigationContext } from "../shims/navigation-context-state.js";
@@ -16,27 +19,30 @@ import { VINEXT_RSC_COMPATIBILITY_ID_HEADER, VINEXT_RSC_CONTENT_TYPE, createRscR
16
19
  import { getNavigationRuntime, registerNavigationRuntimeBootstrap, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
17
20
  import { notifyAppRouterTransitionStart } from "../client/instrumentation-client-state.js";
18
21
  import "../client/instrumentation-client.js";
19
- import { readHistoryStatePreviousNextUrl } from "./app-history-state.js";
20
- import { createBfcacheSegmentIdentityMap, createInitialBfcacheIdMap } from "./app-bfcache-identity.js";
21
- import { createDiscardedServerActionRefreshScheduler, createServerActionInitiationSnapshot, resolveServerActionOperationLane } from "./app-browser-action-result.js";
22
- import { createClientReuseManifestHeaderFromVisibleAppState } from "./app-browser-client-reuse-manifest.js";
23
22
  import { resolveManifestNavigationInterceptionContext, resolveMiddlewareRewriteNavigationInterceptionContext } from "./app-browser-interception-context.js";
23
+ import { isExternalHistoryState, readHistoryStateActiveRoutePaths, readHistoryStatePreviousNextUrl, resolveActiveRoutePaths } from "./app-history-state.js";
24
24
  import { AppBrowserMpaNavigationScheduler } from "./app-browser-mpa-navigation.js";
25
25
  import { stripRscCompletionMetadataResponse } from "./rsc-completion-metadata.js";
26
26
  import { blockDangerousStreamedRscRedirect } from "./app-browser-rsc-redirect.js";
27
27
  import { navigationPlanner } from "./navigation-planner.js";
28
- import { DYNAMIC_NAVIGATION_CACHE_TTL, PREFETCH_CACHE_TTL, __basePath, appRouterInstance, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, deletePrefetchResponseSnapshot, getClientNavigationRenderContext, getMountedSlotsHeader, getPrefetchCache, hasPrefetchCacheEntryForNavigation, invalidatePrefetchCache, preloadHybridClientRouteOwner, pushHistoryStateWithoutNotify, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveLoadedHybridClientRewriteHref, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, seedPrefetchResponseSnapshot, setClientParams, setMountedSlotsHeader, setPendingPathname, useRouter } from "../shims/navigation.js";
28
+ import { DYNAMIC_NAVIGATION_CACHE_TTL, PREFETCH_CACHE_TTL, __basePath, appRouterInstance, commitClientNavigationState, consumePrefetchResponse, consumePrefetchResponseForNavigation, createCachedRscResponseSnapshot, createClientNavigationRenderSnapshot, createSnapshotPathAndSearch, deletePrefetchResponseSnapshot, disableNavigationResponsePrefetchCacheReuse, getClientNavigationRenderContext, getMountedSlotsHeader, getPrefetchCache, hasPrefetchCacheEntryForNavigation, invalidatePrefetchCache, preloadHybridClientRouteOwner, pushHistoryStateWithoutNotify, replaceClientParamsWithoutNotify, replaceHistoryStateWithoutNotify, resolveLoadedHybridClientRewriteHref, resolvePrefetchCacheEntryMountedSlotsHeader, restoreRscResponse, saveScrollPosition, seedPrefetchResponseSnapshot, setClientParams, setMountedSlotsHeader, setPendingPathname, useRouter } from "../shims/navigation.js";
29
+ import { createBfcacheSegmentIdentityMap, createInitialBfcacheIdMap } from "./app-bfcache-identity.js";
30
+ import { createDiscardedServerActionRefreshScheduler, createServerActionInitiationSnapshot, resolveServerActionOperationLane } from "./app-browser-action-result.js";
31
+ import { createClientReuseManifestHeaderFromVisibleAppState } from "./app-browser-client-reuse-manifest.js";
29
32
  import { chunksToReadableStream, createProgressiveRscStream, getVinextBrowserGlobal } from "./app-browser-stream.js";
30
33
  import { COMMITTED_CACHE_APP_NAVIGATION_PAYLOAD_ORIGIN, FRESH_APP_NAVIGATION_PAYLOAD_ORIGIN, VISITED_CACHE_APP_NAVIGATION_PAYLOAD_ORIGIN, isCacheRestorableAppPayloadMetadata, isCompleteAppPayloadMetadata, resolveInterceptionContextFromPreviousNextUrl } from "./app-browser-state.js";
31
34
  import { clearHardNavigationLoopGuard, createAppBrowserNavigationController, createBasePathStrippedPathAndSearch } from "./app-browser-navigation-controller.js";
35
+ import { shouldRecoverSamePathSearchCommitOnResponseCompletion } from "./app-browser-navigation-response.js";
36
+ import { createSupplementalRefreshCoordinator, mergeRefreshedParallelSlot, requireCompleteSupplementalRefresh, resolvePersistedSourcePageRefreshes, resolveServerActionSupplementalRefresh, resolveSupplementalRefreshes } from "./app-browser-supplemental-refresh.js";
37
+ import { createAppBrowserNavigationAbortCoordinator } from "./app-browser-navigation-abort.js";
32
38
  import { consumeInitialFormState, createVinextHydrateRootOptions, hydrateRootInTransition } from "./app-browser-hydration.js";
33
39
  import { AppBrowserHistoryController } from "./app-browser-history-controller.js";
34
- import { createVisitedResponseCacheEntry, deleteVisitedResponseCacheEntry, findVisitedResponseCacheEntry, isVisitedResponseCacheEntryFresh } from "./app-visited-response-cache.js";
35
- import { createPopstateRestoreHandler, restoreSynchronousPopstateScrollPosition } from "./app-browser-popstate.js";
40
+ import { createVisitedResponseCacheEntry, deleteAllVisitedResponseCacheEntries, deleteInvalidatedHistoryRestoreEntries, deleteVisitedResponseCacheEntry, findVisitedResponseCacheEntry, hasNavigationResponseHistoryLifetime, isVisitedResponseCacheEntryFresh } from "./app-visited-response-cache.js";
41
+ import { createPopstateRestoreHandler, restoreSynchronousPopstateScrollPosition, shouldCommitPopstateUrlWithoutNavigation } from "./app-browser-popstate.js";
36
42
  import { createDevOnCaughtError, createOnUncaughtError, createProdOnCaughtError, prodOnRecoverableError } from "./app-browser-error.js";
37
43
  import { createHydrationCachePublication } from "./app-hydration-cache-publication.js";
38
44
  import { peekSettledPrefetchResponseForNavigation, prepareConsumedPrefetchResponseForPublication, preserveCommittedPrefetchExpiry, resolvePrefetchNavigationResponseUrl } from "./app-browser-prefetch-response.js";
39
- import { createOptimisticRouteTemplate, getOptimisticPrefetchSourceKey, getOptimisticRouteTemplateKey, matchOptimisticRouteManifestRoute, resolveOptimisticNavigationPayload } from "./app-optimistic-routing.js";
45
+ import { canCommitOptimisticRouteTemplate, createOptimisticRouteTemplate, getOptimisticPrefetchSourceKey, getOptimisticRouteTemplateKey, matchOptimisticRouteManifestRoute, resolveOptimisticNavigationPayload } from "./app-optimistic-routing.js";
40
46
  import { removeStylesheetLinksCoveredByInlineCss } from "./app-inline-css-client.js";
41
47
  import { createElement, startTransition, use, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
42
48
  import { flushSync } from "react-dom";
@@ -83,6 +89,7 @@ const historyController = new AppBrowserHistoryController({
83
89
  if (!hasBrowserRouterState()) return null;
84
90
  const routerState = getBrowserRouterState();
85
91
  return {
92
+ activeRoutePaths: resolveActiveRoutePaths(routerState.slotBindings),
86
93
  bfcacheIds: routerState.bfcacheIds,
87
94
  previousNextUrl: routerState.previousNextUrl
88
95
  };
@@ -101,6 +108,7 @@ const discardedServerActionRefreshScheduler = hasServerActions ? createDiscarded
101
108
  markNavigationStart() {},
102
109
  schedule() {}
103
110
  };
111
+ const serverActionSupplementalRefreshCoordinator = createSupplementalRefreshCoordinator();
104
112
  const NavigationCommitSignal = browserNavigationController.NavigationCommitSignal;
105
113
  const ACTION_HTTP_FALLBACK_ROBOTS_META_ATTR = "data-vinext-action-http-fallback";
106
114
  function syncServerActionHttpFallbackHead(status) {
@@ -140,13 +148,15 @@ function waitForRscHmrSettle(delayMs = RSC_HMR_SETTLE_DELAY_MS) {
140
148
  window.setTimeout(resolve, delayMs);
141
149
  });
142
150
  }
143
- function restoreHistoryStateSnapshot(historyState, navId, onApprovedBeforeCommit) {
151
+ function restoreHistoryStateSnapshot(historyState, navId, onApprovedBeforeCommit, restoreCopiedExternalHistoryEntry = false) {
144
152
  let restored = false;
145
153
  flushSync(() => {
146
154
  restored = historyController.restoreHistorySnapshot({
147
155
  historyState,
156
+ preferExternalSnapshot: restoreCopiedExternalHistoryEntry,
148
157
  stageClientParams,
149
158
  approveVisibleRestore: ({ state, beforeCommit }) => browserNavigationController.restoreHistorySnapshotVisibleState({
159
+ restoreCopiedExternalHistoryEntry,
150
160
  beforeCommit: () => {
151
161
  onApprovedBeforeCommit?.();
152
162
  beforeCommit();
@@ -158,6 +168,9 @@ function restoreHistoryStateSnapshot(historyState, navId, onApprovedBeforeCommit
158
168
  });
159
169
  });
160
170
  if (!restored) return false;
171
+ clientNavigationCacheGeneration += 1;
172
+ deleteInvalidatedHistoryRestoreEntries(visitedResponseCache);
173
+ disableNavigationResponsePrefetchCacheReuse();
161
174
  commitClientNavigationState(navId, { releaseSnapshot: false });
162
175
  return true;
163
176
  }
@@ -196,6 +209,57 @@ function clearClientNavigationCaches() {
196
209
  clearPrefetchState();
197
210
  historyController.invalidateRestorableClientState();
198
211
  }
212
+ function getMatchedUrlPathname(matchedUrl) {
213
+ return new URL(matchedUrl, "https://vinext.local").pathname;
214
+ }
215
+ function resolvePersistedRefreshInterceptions(state, routeManifest, refreshUrl, requestInterceptionContext) {
216
+ if (routeManifest === null) return [];
217
+ const refreshPathParts = splitPathnameForRouteMatch(stripBasePath(refreshUrl.pathname, __basePath));
218
+ const resolved = [];
219
+ for (const binding of state.slotBindings) {
220
+ if (binding.state !== "active" || !binding.activeRouteId) continue;
221
+ if (!binding.interceptionId || !binding.interceptionSourceMatchedUrl) continue;
222
+ const activeRoute = AppElementsWire.parseElementKey(binding.activeRouteId);
223
+ if (activeRoute?.kind !== "route") continue;
224
+ const match = routeManifest.segmentGraph.interceptions.get(binding.interceptionId);
225
+ if (!match) continue;
226
+ const retainedInterception = state.interception?.slotId === binding.slotId && matchRoutePattern(splitPathnameForRouteMatch(getMatchedUrlPathname(state.interception.targetMatchedUrl)), match.targetPatternParts) !== null ? state.interception : null;
227
+ const targetPathname = retainedInterception?.targetMatchedUrl ?? activeRoute.path;
228
+ const targetParts = splitPathnameForRouteMatch(getMatchedUrlPathname(targetPathname));
229
+ if (requestInterceptionContext !== null && state.interception?.slotId === binding.slotId && matchRoutePattern(refreshPathParts, match.targetPatternParts) !== null && matchRoutePattern(targetParts, match.targetPatternParts) !== null) continue;
230
+ const targetUrl = new URL(targetPathname, refreshUrl);
231
+ targetUrl.pathname = addBasePathToPathname(targetUrl.pathname, __basePath);
232
+ targetUrl.search = refreshUrl.search;
233
+ resolved.push({
234
+ interception: match,
235
+ interceptionContext: retainedInterception?.sourceMatchedUrl ?? binding.interceptionSourceMatchedUrl,
236
+ targetPathname: `${targetUrl.pathname}${targetUrl.search}`
237
+ });
238
+ }
239
+ return resolved;
240
+ }
241
+ async function fetchPersistedInterceptedSlotRefresh(options) {
242
+ const headers = createRscRequestHeaders({
243
+ interceptionContext: options.interceptionContext,
244
+ interceptionId: options.interceptionId,
245
+ mountedSlotsHeader: options.mountedSlotsHeader
246
+ });
247
+ const response = await fetch(await createRscRequestUrl(options.targetPathname, headers), {
248
+ credentials: "include",
249
+ headers,
250
+ signal: options.signal
251
+ });
252
+ return decodeAppElementsPromise(createFromFetch(Promise.resolve(response)));
253
+ }
254
+ async function fetchPersistedSourcePageRefresh(options) {
255
+ const headers = createRscRequestHeaders({ mountedSlotsHeader: options.mountedSlotsHeader });
256
+ const response = await fetch(await createRscRequestUrl(options.targetPathname, headers), {
257
+ credentials: "include",
258
+ headers,
259
+ signal: options.signal
260
+ });
261
+ return decodeAppElementsPromise(createFromFetch(Promise.resolve(response)));
262
+ }
199
263
  function isSettledPrefetchCacheEntry(entry) {
200
264
  return entry.outcome === "cache-seeded" && entry.pending === void 0 && entry.snapshot !== void 0;
201
265
  }
@@ -272,13 +336,14 @@ function createActionInitiationSnapshot() {
272
336
  });
273
337
  }
274
338
  function createNavigationCommitEffect(options) {
275
- const { bfcacheIds, href, historyUpdateMode, navId, params, previousNextUrl, targetHistoryIndex } = options;
339
+ const { activeRoutePaths, bfcacheIds, href, historyUpdateMode, navId, params, previousNextUrl, targetHistoryIndex } = options;
276
340
  return () => {
277
341
  if (!browserNavigationController.isCurrentNavigation(navId)) {
278
342
  commitClientNavigationState(void 0, { releaseSnapshot: true });
279
343
  return;
280
344
  }
281
345
  historyController.commitNavigationHistory({
346
+ activeRoutePaths,
282
347
  bfcacheIds,
283
348
  href,
284
349
  historyUpdateMode,
@@ -298,6 +363,7 @@ async function renderNavigationPayload(options) {
298
363
  historyUpdateMode: options.historyUpdateMode,
299
364
  navigationCommitKind: options.navigationCommitKind,
300
365
  navigationInitiationState: options.navigationInitiationState,
366
+ navigationResponseCompletion: options.navigationResponseCompletion,
301
367
  navigationSnapshot: options.navigationSnapshot,
302
368
  navId: options.navId,
303
369
  nextElements: options.payload,
@@ -316,15 +382,62 @@ async function renderNavigationPayload(options) {
316
382
  });
317
383
  }
318
384
  async function commitSameUrlNavigatePayload(nextElements, actionInitiation, returnValue, revalidation = "none") {
385
+ let shouldRetrySupplementalRefresh = false;
386
+ let supplementalHandle = null;
387
+ if (revalidation !== "none") {
388
+ const refreshUrl = new URL(actionInitiation.href);
389
+ const requestInterceptionContext = resolveInterceptionContextFromPreviousNextUrl(actionInitiation.routerState.previousNextUrl, __basePath);
390
+ const persistedInterceptions = resolvePersistedRefreshInterceptions(actionInitiation.routerState, getBrowserRouteManifest(), refreshUrl, requestInterceptionContext);
391
+ const sourcePageRefreshes = resolvePersistedSourcePageRefreshes({
392
+ basePath: __basePath,
393
+ refreshUrl,
394
+ state: actionInitiation.routerState
395
+ }).filter((sourcePathname) => !persistedInterceptions.some((interception) => interception.targetPathname === sourcePathname));
396
+ if (persistedInterceptions.length > 0 || sourcePageRefreshes.length > 0) {
397
+ supplementalHandle = serverActionSupplementalRefreshCoordinator.begin({
398
+ activeNavigationId: browserNavigationController.getActiveNavigationId(),
399
+ startedNavigationId: actionInitiation.navigationId
400
+ });
401
+ const mountedSlotsHeader = getMountedSlotIdsHeader(actionInitiation.routerState.elements);
402
+ const supplemental = persistedInterceptions.map((interception) => (signal) => fetchPersistedInterceptedSlotRefresh({
403
+ interceptionContext: interception.interceptionContext,
404
+ interceptionId: interception.interception.id,
405
+ mountedSlotsHeader,
406
+ signal,
407
+ targetPathname: interception.targetPathname
408
+ }));
409
+ for (const sourcePageRefresh of sourcePageRefreshes) supplemental.push((signal) => fetchPersistedSourcePageRefresh({
410
+ mountedSlotsHeader,
411
+ signal,
412
+ targetPathname: sourcePageRefresh
413
+ }));
414
+ nextElements = resolveSupplementalRefreshes({
415
+ merge: mergeRefreshedParallelSlot,
416
+ primary: nextElements,
417
+ signal: supplementalHandle.signal,
418
+ supplemental
419
+ }).then((result) => {
420
+ const resolution = resolveServerActionSupplementalRefresh(result, actionInitiation.routerState.elements);
421
+ shouldRetrySupplementalRefresh ||= resolution.retry;
422
+ return resolution.value;
423
+ });
424
+ }
425
+ }
319
426
  const navigationSnapshot = createClientNavigationRenderSnapshot(actionInitiation.href, actionInitiation.routerState.navigationSnapshot.params);
320
- return browserNavigationController.commitSameUrlNavigatePayload(nextElements, navigationSnapshot, returnValue, actionInitiation.routerState, {
321
- onDiscardedRevalidation() {
322
- discardedServerActionRefreshScheduler.schedule();
323
- },
324
- revalidation,
325
- startedNavigationId: actionInitiation.navigationId,
326
- targetHref: actionInitiation.href
327
- });
427
+ try {
428
+ const result = await browserNavigationController.commitSameUrlNavigatePayload(nextElements, navigationSnapshot, returnValue, actionInitiation.routerState, {
429
+ onDiscardedRevalidation() {
430
+ discardedServerActionRefreshScheduler.schedule();
431
+ },
432
+ revalidation,
433
+ startedNavigationId: actionInitiation.navigationId,
434
+ targetHref: actionInitiation.href
435
+ });
436
+ if (shouldRetrySupplementalRefresh) discardedServerActionRefreshScheduler.schedule();
437
+ return result;
438
+ } finally {
439
+ supplementalHandle?.finish();
440
+ }
328
441
  }
329
442
  function evictVisitedResponseCacheIfNeeded() {
330
443
  while (visitedResponseCache.size >= MAX_VISITED_RESPONSE_CACHE_SIZE) {
@@ -371,9 +484,9 @@ function applyVisitedResponseCacheCandidateDecision(candidate, decision) {
371
484
  function deleteVisitedResponse(rscUrl, interceptionContext) {
372
485
  deleteVisitedResponseCacheEntry(visitedResponseCache, rscUrl, interceptionContext);
373
486
  }
374
- function storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, params, prefetchFallbackTtlMs = DYNAMIC_NAVIGATION_CACHE_TTL, requestMountedSlotsHeader = snapshot.mountedSlotsHeader ?? null, elements, seedPrefetchCache = true, prefetchSnapshot = snapshot) {
487
+ function storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, params, prefetchFallbackTtlMs = DYNAMIC_NAVIGATION_CACHE_TTL, requestMountedSlotsHeader = snapshot.mountedSlotsHeader ?? null, elements, seedPrefetchCache = true, prefetchSnapshot = snapshot, reuseAfterHistoryRestore = false) {
375
488
  const cacheKey = AppElementsWire.encodeCacheKey(rscUrl, interceptionContext);
376
- visitedResponseCache.delete(cacheKey);
489
+ deleteAllVisitedResponseCacheEntries(visitedResponseCache, rscUrl, interceptionContext);
377
490
  evictVisitedResponseCacheIfNeeded();
378
491
  const entry = createVisitedResponseCacheEntry({
379
492
  fallbackTtlMs: prefetchFallbackTtlMs,
@@ -381,10 +494,11 @@ function storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, par
381
494
  now: Date.now(),
382
495
  mountedSlotsHeader: requestMountedSlotsHeader,
383
496
  params,
384
- response: snapshot
497
+ response: snapshot,
498
+ reuseAfterHistoryRestore
385
499
  });
386
500
  visitedResponseCache.set(cacheKey, entry);
387
- if (seedPrefetchCache) seedPrefetchResponseSnapshot(rscUrl, prefetchSnapshot, interceptionContext, requestMountedSlotsHeader, prefetchFallbackTtlMs);
501
+ if (seedPrefetchCache) seedPrefetchResponseSnapshot(rscUrl, prefetchSnapshot, interceptionContext, requestMountedSlotsHeader, prefetchFallbackTtlMs, reuseAfterHistoryRestore);
388
502
  return () => {
389
503
  if (visitedResponseCache.get(cacheKey) === entry) visitedResponseCache.delete(cacheKey);
390
504
  if (seedPrefetchCache) deletePrefetchResponseSnapshot(rscUrl, prefetchSnapshot, interceptionContext);
@@ -467,6 +581,10 @@ function AppRouterRedirectBridge({ children }) {
467
581
  const handleUnhandledRedirect = (event) => {
468
582
  const error = "reason" in event ? event.reason : event.error;
469
583
  if (!isRedirectError(error)) return;
584
+ if ("handled" in error && error.handled === true) {
585
+ event.preventDefault();
586
+ return;
587
+ }
470
588
  const result = decodeRedirectError(error.digest);
471
589
  if (!result) return;
472
590
  event.preventDefault();
@@ -565,13 +683,15 @@ function BrowserRoot({ hydrationCachePublication, initialElements, initialNaviga
565
683
  useLayoutEffect(() => {
566
684
  if (treeState.renderId !== 0) return;
567
685
  historyController.writeHydratedHistoryMetadata({
686
+ activeRoutePaths: resolveActiveRoutePaths(treeState.slotBindings),
568
687
  bfcacheIds: treeState.bfcacheIds,
569
688
  previousNextUrl: treeState.previousNextUrl
570
689
  });
571
690
  }, [
572
691
  treeState.bfcacheIds,
573
692
  treeState.previousNextUrl,
574
- treeState.renderId
693
+ treeState.renderId,
694
+ treeState.slotBindings
575
695
  ]);
576
696
  const routeTree = createElement(RedirectBoundary, null, createElement(NavigationCommitSignal, { renderId: treeState.renderId }, createElement(ElementsContext.Provider, { value: treeState.elements }, createElement(Slot, { id: treeState.routeId }))));
577
697
  const bfcacheSegmentIdentities = useMemo(() => createBfcacheSegmentIdentityMap({ elements: treeState.elements }), [treeState.elements]);
@@ -599,6 +719,9 @@ function restoreHydrationNavigationContext(pathname, searchParams, params) {
599
719
  params
600
720
  });
601
721
  }
722
+ function restoreEmbeddedHydrationNavigationContext(pathname, searchParams, params, searchParamsFromBrowser) {
723
+ restoreHydrationNavigationContext(pathname, searchParamsFromBrowser ? window.location.search : searchParams, params);
724
+ }
602
725
  function restorePopstateScrollPosition(state, options) {
603
726
  const shouldContinue = options?.shouldContinue ?? (() => true);
604
727
  if (!shouldContinue()) return;
@@ -667,9 +790,7 @@ async function readInitialRscStream() {
667
790
  }
668
791
  return createProgressiveRscStream();
669
792
  }
670
- const params = vinext.__VINEXT_RSC_PARAMS__ ?? {};
671
793
  if (vinext.__VINEXT_RSC_PARAMS__) applyClientParams(vinext.__VINEXT_RSC_PARAMS__);
672
- if (vinext.__VINEXT_RSC_NAV__) restoreHydrationNavigationContext(vinext.__VINEXT_RSC_NAV__.pathname, vinext.__VINEXT_RSC_NAV__.searchParams, params);
673
794
  return createProgressiveRscStream();
674
795
  }
675
796
  const rscHeaders = createRscRequestHeaders();
@@ -694,7 +815,7 @@ async function readInitialRscStream() {
694
815
  function applyRuntimeRscBootstrap(rsc) {
695
816
  const params = rsc.params ?? {};
696
817
  if (rsc.params) applyClientParams(rsc.params);
697
- if (rsc.nav) restoreHydrationNavigationContext(rsc.nav.pathname, rsc.nav.searchParams, params);
818
+ if (rsc.nav) restoreEmbeddedHydrationNavigationContext(rsc.nav.pathname, rsc.nav.searchParams, params, rsc.searchParamsFromBrowser === true);
698
819
  }
699
820
  function registerServerActionCallback() {
700
821
  setServerCallback((id, args) => {
@@ -789,7 +910,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
789
910
  const fallbackTtlMs = initialRscBootstrap?.initialCacheKind === "static" ? PREFETCH_CACHE_TTL : DYNAMIC_NAVIGATION_CACHE_TTL;
790
911
  hydrationCachePublication.publish(() => {
791
912
  if (cacheGeneration !== clientNavigationCacheGeneration) return () => {};
792
- return storeVisitedResponseSnapshot(rscUrl, metadata.interceptionContext, snapshot, initialParams, fallbackTtlMs, mountedSlotsHeader, elements, false);
913
+ return storeVisitedResponseSnapshot(rscUrl, metadata.interceptionContext, snapshot, initialParams, fallbackTtlMs, mountedSlotsHeader, elements, false, snapshot, initialRscBootstrap?.initialCacheKind === "static" || metadata.interceptionContext !== null);
793
914
  });
794
915
  }).catch(() => {});
795
916
  historyController.writeBootstrapHistoryMetadata();
@@ -839,11 +960,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
839
960
  startTransition
840
961
  });
841
962
  markInitialAppRouterBootstrapHydrated();
842
- let activeNavigationAbortController = null;
843
- function abortSupersededNavigation() {
844
- activeNavigationAbortController?.abort();
845
- activeNavigationAbortController = null;
846
- }
963
+ const navigationAbortCoordinator = createAppBrowserNavigationAbortCoordinator();
847
964
  registerNavigationRuntimeFunctions({
848
965
  clearNavigationCaches: clearClientNavigationCaches,
849
966
  commitHashNavigation: (href, historyUpdateMode, scroll) => historyController.commitHashOnlyNavigation(href, historyUpdateMode, scroll),
@@ -867,10 +984,9 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
867
984
  routeId: state.routeId
868
985
  };
869
986
  },
870
- navigate: async function navigateRsc(href, redirectDepth = 0, navigationKind = "navigate", historyUpdateMode, previousNextUrlOverride, programmaticTransition = false, traversalIntent, scrollIntent, visibleCommitMode = "transition") {
871
- abortSupersededNavigation();
872
- const navigationAbortController = new AbortController();
873
- activeNavigationAbortController = navigationAbortController;
987
+ navigate: async function navigateRsc(href, redirectDepth = 0, navigationKind = "navigate", historyUpdateMode, previousNextUrlOverride, programmaticTransition = false, traversalIntent, scrollIntent, visibleCommitMode = "transition", initialBypassNavigationCache) {
988
+ serverActionSupplementalRefreshCoordinator.abortAll();
989
+ const navigationAbortHandle = navigationAbortCoordinator.begin();
874
990
  let pendingRouterState = null;
875
991
  const navId = browserNavigationController.beginNavigation();
876
992
  const navigationCacheGeneration = clientNavigationCacheGeneration;
@@ -905,16 +1021,33 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
905
1021
  const requestState = getRequestState(navigationKind, url.pathname, currentPrevNextUrl, activeTraversalIntent?.historyState);
906
1022
  const requestInterceptionContext = requestState.interceptionContext;
907
1023
  const requestPreviousNextUrl = requestState.previousNextUrl;
908
- if (navigationKind === "refresh") historyController.syncCurrentHistoryStatePreviousNextUrl(requestPreviousNextUrl, getBrowserRouterState().bfcacheIds);
1024
+ const shouldSupplementVisibleBranches = navigationKind === "refresh" || navigationKind === "traverse" && !reuseCurrentBfcacheIds;
1025
+ const persistedRefreshInterceptions = navigationKind === "refresh" ? resolvePersistedRefreshInterceptions(navigationInitiationState, getBrowserRouteManifest(), url, requestInterceptionContext) : [];
1026
+ const persistedSourcePageRefreshes = shouldSupplementVisibleBranches ? resolvePersistedSourcePageRefreshes({
1027
+ activeRoutePaths: navigationKind === "traverse" ? readHistoryStateActiveRoutePaths(activeTraversalIntent?.historyState) ?? [] : void 0,
1028
+ basePath: __basePath,
1029
+ refreshUrl: url,
1030
+ state: navigationKind === "traverse" ? {
1031
+ previousNextUrl: requestPreviousNextUrl,
1032
+ slotBindings: []
1033
+ } : navigationInitiationState
1034
+ }).filter((sourcePathAndSearch) => {
1035
+ if (persistedRefreshInterceptions.some((interception) => interception.targetPathname === sourcePathAndSearch)) return false;
1036
+ return true;
1037
+ }) : [];
1038
+ const hasSupplementalRefresh = persistedRefreshInterceptions.length > 0 || persistedSourcePageRefreshes.length > 0;
1039
+ if (navigationKind === "refresh") historyController.syncCurrentHistoryStatePreviousNextUrl(requestPreviousNextUrl, getBrowserRouterState().bfcacheIds, resolveActiveRoutePaths(getBrowserRouterState().slotBindings));
909
1040
  setPendingPathname(url.pathname, navId);
910
- const earlyIntentDecision = navigationKind === "navigate" ? navigationPlanner.classifyEarlyNavigationIntent({
1041
+ const usesInitialNavigationCachePolicy = navigationKind === "navigate" && currentHref === href && redirectCount === redirectDepth && initialBypassNavigationCache !== void 0;
1042
+ const earlyIntentDecision = navigationKind === "navigate" && !usesInitialNavigationCachePolicy ? navigationPlanner.classifyEarlyNavigationIntent({
911
1043
  basePath: __basePath,
1044
+ currentUrlSpace: "appRelativeSnapshot",
912
1045
  currentHref: clientNavigationSnapshotHref(navigationInitiationState.navigationSnapshot),
913
1046
  mode: "push",
914
1047
  scroll: false,
915
1048
  targetHref: url.href
916
1049
  }) : null;
917
- const shouldBypassNavigationCache = earlyIntentDecision?.kind === "flightNavigation" && earlyIntentDecision.bypassNavigationCache;
1050
+ const shouldBypassNavigationCache = usesInitialNavigationCachePolicy ? initialBypassNavigationCache : earlyIntentDecision?.kind === "flightNavigation" && earlyIntentDecision.bypassNavigationCache;
918
1051
  const requestHeaders = createRscRequestHeaders({
919
1052
  fetchPriority: "auto",
920
1053
  interceptionContext: requestInterceptionContext,
@@ -1089,7 +1222,15 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1089
1222
  routeManifest,
1090
1223
  templates: optimisticRouteTemplates
1091
1224
  });
1092
- if (optimisticPayload !== null) {
1225
+ if (optimisticPayload !== null && canCommitOptimisticRouteTemplate({
1226
+ currentElements: navigationInitiationState.elements,
1227
+ currentLayoutIds: navigationInitiationState.layoutIds,
1228
+ currentParams: navigationInitiationState.navigationSnapshot.params,
1229
+ routeManifest,
1230
+ targetRouteParams: optimisticPayload.routeParams,
1231
+ targetUrlParts: optimisticPayload.urlParts,
1232
+ template: optimisticPayload.template
1233
+ })) {
1093
1234
  detachedNavigationCommits = true;
1094
1235
  const optimisticNavigationSnapshot = createClientNavigationRenderSnapshot(currentHref, optimisticPayload.params);
1095
1236
  renderNavigationPayload({
@@ -1126,7 +1267,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1126
1267
  headers: requestHeaders,
1127
1268
  credentials: "include",
1128
1269
  priority: "auto",
1129
- signal: navigationAbortController.signal
1270
+ signal: navigationAbortHandle.signal
1130
1271
  });
1131
1272
  }
1132
1273
  if (!browserNavigationController.isCurrentNavigation(navId)) return;
@@ -1167,6 +1308,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1167
1308
  redirectCount = liveFetchDecision.redirect.redirectDepth;
1168
1309
  continue;
1169
1310
  }
1311
+ if (!hasSupplementalRefresh) navigationAbortHandle.release();
1170
1312
  const navParams = parseEncodedJsonHeader(navResponse.headers.get("X-Vinext-Params")) ?? {};
1171
1313
  const navigationSnapshot = createClientNavigationRenderSnapshot(currentHref, navParams);
1172
1314
  const navBody = navResponse.body;
@@ -1180,7 +1322,27 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1180
1322
  cacheBufferPromise.catch(() => {});
1181
1323
  if (!browserNavigationController.isCurrentNavigation(navId)) return;
1182
1324
  if (prefetchedElements) reactResponse.body?.cancel().catch(() => {});
1183
- const rscPayload = prefetchedElements ? prefetchedElements : decodeAppElementsPromise(createFromFetch(Promise.resolve(reactResponse)));
1325
+ let rscPayload = prefetchedElements ? prefetchedElements : decodeAppElementsPromise(createFromFetch(Promise.resolve(reactResponse)));
1326
+ if (hasSupplementalRefresh) {
1327
+ const supplemental = persistedRefreshInterceptions.map((interception) => (signal) => fetchPersistedInterceptedSlotRefresh({
1328
+ interceptionContext: interception.interceptionContext,
1329
+ interceptionId: interception.interception.id,
1330
+ mountedSlotsHeader,
1331
+ signal,
1332
+ targetPathname: interception.targetPathname
1333
+ }));
1334
+ for (const persistedSourcePageRefresh of persistedSourcePageRefreshes) supplemental.push((signal) => fetchPersistedSourcePageRefresh({
1335
+ mountedSlotsHeader,
1336
+ signal,
1337
+ targetPathname: persistedSourcePageRefresh
1338
+ }));
1339
+ rscPayload = resolveSupplementalRefreshes({
1340
+ merge: mergeRefreshedParallelSlot,
1341
+ primary: Promise.resolve(rscPayload),
1342
+ signal: navigationAbortHandle.signal,
1343
+ supplemental
1344
+ }).then(requireCompleteSupplementalRefresh);
1345
+ }
1184
1346
  if (!browserNavigationController.isCurrentNavigation(navId)) return;
1185
1347
  let committedState = null;
1186
1348
  if (await renderNavigationPayload({
@@ -1189,10 +1351,17 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1189
1351
  navigationCommitKind: detachedNavigationCommits ? "authoritative" : void 0,
1190
1352
  navigationInitiationState,
1191
1353
  navigationSnapshot,
1354
+ navigationResponseCompletion: shouldRecoverSamePathSearchCommitOnResponseCompletion({
1355
+ basePath: __basePath,
1356
+ currentSnapshot: navigationInitiationState.navigationSnapshot,
1357
+ navigationKind,
1358
+ programmaticTransition,
1359
+ targetUrl: url
1360
+ }) ? cacheBufferPromise : void 0,
1192
1361
  navId,
1193
1362
  onCommittedState: (state) => {
1194
1363
  committedState = state;
1195
- if (activeNavigationAbortController === navigationAbortController) activeNavigationAbortController = null;
1364
+ navigationAbortHandle.release();
1196
1365
  },
1197
1366
  operationLane: toOperationLane(navigationKind),
1198
1367
  params: navParams,
@@ -1207,6 +1376,10 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1207
1376
  traversalIntent: activeTraversalIntent,
1208
1377
  visibleCommitMode: prefetchedElements ? "synchronous" : visibleCommitMode
1209
1378
  }) !== "committed") return;
1379
+ if (hasSupplementalRefresh) {
1380
+ clearVisitedResponseCache();
1381
+ return;
1382
+ }
1210
1383
  committedState ??= getBrowserRouterState();
1211
1384
  try {
1212
1385
  const renderedElements = await rscPayload;
@@ -1227,7 +1400,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1227
1400
  const interceptionContext = resolveVisitedResponseInterceptionContext(requestInterceptionContext, metadata.interceptionContext);
1228
1401
  if (cacheRestorable) {
1229
1402
  if (navigationCacheGeneration !== clientNavigationCacheGeneration) return;
1230
- storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, navParams, PREFETCH_CACHE_TTL, mountedSlotsHeader, void 0, true, prefetchSnapshot);
1403
+ storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, navParams, PREFETCH_CACHE_TTL, mountedSlotsHeader, void 0, true, prefetchSnapshot, true);
1231
1404
  } else {
1232
1405
  const state = committedState;
1233
1406
  const committedElements = {
@@ -1238,7 +1411,7 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1238
1411
  [AppElementsWire.keys.slotBindings]: state.slotBindings
1239
1412
  };
1240
1413
  if (navigationCacheGeneration !== clientNavigationCacheGeneration) return;
1241
- storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, navParams, DYNAMIC_NAVIGATION_CACHE_TTL, mountedSlotsHeader, committedElements, true, prefetchSnapshot);
1414
+ storeVisitedResponseSnapshot(rscUrl, interceptionContext, snapshot, navParams, DYNAMIC_NAVIGATION_CACHE_TTL, mountedSlotsHeader, committedElements, true, prefetchSnapshot, interceptionContext !== null || hasNavigationResponseHistoryLifetime(snapshot));
1242
1415
  }
1243
1416
  } catch {}
1244
1417
  return;
@@ -1248,12 +1421,14 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1248
1421
  if (!isPageUnloading) console.error("[vinext] RSC navigation error:", error);
1249
1422
  performHardNavigationForScrollIntent(navigationPlanner.classifyRscNavigationError({ currentHref }).url);
1250
1423
  } finally {
1251
- if (activeNavigationAbortController === navigationAbortController) activeNavigationAbortController = null;
1424
+ navigationAbortHandle.release();
1252
1425
  browserNavigationController.finalizeNavigation(navId, pendingRouterState);
1253
1426
  discardedServerActionRefreshScheduler.markNavigationSettled();
1254
1427
  }
1255
1428
  },
1256
- preparePrefetchResponse: (response) => decodeAppElementsPromise(createFromFetch(Promise.resolve(response)))
1429
+ preparePrefetchResponse: (response) => decodeAppElementsPromise(createFromFetch(Promise.resolve(response))),
1430
+ claimCurrentHistoryTreeSnapshot: (historyUpdateMode, previousHistoryState) => historyController.claimCurrentHistoryTreeSnapshot(historyUpdateMode, previousHistoryState),
1431
+ commitAppOwnedHistoryStateWrite: (historyUpdateMode, previousHistoryState) => historyController.commitAppOwnedHistoryStateWrite(historyUpdateMode, previousHistoryState)
1257
1432
  });
1258
1433
  const handlePopstate = createPopstateRestoreHandler({
1259
1434
  getActiveNavigationId: browserNavigationController.getActiveNavigationId.bind(browserNavigationController),
@@ -1271,17 +1446,23 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
1271
1446
  });
1272
1447
  window.addEventListener("popstate", (event) => {
1273
1448
  const href = window.location.href;
1274
- if (isSameAppRoutePopstateTarget(href)) {
1449
+ const isExternalHistoryEntry = isExternalHistoryState(event.state);
1450
+ if (shouldCommitPopstateUrlWithoutNavigation({
1451
+ historyState: event.state,
1452
+ isCurrentExternalHistoryTree: historyController.isCurrentExternalHistoryTree(event.state),
1453
+ isSameAppRouteTarget: isSameAppRoutePopstateTarget(href)
1454
+ })) {
1275
1455
  notifyAppRouterTransitionStart(href, "traverse");
1276
1456
  historyController.commitTraversalIndexFromHistoryState(event.state);
1457
+ commitClientNavigationState();
1277
1458
  restorePopstateScrollPosition(event.state);
1278
1459
  return;
1279
1460
  }
1280
1461
  const snapshotNavigationId = browserNavigationController.beginNavigation();
1281
1462
  if (restoreHistoryStateSnapshot(event.state, snapshotNavigationId, () => {
1282
- abortSupersededNavigation();
1463
+ navigationAbortCoordinator.abortActive();
1283
1464
  notifyAppRouterTransitionStart(href, "traverse");
1284
- })) {
1465
+ }, isExternalHistoryEntry)) {
1285
1466
  window.__VINEXT_RSC_PENDING__ = null;
1286
1467
  restoreSynchronousPopstateScrollPosition({
1287
1468
  getActiveNavigationId: () => browserNavigationController.getActiveNavigationId(),
@@ -7,7 +7,6 @@ type HydrateRootErrorHandler = (error: unknown, errorInfo: VinextHydrateRootErro
7
7
  declare function createOnUncaughtError(): HydrateRootErrorHandler;
8
8
  declare function createProdOnCaughtError(onImplicitRootError: HydrateRootErrorHandler): HydrateRootErrorHandler;
9
9
  declare function createDevOnCaughtError(onCaughtError: HydrateRootErrorHandler, onImplicitRootError: HydrateRootErrorHandler): HydrateRootErrorHandler;
10
- declare function prodOnCaughtError(error: unknown, errorInfo: VinextHydrateRootErrorInfo): void;
11
10
  declare function prodOnRecoverableError(error: unknown): void;
12
11
  //#endregion
13
- export { createDevOnCaughtError, createOnUncaughtError, createProdOnCaughtError, prodOnCaughtError, prodOnRecoverableError };
12
+ export { createDevOnCaughtError, createOnUncaughtError, createProdOnCaughtError, prodOnRecoverableError };
@@ -41,12 +41,8 @@ function createDevOnCaughtError(onCaughtError, onImplicitRootError) {
41
41
  onCaughtError(error, errorInfo);
42
42
  };
43
43
  }
44
- function prodOnCaughtError(error, errorInfo) {
45
- if (isNavigationSignalError(error)) return;
46
- logCaughtError(error, errorInfo);
47
- }
48
44
  function prodOnRecoverableError(error) {
49
45
  reportGlobalError(error instanceof Error && error.cause !== void 0 ? error.cause : error);
50
46
  }
51
47
  //#endregion
52
- export { createDevOnCaughtError, createOnUncaughtError, createProdOnCaughtError, prodOnCaughtError, prodOnRecoverableError };
48
+ export { createDevOnCaughtError, createOnUncaughtError, createProdOnCaughtError, prodOnRecoverableError };
@@ -8,6 +8,7 @@ import { HistoryUpdateMode } from "./app-browser-navigation-controller.js";
8
8
  * falls back to reading the same facts off the live history entry.
9
9
  */
10
10
  type VisibleNavigationMetadata = {
11
+ activeRoutePaths: readonly string[] | null;
11
12
  bfcacheIds: BfcacheIdMap | null;
12
13
  previousNextUrl: string | null;
13
14
  };
@@ -37,10 +38,12 @@ type RestorableSnapshotCandidate = {
37
38
  };
38
39
  type RestoreHistorySnapshotOptions = {
39
40
  historyState: unknown;
41
+ preferExternalSnapshot?: boolean;
40
42
  stageClientParams: (params: Record<string, string | string[]>) => void;
41
43
  approveVisibleRestore: (candidate: RestorableSnapshotCandidate) => boolean;
42
44
  };
43
45
  type CommitNavigationHistoryOptions = {
46
+ activeRoutePaths: readonly string[];
44
47
  bfcacheIds: BfcacheIdMap;
45
48
  href: string;
46
49
  historyUpdateMode: HistoryUpdateMode | undefined;
@@ -76,6 +79,17 @@ declare class AppBrowserHistoryController {
76
79
  beginCacheInvalidationGuard(): () => void;
77
80
  invalidateRestorableClientState(): void;
78
81
  rememberHistoryStateSnapshot(state: AppRouterState): void;
82
+ isCurrentExternalHistoryTree(historyState: unknown): boolean;
83
+ /** Records the raw/hash history entry that now claims the live tree. */
84
+ claimCurrentHistoryTreeSnapshot(historyUpdateMode: HistoryUpdateMode, previousHistoryState: unknown): void;
85
+ /**
86
+ * Applies only the claim cleanup caused by a successful raw History API write
87
+ * whose caller state is already app-owned. The browser write intentionally
88
+ * bypasses external-tree claiming (matching Next.js' `data?.__NA` path), but
89
+ * it still overwrites or truncates entries that may own retained snapshots.
90
+ * Every cleanup operation is idempotent so duplicate runtime delivery is safe.
91
+ */
92
+ commitAppOwnedHistoryStateWrite(historyUpdateMode: HistoryUpdateMode, previousHistoryState: unknown): void;
79
93
  commitHashOnlyNavigation(href: string, historyUpdateMode: HistoryUpdateMode, scroll: boolean): void;
80
94
  /**
81
95
  * Writes the history entry for an approved push/replace/traverse commit and
@@ -85,11 +99,12 @@ declare class AppBrowserHistoryController {
85
99
  * into the history entry during the navigation commit.
86
100
  */
87
101
  commitNavigationHistory(options: CommitNavigationHistoryOptions): void;
88
- syncCurrentHistoryStatePreviousNextUrl(previousNextUrl: string | null, bfcacheIds?: BfcacheIdMap | null): void;
102
+ syncCurrentHistoryStatePreviousNextUrl(previousNextUrl: string | null, bfcacheIds?: BfcacheIdMap | null, activeRoutePaths?: readonly string[] | null): void;
89
103
  /** Initial history write performed before hydration starts. */
90
104
  writeBootstrapHistoryMetadata(): void;
91
105
  /** History write performed on the first committed (hydrated) render. */
92
106
  writeHydratedHistoryMetadata(options: {
107
+ activeRoutePaths: readonly string[];
93
108
  bfcacheIds: BfcacheIdMap;
94
109
  previousNextUrl: string | null;
95
110
  }): void;