vinext 0.0.42 → 0.0.43
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.
- package/dist/entries/app-rsc-entry.js +29 -7
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/routing/app-router.js +23 -3
- package/dist/routing/app-router.js.map +1 -1
- package/dist/server/app-browser-entry.js +96 -27
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-route-handler-policy.js +5 -3
- package/dist/server/app-route-handler-policy.js.map +1 -1
- package/dist/server/app-route-handler-response.js +2 -0
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/shims/navigation.d.ts +1 -1
- package/dist/shims/navigation.js +15 -5
- package/dist/shims/navigation.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-browser-entry.js","names":[],"sources":["../../src/server/app-browser-entry.ts"],"sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport {\n createElement,\n startTransition,\n use,\n useLayoutEffect,\n useReducer,\n useRef,\n type Dispatch,\n type ReactNode,\n} from \"react\";\nimport {\n createFromFetch,\n createFromReadableStream,\n createTemporaryReferenceSet,\n encodeReply,\n setServerCallback,\n} from \"@vitejs/plugin-rsc/browser\";\nimport { hydrateRoot } from \"react-dom/client\";\nimport \"../client/instrumentation-client.js\";\nimport { notifyAppRouterTransitionStart } from \"../client/instrumentation-client-state.js\";\nimport {\n __basePath,\n activateNavigationSnapshot,\n clearPendingPathname,\n commitClientNavigationState,\n consumePrefetchResponse,\n createClientNavigationRenderSnapshot,\n getCurrentNextUrl,\n getCurrentInterceptionContext,\n getClientNavigationRenderContext,\n getClientNavigationState,\n getPrefetchCache,\n getPrefetchedUrls,\n pushHistoryStateWithoutNotify,\n replaceClientParamsWithoutNotify,\n replaceHistoryStateWithoutNotify,\n restoreRscResponse,\n setClientParams,\n setPendingPathname,\n snapshotRscResponse,\n setMountedSlotsHeader,\n setNavigationContext,\n toRscUrl,\n type CachedRscResponse,\n type ClientNavigationRenderSnapshot,\n} from \"../shims/navigation.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport {\n chunksToReadableStream,\n createProgressiveRscStream,\n getVinextBrowserGlobal,\n} from \"./app-browser-stream.js\";\nimport {\n createAppPayloadCacheKey,\n getMountedSlotIdsHeader,\n normalizeAppElements,\n readAppElementsMetadata,\n resolveVisitedResponseInterceptionContext,\n type AppElements,\n type AppWireElements,\n type LayoutFlags,\n} from \"./app-elements.js\";\nimport {\n createHistoryStateWithPreviousNextUrl,\n createPendingNavigationCommit,\n readHistoryStatePreviousNextUrl,\n resolveAndClassifyNavigationCommit,\n resolveInterceptionContextFromPreviousNextUrl,\n resolvePendingNavigationCommitDisposition,\n resolveServerActionRequestState,\n routerReducer,\n type AppRouterAction,\n type AppRouterState,\n} from \"./app-browser-state.js\";\nimport { ElementsContext, Slot } from \"../shims/slot.js\";\nimport { devOnCaughtError } from \"./app-browser-error.js\";\n\ntype SearchParamInput = ConstructorParameters<typeof URLSearchParams>[0];\n\ntype ServerActionResult = {\n root: AppWireElements;\n returnValue?: {\n ok: boolean;\n data: unknown;\n };\n};\n\ntype NavigationKind = \"navigate\" | \"traverse\" | \"refresh\";\n\n// Maps NavigationKind to the AppRouterAction type used by the reducer.\n// \"refresh\" is intentionally treated as \"navigate\" (merge, preserve absent slots).\n// Both call sites must stay in sync — update here if NavigationKind gains new values.\nfunction toActionType(kind: NavigationKind): \"navigate\" | \"traverse\" {\n return kind === \"traverse\" ? \"traverse\" : \"navigate\";\n}\n\ntype HistoryUpdateMode = \"push\" | \"replace\";\ntype VisitedResponseCacheEntry = {\n params: Record<string, string | string[]>;\n expiresAt: number;\n response: CachedRscResponse;\n};\n\nconst MAX_VISITED_RESPONSE_CACHE_SIZE = 50;\nconst VISITED_RESPONSE_CACHE_TTL = 5 * 60_000;\nconst MAX_TRAVERSAL_CACHE_TTL = 30 * 60_000;\n\n// These are plain module-level variables, unlike ClientNavigationState in\n// navigation.ts which uses Symbol.for to survive multiple Vite module instances.\n// The browser entry is loaded exactly once (via the RSC plugin's generated\n// bootstrap), so module-level state is safe here. If that assumption ever\n// changes, these should be migrated to a Symbol.for-backed global.\n//\n// The most severe consequence of multiple instances would be Map fragmentation:\n// pendingNavigationCommits and pendingNavigationPrePaintEffects would split\n// across instances, so drainPrePaintEffects in one instance could never drain\n// effects queued by the other, permanently leaking navigationSnapshotActiveCount\n// and causing hooks to prefer stale snapshot values indefinitely.\nlet nextNavigationRenderId = 0;\nlet activeNavigationId = 0;\nconst pendingNavigationCommits = new Map<number, () => void>();\nconst pendingNavigationPrePaintEffects = new Map<number, () => void>();\nlet dispatchBrowserRouterAction: Dispatch<AppRouterAction> | null = null;\nlet browserRouterStateRef: { current: AppRouterState } | null = null;\nlet latestClientParams: Record<string, string | string[]> = {};\nconst visitedResponseCache = new Map<string, VisitedResponseCacheEntry>();\n\nfunction isServerActionResult(value: unknown): value is ServerActionResult {\n return !!value && typeof value === \"object\" && \"root\" in value;\n}\n\nfunction getBrowserRouterDispatch(): Dispatch<AppRouterAction> {\n if (!dispatchBrowserRouterAction) {\n throw new Error(\"[vinext] Browser router dispatch is not initialized\");\n }\n return dispatchBrowserRouterAction;\n}\n\nfunction getBrowserRouterState(): AppRouterState {\n if (!browserRouterStateRef) {\n throw new Error(\"[vinext] Browser router state is not initialized\");\n }\n return browserRouterStateRef.current;\n}\n\nfunction applyClientParams(params: Record<string, string | string[]>): void {\n latestClientParams = params;\n setClientParams(params);\n}\n\nfunction stageClientParams(params: Record<string, string | string[]>): void {\n // NB: latestClientParams diverges from ClientNavigationState.clientParams\n // between staging and commit. Server action snapshots (same-URL\n // commitSameUrlNavigatePayload() calls inside registerServerActionCallback)\n // read latestClientParams, so a\n // server action fired during this window would get the pending (not yet\n // committed) params. This is acceptable because the commit effect fires\n // before hooks observe the new URL state, keeping the window vanishingly small.\n latestClientParams = params;\n replaceClientParamsWithoutNotify(params);\n}\n\nfunction clearVisitedResponseCache(): void {\n visitedResponseCache.clear();\n}\n\nfunction clearPrefetchState(): void {\n getPrefetchCache().clear();\n getPrefetchedUrls().clear();\n}\n\nfunction clearClientNavigationCaches(): void {\n clearVisitedResponseCache();\n clearPrefetchState();\n}\n\nfunction queuePrePaintNavigationEffect(renderId: number, effect: (() => void) | null): void {\n if (!effect) {\n return;\n }\n pendingNavigationPrePaintEffects.set(renderId, effect);\n}\n\n/**\n * Run all queued pre-paint effects for renderIds up to and including the\n * given renderId. When React supersedes a startTransition update (rapid\n * clicks on same-route links), the superseded NavigationCommitSignal never\n * mounts, so its pre-paint effect never fires. By draining all effects\n * <= the committed renderId here, the winning transition cleans up after\n * any superseded ones, keeping the counter balanced.\n *\n * Invariant: each superseded navigation gets a commitClientNavigationState()\n * to balance the activateNavigationSnapshot() from its renderNavigationPayload call.\n */\nfunction drainPrePaintEffects(upToRenderId: number): void {\n for (const [id, effect] of pendingNavigationPrePaintEffects) {\n if (id <= upToRenderId) {\n pendingNavigationPrePaintEffects.delete(id);\n if (id === upToRenderId) {\n // Winning navigation: run its actual pre-paint effect\n effect();\n } else {\n // Superseded navigation: balance its activateNavigationSnapshot().\n // Pass undefined navId intentionally so this cleanup cannot clear\n // pendingPathname owned by the current active navigation.\n commitClientNavigationState(undefined);\n }\n }\n }\n}\n\nfunction createNavigationCommitEffect(\n href: string,\n historyUpdateMode: HistoryUpdateMode | undefined,\n navId: number,\n params: Record<string, string | string[]>,\n previousNextUrl: string | null,\n): () => void {\n return () => {\n // Only update URL if this is still the active navigation.\n // A newer navigation would have incremented activeNavigationId.\n if (navId !== activeNavigationId) {\n // This transition was superseded before commit; balance the active\n // snapshot counter without clearing pendingPathname ownership.\n commitClientNavigationState(undefined);\n return;\n }\n\n const targetHref = new URL(href, window.location.origin).href;\n stageClientParams(params);\n const preserveExistingState = historyUpdateMode === \"replace\";\n const historyState = createHistoryStateWithPreviousNextUrl(\n preserveExistingState ? window.history.state : null,\n previousNextUrl,\n );\n\n if (historyUpdateMode === \"replace\" && window.location.href !== targetHref) {\n replaceHistoryStateWithoutNotify(historyState, \"\", href);\n } else if (historyUpdateMode === \"push\" && window.location.href !== targetHref) {\n pushHistoryStateWithoutNotify(historyState, \"\", href);\n }\n\n commitClientNavigationState(navId);\n };\n}\n\nfunction evictVisitedResponseCacheIfNeeded(): void {\n while (visitedResponseCache.size >= MAX_VISITED_RESPONSE_CACHE_SIZE) {\n const oldest = visitedResponseCache.keys().next().value;\n if (oldest === undefined) {\n return;\n }\n visitedResponseCache.delete(oldest);\n }\n}\n\nfunction getVisitedResponse(\n rscUrl: string,\n interceptionContext: string | null,\n mountedSlotsHeader: string | null,\n navigationKind: NavigationKind,\n): VisitedResponseCacheEntry | null {\n const cacheKey = createAppPayloadCacheKey(rscUrl, interceptionContext);\n const cached = visitedResponseCache.get(cacheKey);\n if (!cached) {\n return null;\n }\n\n if ((cached.response.mountedSlotsHeader ?? null) !== mountedSlotsHeader) {\n visitedResponseCache.delete(cacheKey);\n return null;\n }\n\n if (navigationKind === \"refresh\") {\n return null;\n }\n\n if (navigationKind === \"traverse\") {\n const createdAt = cached.expiresAt - VISITED_RESPONSE_CACHE_TTL;\n if (Date.now() - createdAt >= MAX_TRAVERSAL_CACHE_TTL) {\n visitedResponseCache.delete(cacheKey);\n return null;\n }\n // LRU: promote to most-recently-used (delete + re-insert moves to end of Map)\n visitedResponseCache.delete(cacheKey);\n visitedResponseCache.set(cacheKey, cached);\n return cached;\n }\n\n if (cached.expiresAt > Date.now()) {\n // LRU: promote to most-recently-used\n visitedResponseCache.delete(cacheKey);\n visitedResponseCache.set(cacheKey, cached);\n return cached;\n }\n\n visitedResponseCache.delete(cacheKey);\n return null;\n}\n\nfunction storeVisitedResponseSnapshot(\n rscUrl: string,\n interceptionContext: string | null,\n snapshot: CachedRscResponse,\n params: Record<string, string | string[]>,\n): void {\n const cacheKey = createAppPayloadCacheKey(rscUrl, interceptionContext);\n visitedResponseCache.delete(cacheKey);\n evictVisitedResponseCacheIfNeeded();\n const now = Date.now();\n visitedResponseCache.set(cacheKey, {\n params,\n expiresAt: now + VISITED_RESPONSE_CACHE_TTL,\n response: snapshot,\n });\n}\n\ntype NavigationRequestState = {\n interceptionContext: string | null;\n previousNextUrl: string | null;\n};\n\nfunction getRequestState(\n navigationKind: NavigationKind,\n previousNextUrlOverride?: string | null,\n): NavigationRequestState {\n if (previousNextUrlOverride !== undefined) {\n return {\n interceptionContext: resolveInterceptionContextFromPreviousNextUrl(\n previousNextUrlOverride,\n __basePath,\n ),\n previousNextUrl: previousNextUrlOverride,\n };\n }\n\n switch (navigationKind) {\n case \"navigate\":\n return {\n interceptionContext: getCurrentInterceptionContext(),\n previousNextUrl: getCurrentNextUrl(),\n };\n case \"traverse\": {\n const previousNextUrl = readHistoryStatePreviousNextUrl(window.history.state);\n return {\n interceptionContext: resolveInterceptionContextFromPreviousNextUrl(\n previousNextUrl,\n __basePath,\n ),\n previousNextUrl,\n };\n }\n case \"refresh\": {\n const currentPreviousNextUrl = getBrowserRouterState().previousNextUrl;\n return {\n interceptionContext: resolveInterceptionContextFromPreviousNextUrl(\n currentPreviousNextUrl,\n __basePath,\n ),\n previousNextUrl: currentPreviousNextUrl,\n };\n }\n default: {\n const _exhaustive: never = navigationKind;\n throw new Error(\"[vinext] Unknown navigation kind: \" + String(_exhaustive));\n }\n }\n}\n\nfunction createRscRequestHeaders(interceptionContext: string | null): Headers {\n const headers = new Headers({ Accept: \"text/x-component\" });\n if (interceptionContext !== null) {\n headers.set(\"X-Vinext-Interception-Context\", interceptionContext);\n }\n return headers;\n}\n\n/**\n * Resolve all pending navigation commits with renderId <= the committed renderId.\n * Note: Map iteration handles concurrent deletion safely — entries are visited in\n * insertion order and deletion doesn't affect the iterator's view of remaining entries.\n * This pattern is also used in drainPrePaintEffects with the same semantics.\n */\nfunction resolveCommittedNavigations(renderId: number): void {\n for (const [pendingId, resolve] of pendingNavigationCommits) {\n if (pendingId <= renderId) {\n pendingNavigationCommits.delete(pendingId);\n resolve();\n }\n }\n}\n\nfunction NavigationCommitSignal({\n renderId,\n children,\n}: {\n renderId: number;\n children?: ReactNode;\n}) {\n useLayoutEffect(() => {\n drainPrePaintEffects(renderId);\n\n const frame = requestAnimationFrame(() => {\n resolveCommittedNavigations(renderId);\n });\n\n return () => {\n cancelAnimationFrame(frame);\n // Resolve pending commits to prevent callers from hanging if React\n // unmounts this component without committing (e.g., error boundary).\n resolveCommittedNavigations(renderId);\n };\n }, [renderId]);\n\n return children;\n}\n\nfunction normalizeAppElementsPromise(payload: Promise<AppWireElements>): Promise<AppElements> {\n // Wrap in Promise.resolve() because createFromReadableStream() returns a\n // React Flight thenable whose .then() returns undefined (not a new Promise).\n // Without the wrap, chaining .then() produces undefined → use() crashes.\n return Promise.resolve(payload).then((elements) => normalizeAppElements(elements));\n}\n\nasync function commitSameUrlNavigatePayload(\n nextElements: Promise<AppElements>,\n returnValue?: ServerActionResult[\"returnValue\"],\n): Promise<unknown> {\n const navigationSnapshot = createClientNavigationRenderSnapshot(\n window.location.href,\n latestClientParams,\n );\n const currentState = getBrowserRouterState();\n const startedNavigationId = activeNavigationId;\n const { disposition, pending } = await resolveAndClassifyNavigationCommit({\n activeNavigationId,\n currentState,\n navigationSnapshot,\n nextElements,\n renderId: ++nextNavigationRenderId,\n startedNavigationId,\n type: \"navigate\",\n });\n\n // Known limitation: if a same-URL navigation fully commits while this\n // server action is awaiting createPendingNavigationCommit(), the action\n // can still dispatch its older payload afterward. The old pre-2c code had\n // the same race, and Next.js has similar behavior. Tightening this would\n // need a stronger commit-version gate than activeNavigationId alone.\n if (disposition === \"hard-navigate\") {\n window.location.assign(window.location.href);\n return undefined;\n }\n\n if (disposition === \"dispatch\") {\n dispatchBrowserTree(\n pending.action.elements,\n navigationSnapshot,\n pending.action.renderId,\n \"navigate\",\n pending.interceptionContext,\n pending.action.layoutFlags,\n pending.previousNextUrl,\n pending.routeId,\n pending.rootLayoutTreePath,\n false,\n );\n }\n\n // Same-URL server actions still return their action value even if the UI\n // update was skipped due to a superseding navigation. That preserves the\n // existing caller contract; a future Phase 2 router state model could make\n // skipped UI updates observable to the caller without conflating them here.\n if (returnValue) {\n if (!returnValue.ok) {\n throw returnValue.data;\n }\n return returnValue.data;\n }\n\n return undefined;\n}\n\nfunction BrowserRoot({\n initialElements,\n initialNavigationSnapshot,\n}: {\n initialElements: Promise<AppElements>;\n initialNavigationSnapshot: ClientNavigationRenderSnapshot;\n}) {\n const resolvedElements = use(initialElements);\n const initialMetadata = readAppElementsMetadata(resolvedElements);\n const [treeState, dispatchTreeState] = useReducer(routerReducer, {\n elements: resolvedElements,\n interceptionContext: initialMetadata.interceptionContext,\n layoutFlags: initialMetadata.layoutFlags,\n navigationSnapshot: initialNavigationSnapshot,\n previousNextUrl: null,\n renderId: 0,\n rootLayoutTreePath: initialMetadata.rootLayoutTreePath,\n routeId: initialMetadata.routeId,\n });\n\n // Keep the latest router state in a ref so external callers (navigate(),\n // server actions, HMR) always read the current state. Safe: those readers\n // run from events/effects, never from React render itself.\n // Note: stateRef.current is written during render, not in an effect, to\n // avoid a stale-read window between commit and layout effects. This mirrors\n // the same render-phase ref update pattern used by Next.js's own router.\n const stateRef = useRef(treeState);\n stateRef.current = treeState;\n\n // Publish the stable ref object and dispatch during layout commit. This keeps\n // the module-level escape hatches aligned with React's committed tree without\n // performing module writes during render. __VINEXT_RSC_NAVIGATE__ is assigned\n // after hydrateRoot() returns; by then this layout effect has already run for\n // the hydration commit, so getBrowserRouterState() never observes a null ref.\n useLayoutEffect(() => {\n dispatchBrowserRouterAction = dispatchTreeState;\n browserRouterStateRef = stateRef;\n return () => {\n if (dispatchBrowserRouterAction === dispatchTreeState) {\n dispatchBrowserRouterAction = null;\n }\n if (browserRouterStateRef === stateRef) {\n browserRouterStateRef = null;\n }\n setMountedSlotsHeader(null);\n };\n }, [dispatchTreeState]);\n\n useLayoutEffect(() => {\n setMountedSlotsHeader(getMountedSlotIdsHeader(stateRef.current.elements));\n }, [treeState.elements]);\n\n useLayoutEffect(() => {\n if (treeState.renderId !== 0) {\n return;\n }\n\n replaceHistoryStateWithoutNotify(\n createHistoryStateWithPreviousNextUrl(window.history.state, treeState.previousNextUrl),\n \"\",\n window.location.href,\n );\n }, [treeState.previousNextUrl, treeState.renderId]);\n\n const committedTree = createElement(\n NavigationCommitSignal,\n { renderId: treeState.renderId },\n createElement(\n ElementsContext.Provider,\n { value: treeState.elements },\n createElement(Slot, { id: treeState.routeId }),\n ),\n );\n\n const ClientNavigationRenderContext = getClientNavigationRenderContext();\n if (!ClientNavigationRenderContext) {\n return committedTree;\n }\n\n return createElement(\n ClientNavigationRenderContext.Provider,\n { value: treeState.navigationSnapshot },\n committedTree,\n );\n}\n\nfunction dispatchBrowserTree(\n elements: AppElements,\n navigationSnapshot: ClientNavigationRenderSnapshot,\n renderId: number,\n actionType: \"navigate\" | \"replace\" | \"traverse\",\n interceptionContext: string | null,\n layoutFlags: LayoutFlags,\n previousNextUrl: string | null,\n routeId: string,\n rootLayoutTreePath: string | null,\n useTransitionMode: boolean,\n): void {\n const dispatch = getBrowserRouterDispatch();\n\n const applyAction = () =>\n dispatch({\n elements,\n interceptionContext,\n layoutFlags,\n navigationSnapshot,\n previousNextUrl,\n renderId,\n rootLayoutTreePath,\n routeId,\n type: actionType,\n });\n\n if (useTransitionMode) {\n startTransition(applyAction);\n } else {\n applyAction();\n }\n}\n\nasync function renderNavigationPayload(\n payload: Promise<AppElements>,\n navigationSnapshot: ClientNavigationRenderSnapshot,\n targetHref: string,\n navId: number,\n historyUpdateMode: HistoryUpdateMode | undefined,\n params: Record<string, string | string[]>,\n previousNextUrl: string | null,\n useTransition = true,\n actionType: \"navigate\" | \"replace\" | \"traverse\" = \"navigate\",\n): Promise<void> {\n const renderId = ++nextNavigationRenderId;\n const committed = new Promise<void>((resolve) => {\n pendingNavigationCommits.set(renderId, resolve);\n });\n\n let snapshotActivated = false;\n try {\n const currentState = getBrowserRouterState();\n const pending = await createPendingNavigationCommit({\n currentState,\n nextElements: payload,\n navigationSnapshot,\n previousNextUrl,\n renderId,\n type: actionType,\n });\n\n const disposition = resolvePendingNavigationCommitDisposition({\n activeNavigationId,\n currentRootLayoutTreePath: currentState.rootLayoutTreePath,\n nextRootLayoutTreePath: pending.rootLayoutTreePath,\n startedNavigationId: navId,\n });\n\n if (disposition === \"skip\") {\n const resolve = pendingNavigationCommits.get(renderId);\n pendingNavigationCommits.delete(renderId);\n resolve?.();\n return;\n }\n\n if (disposition === \"hard-navigate\") {\n pendingNavigationCommits.delete(renderId);\n window.location.assign(targetHref);\n return;\n }\n\n queuePrePaintNavigationEffect(\n renderId,\n createNavigationCommitEffect(\n targetHref,\n historyUpdateMode,\n navId,\n params,\n pending.previousNextUrl,\n ),\n );\n activateNavigationSnapshot();\n snapshotActivated = true;\n dispatchBrowserTree(\n pending.action.elements,\n navigationSnapshot,\n renderId,\n actionType,\n pending.interceptionContext,\n pending.action.layoutFlags,\n pending.previousNextUrl,\n pending.routeId,\n pending.rootLayoutTreePath,\n useTransition,\n );\n } catch (error) {\n // Clean up pending state on error. Only decrement the snapshot counter\n // if activateNavigationSnapshot() was actually called — if\n // createPendingNavigationCommit() threw, the counter was never\n // incremented so decrementing would underflow it.\n pendingNavigationPrePaintEffects.delete(renderId);\n const resolve = pendingNavigationCommits.get(renderId);\n pendingNavigationCommits.delete(renderId);\n if (snapshotActivated) {\n commitClientNavigationState(navId);\n }\n resolve?.();\n throw error;\n }\n\n return committed;\n}\n\nfunction restoreHydrationNavigationContext(\n pathname: string,\n searchParams: SearchParamInput,\n params: Record<string, string | string[]>,\n): void {\n setNavigationContext({\n pathname,\n searchParams: new URLSearchParams(searchParams),\n params,\n });\n}\n\nfunction restorePopstateScrollPosition(state: unknown): void {\n if (!(state && typeof state === \"object\" && \"__vinext_scrollY\" in state)) {\n return;\n }\n\n const y = Number(state.__vinext_scrollY);\n const x = \"__vinext_scrollX\" in state ? Number(state.__vinext_scrollX) : 0;\n\n requestAnimationFrame(() => {\n window.scrollTo(x, y);\n });\n}\n\nasync function readInitialRscStream(): Promise<ReadableStream<Uint8Array>> {\n const vinext = getVinextBrowserGlobal();\n\n if (vinext.__VINEXT_RSC__ || vinext.__VINEXT_RSC_CHUNKS__ || vinext.__VINEXT_RSC_DONE__) {\n if (vinext.__VINEXT_RSC__) {\n const embedData = vinext.__VINEXT_RSC__;\n delete vinext.__VINEXT_RSC__;\n\n const params = embedData.params ?? {};\n if (embedData.params) {\n applyClientParams(embedData.params);\n }\n if (embedData.nav) {\n restoreHydrationNavigationContext(\n embedData.nav.pathname,\n embedData.nav.searchParams,\n params,\n );\n }\n\n return chunksToReadableStream(embedData.rsc);\n }\n\n const params = vinext.__VINEXT_RSC_PARAMS__ ?? {};\n if (vinext.__VINEXT_RSC_PARAMS__) {\n applyClientParams(vinext.__VINEXT_RSC_PARAMS__);\n }\n if (vinext.__VINEXT_RSC_NAV__) {\n restoreHydrationNavigationContext(\n vinext.__VINEXT_RSC_NAV__.pathname,\n vinext.__VINEXT_RSC_NAV__.searchParams,\n params,\n );\n }\n\n return createProgressiveRscStream();\n }\n\n const rscResponse = await fetch(toRscUrl(window.location.pathname + window.location.search));\n\n let params: Record<string, string | string[]> = {};\n const paramsHeader = rscResponse.headers.get(\"X-Vinext-Params\");\n if (paramsHeader) {\n try {\n params = JSON.parse(decodeURIComponent(paramsHeader)) as Record<string, string | string[]>;\n applyClientParams(params);\n } catch {\n // Ignore malformed param headers and continue with hydration.\n }\n }\n\n restoreHydrationNavigationContext(window.location.pathname, window.location.search, params);\n\n if (!rscResponse.body) {\n throw new Error(\"[vinext] Initial RSC response had no body\");\n }\n\n return rscResponse.body;\n}\n\nfunction registerServerActionCallback(): void {\n setServerCallback(async (id, args) => {\n const temporaryReferences = createTemporaryReferenceSet();\n const body = await encodeReply(args, { temporaryReferences });\n\n // Carry the interception context + mounted slots from the current router\n // state so the server-action re-render rebuilds the intercepted tree\n // instead of replacing it with the direct page. Parity with Next.js,\n // which sends `Next-URL` on action POSTs when the current tree contains\n // an interception route.\n const currentState = getBrowserRouterState();\n const { headers } = resolveServerActionRequestState({\n actionId: id,\n basePath: __basePath,\n elements: currentState.elements,\n previousNextUrl: currentState.previousNextUrl,\n });\n\n const fetchResponse = await fetch(toRscUrl(window.location.pathname + window.location.search), {\n method: \"POST\",\n headers,\n body,\n });\n\n const actionRedirect = fetchResponse.headers.get(\"x-action-redirect\");\n if (actionRedirect) {\n // Check for external URLs that need a hard redirect.\n try {\n const redirectUrl = new URL(actionRedirect, window.location.origin);\n if (redirectUrl.origin !== window.location.origin) {\n window.location.href = actionRedirect;\n return undefined;\n }\n } catch {\n // Fall through to hard redirect below if URL parsing fails.\n }\n\n // Use hard redirect for all action redirects because vinext's server\n // currently returns an empty body for redirect responses. RSC navigation\n // requires a valid RSC payload. This is a known parity gap with Next.js,\n // which pre-renders the redirect target's RSC payload.\n const redirectType = fetchResponse.headers.get(\"x-action-redirect-type\") ?? \"replace\";\n if (redirectType === \"push\") {\n window.location.assign(actionRedirect);\n } else {\n window.location.replace(actionRedirect);\n }\n return undefined;\n }\n\n clearClientNavigationCaches();\n\n const result = await createFromFetch<ServerActionResult | AppWireElements>(\n Promise.resolve(fetchResponse),\n { temporaryReferences },\n );\n\n // Server actions stay on the same URL and use commitSameUrlNavigatePayload()\n // for merge-based dispatch. This path does not call\n // activateNavigationSnapshot() because there is no URL change to commit, so\n // hooks continue reading the live external-store values directly. If server\n // actions ever trigger URL changes via RSC payload (instead of hard\n // redirects), this would need renderNavigationPayload().\n if (isServerActionResult(result)) {\n return commitSameUrlNavigatePayload(\n Promise.resolve(normalizeAppElements(result.root)),\n result.returnValue,\n );\n }\n\n return commitSameUrlNavigatePayload(Promise.resolve(normalizeAppElements(result)));\n });\n}\n\nasync function main(): Promise<void> {\n registerServerActionCallback();\n\n const rscStream = await readInitialRscStream();\n const root = normalizeAppElementsPromise(createFromReadableStream<AppWireElements>(rscStream));\n const initialNavigationSnapshot = createClientNavigationRenderSnapshot(\n window.location.href,\n latestClientParams,\n );\n replaceHistoryStateWithoutNotify(\n createHistoryStateWithPreviousNextUrl(window.history.state, null),\n \"\",\n window.location.href,\n );\n\n window.__VINEXT_RSC_ROOT__ = hydrateRoot(\n document,\n createElement(BrowserRoot, {\n initialElements: root,\n initialNavigationSnapshot,\n }),\n import.meta.env.DEV ? { onCaughtError: devOnCaughtError } : undefined,\n );\n window.__VINEXT_HYDRATED_AT = performance.now();\n\n window.__VINEXT_RSC_NAVIGATE__ = async function navigateRsc(\n href: string,\n redirectDepth = 0,\n navigationKind: NavigationKind = \"navigate\",\n historyUpdateMode?: HistoryUpdateMode,\n previousNextUrlOverride?: string | null,\n ): Promise<void> {\n if (redirectDepth > 10) {\n console.error(\n \"[vinext] Too many RSC redirects — aborting navigation to prevent infinite loop.\",\n );\n window.location.href = href;\n return;\n }\n\n let _snapshotPending = false;\n // Hoist navId above try so the catch block can guard against hard-navigating\n // to a stale URL when this navigation has already been superseded.\n const navId = ++activeNavigationId;\n try {\n const url = new URL(href, window.location.origin);\n const rscUrl = toRscUrl(url.pathname + url.search);\n const requestState = getRequestState(navigationKind, previousNextUrlOverride);\n const requestInterceptionContext = requestState.interceptionContext;\n const requestPreviousNextUrl = requestState.previousNextUrl;\n\n // Compare against previous pending navigation first, then committed state.\n // This avoids isSameRoute misclassification during rapid back-to-back clicks.\n const navState = getClientNavigationState();\n const currentPath =\n navState?.pendingPathname ??\n navState?.cachedPathname ??\n stripBasePath(window.location.pathname, __basePath);\n\n const targetPath = stripBasePath(url.pathname, __basePath);\n const isSameRoute = targetPath === currentPath;\n\n // Set this navigation as the pending pathname, overwriting any previous.\n // Pass navId so only this navigation (or a newer one) can clear it later.\n setPendingPathname(url.pathname, navId);\n\n const elementsAtNavStart = getBrowserRouterState().elements;\n const mountedSlotsHeader = getMountedSlotIdsHeader(elementsAtNavStart);\n const cachedRoute = getVisitedResponse(\n rscUrl,\n requestInterceptionContext,\n mountedSlotsHeader,\n navigationKind,\n );\n if (cachedRoute) {\n // Check stale-navigation before and after createFromFetch. The pre-check\n // avoids wasted parse work; the post-check catches supersessions that\n // occur during the await. createFromFetch on a buffered response is fast\n // but still async, so the window exists. The non-cached path (below) places\n // its heavyweight async steps (fetch, snapshotRscResponse, createFromFetch)\n // between navId checks consistently; the cached path omits the check between\n // createClientNavigationRenderSnapshot (synchronous) and createFromFetch\n // because there is no await in that gap.\n if (navId !== activeNavigationId) return;\n const cachedParams = cachedRoute.params;\n // createClientNavigationRenderSnapshot is synchronous (URL parsing + param\n // wrapping only) — no stale-navigation recheck needed between here and the\n // next await.\n const cachedNavigationSnapshot = createClientNavigationRenderSnapshot(href, cachedParams);\n const cachedPayload = normalizeAppElementsPromise(\n createFromFetch<AppWireElements>(\n Promise.resolve(restoreRscResponse(cachedRoute.response)),\n ),\n );\n if (navId !== activeNavigationId) return;\n _snapshotPending = true; // Set before renderNavigationPayload\n try {\n await renderNavigationPayload(\n cachedPayload,\n cachedNavigationSnapshot,\n href,\n navId,\n historyUpdateMode,\n cachedParams,\n requestPreviousNextUrl,\n isSameRoute,\n toActionType(navigationKind),\n );\n } finally {\n // Always clear _snapshotPending so the outer catch does not\n // double-decrement if renderNavigationPayload throws.\n _snapshotPending = false;\n }\n return;\n }\n\n // Continue using the slot state captured at navigation start for fetches\n // and prefetch compatibility decisions.\n\n let navResponse: Response | undefined;\n let navResponseUrl: string | null = null;\n if (navigationKind !== \"refresh\") {\n const prefetchedResponse = consumePrefetchResponse(\n rscUrl,\n requestInterceptionContext,\n mountedSlotsHeader,\n );\n if (prefetchedResponse) {\n navResponse = restoreRscResponse(prefetchedResponse, false);\n navResponseUrl = prefetchedResponse.url;\n }\n }\n\n if (!navResponse) {\n const requestHeaders = createRscRequestHeaders(requestInterceptionContext);\n if (mountedSlotsHeader) {\n requestHeaders.set(\"X-Vinext-Mounted-Slots\", mountedSlotsHeader);\n }\n navResponse = await fetch(rscUrl, {\n headers: requestHeaders,\n credentials: \"include\",\n });\n }\n\n if (navId !== activeNavigationId) return;\n\n const finalUrl = new URL(navResponseUrl ?? navResponse.url, window.location.origin);\n const requestedUrl = new URL(rscUrl, window.location.origin);\n\n if (finalUrl.pathname !== requestedUrl.pathname) {\n const destinationPath = finalUrl.pathname.replace(/\\.rsc$/, \"\") + finalUrl.search;\n replaceHistoryStateWithoutNotify(\n createHistoryStateWithPreviousNextUrl(null, requestPreviousNextUrl),\n \"\",\n destinationPath,\n );\n\n const navigate = window.__VINEXT_RSC_NAVIGATE__;\n if (!navigate) {\n window.location.href = destinationPath;\n return;\n }\n\n // The URL has already been updated via replaceHistoryStateWithoutNotify above,\n // so the recursive navigation should NOT push/replace again. Pass undefined\n // for historyUpdateMode to make the commit effect a no-op for history updates.\n return navigate(\n destinationPath,\n redirectDepth + 1,\n navigationKind,\n undefined,\n requestPreviousNextUrl,\n );\n }\n\n let navParams: Record<string, string | string[]> = {};\n const paramsHeader = navResponse.headers.get(\"X-Vinext-Params\");\n if (paramsHeader) {\n try {\n navParams = JSON.parse(decodeURIComponent(paramsHeader)) as Record<\n string,\n string | string[]\n >;\n } catch {\n // navParams stays as {}\n }\n }\n // Build snapshot from local params, not latestClientParams\n const navigationSnapshot = createClientNavigationRenderSnapshot(href, navParams);\n\n const responseSnapshot = await snapshotRscResponse(navResponse);\n\n if (navId !== activeNavigationId) return;\n\n const rscPayload = normalizeAppElementsPromise(\n createFromFetch<AppWireElements>(Promise.resolve(restoreRscResponse(responseSnapshot))),\n );\n\n if (navId !== activeNavigationId) return;\n\n _snapshotPending = true; // Set before renderNavigationPayload\n try {\n await renderNavigationPayload(\n rscPayload,\n navigationSnapshot,\n href,\n navId,\n historyUpdateMode,\n navParams,\n requestPreviousNextUrl,\n isSameRoute,\n toActionType(navigationKind),\n );\n } finally {\n // Always clear _snapshotPending after renderNavigationPayload returns or\n // throws. renderNavigationPayload's inner catch already calls\n // commitClientNavigationState() on synchronous errors and re-throws, so\n // the outer catch must not call it again. Clearing here prevents the outer\n // catch from double-decrementing navigationSnapshotActiveCount.\n _snapshotPending = false;\n }\n // Don't cache the response if this navigation was superseded during\n // renderNavigationPayload's await — the elements were never dispatched.\n if (navId !== activeNavigationId) return;\n // Store the visited response only after renderNavigationPayload succeeds.\n // If we stored it before and renderNavigationPayload threw, a future\n // back/forward navigation could replay a snapshot from a navigation that\n // never actually rendered successfully.\n const resolvedElements = await rscPayload;\n const metadata = readAppElementsMetadata(resolvedElements);\n storeVisitedResponseSnapshot(\n rscUrl,\n resolveVisitedResponseInterceptionContext(\n requestInterceptionContext,\n metadata.interceptionContext,\n ),\n responseSnapshot,\n navParams,\n );\n return;\n } catch (error) {\n // Only decrement counter if snapshot was activated but not yet committed.\n // renderNavigationPayload clears _snapshotPending (via its inner try-finally)\n // before re-throwing, so this guard correctly skips the double-decrement case.\n if (_snapshotPending) {\n _snapshotPending = false;\n commitClientNavigationState(navId);\n }\n // Clear pending pathname on error so subsequent navigations compare correctly.\n // Only clear if this is still the active navigation — a newer navigation\n // has already overwritten pendingPathname with its own target.\n if (navId === activeNavigationId) {\n clearPendingPathname(navId);\n }\n // Don't hard-navigate to a stale URL if this navigation was superseded by\n // a newer one — the newer navigation is already in flight and would be clobbered.\n if (navId !== activeNavigationId) return;\n console.error(\"[vinext] RSC navigation error:\", error);\n window.location.href = href;\n }\n };\n\n if (\"scrollRestoration\" in history) {\n history.scrollRestoration = \"manual\";\n }\n\n // Note: This popstate handler runs for App Router (RSC navigation available).\n // It coordinates scroll restoration with the pending RSC navigation.\n // Pages Router scroll restoration is handled in shims/navigation.ts:1289 with\n // microtask-based deferral for compatibility with non-RSC navigation.\n // See: https://github.com/vercel/next.js/discussions/41934#discussioncomment-4602607\n window.addEventListener(\"popstate\", (event) => {\n notifyAppRouterTransitionStart(window.location.href, \"traverse\");\n const pendingNavigation =\n window.__VINEXT_RSC_NAVIGATE__?.(window.location.href, 0, \"traverse\") ?? Promise.resolve();\n window.__VINEXT_RSC_PENDING__ = pendingNavigation;\n void pendingNavigation.finally(() => {\n restorePopstateScrollPosition(event.state);\n if (window.__VINEXT_RSC_PENDING__ === pendingNavigation) {\n window.__VINEXT_RSC_PENDING__ = null;\n }\n });\n });\n\n if (import.meta.hot) {\n import.meta.hot.on(\"rsc:update\", async () => {\n try {\n clearClientNavigationCaches();\n const navigationSnapshot = createClientNavigationRenderSnapshot(\n window.location.href,\n latestClientParams,\n );\n // Interception context on HMR re-renders is intentionally deferred:\n // preserving intercepted modal state across HMR reloads is out of scope\n // for the previousNextUrl mechanism.\n const pending = await createPendingNavigationCommit({\n currentState: getBrowserRouterState(),\n nextElements: normalizeAppElementsPromise(\n createFromFetch<AppWireElements>(\n fetch(toRscUrl(window.location.pathname + window.location.search)),\n ),\n ),\n navigationSnapshot,\n renderId: ++nextNavigationRenderId,\n type: \"replace\",\n });\n dispatchBrowserTree(\n pending.action.elements,\n navigationSnapshot,\n pending.action.renderId,\n \"replace\",\n pending.interceptionContext,\n pending.action.layoutFlags,\n pending.previousNextUrl,\n pending.routeId,\n pending.rootLayoutTreePath,\n false,\n );\n } catch (error) {\n console.error(\"[vinext] RSC HMR error:\", error);\n }\n });\n }\n}\n\nif (typeof document !== \"undefined\") {\n void main();\n}\n"],"mappings":";;;;;;;;;;;;;AA8FA,SAAS,aAAa,MAA+C;AACnE,QAAO,SAAS,aAAa,aAAa;;AAU5C,MAAM,kCAAkC;AACxC,MAAM,6BAA6B,IAAI;AACvC,MAAM,0BAA0B,KAAK;AAarC,IAAI,yBAAyB;AAC7B,IAAI,qBAAqB;AACzB,MAAM,2CAA2B,IAAI,KAAyB;AAC9D,MAAM,mDAAmC,IAAI,KAAyB;AACtE,IAAI,8BAAgE;AACpE,IAAI,wBAA4D;AAChE,IAAI,qBAAwD,EAAE;AAC9D,MAAM,uCAAuB,IAAI,KAAwC;AAEzE,SAAS,qBAAqB,OAA6C;AACzE,QAAO,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,UAAU;;AAG3D,SAAS,2BAAsD;AAC7D,KAAI,CAAC,4BACH,OAAM,IAAI,MAAM,sDAAsD;AAExE,QAAO;;AAGT,SAA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AO;AACd,WAAQ,MAAM,2BAA2B,MAAM;;GAEjD;;AAIN,IAAI,OAAO,aAAa,YACjB,OAAM"}
|
|
1
|
+
{"version":3,"file":"app-browser-entry.js","names":[],"sources":["../../src/server/app-browser-entry.ts"],"sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport {\n createElement,\n startTransition,\n use,\n useLayoutEffect,\n useRef,\n useState,\n type Dispatch,\n type ReactNode,\n} from \"react\";\nimport {\n createFromFetch,\n createFromReadableStream,\n createTemporaryReferenceSet,\n encodeReply,\n setServerCallback,\n} from \"@vitejs/plugin-rsc/browser\";\nimport { hydrateRoot } from \"react-dom/client\";\nimport \"../client/instrumentation-client.js\";\nimport { notifyAppRouterTransitionStart } from \"../client/instrumentation-client-state.js\";\nimport {\n __basePath,\n activateNavigationSnapshot,\n clearPendingPathname,\n commitClientNavigationState,\n consumePrefetchResponse,\n createClientNavigationRenderSnapshot,\n getCurrentNextUrl,\n getCurrentInterceptionContext,\n getClientNavigationRenderContext,\n getClientNavigationState,\n getPrefetchCache,\n getPrefetchedUrls,\n pushHistoryStateWithoutNotify,\n replaceClientParamsWithoutNotify,\n replaceHistoryStateWithoutNotify,\n restoreRscResponse,\n setClientParams,\n setPendingPathname,\n snapshotRscResponse,\n setMountedSlotsHeader,\n setNavigationContext,\n toRscUrl,\n type CachedRscResponse,\n type ClientNavigationRenderSnapshot,\n} from \"../shims/navigation.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport {\n chunksToReadableStream,\n createProgressiveRscStream,\n getVinextBrowserGlobal,\n} from \"./app-browser-stream.js\";\nimport {\n createAppPayloadCacheKey,\n getMountedSlotIdsHeader,\n normalizeAppElements,\n readAppElementsMetadata,\n resolveVisitedResponseInterceptionContext,\n type AppElements,\n type AppWireElements,\n type LayoutFlags,\n} from \"./app-elements.js\";\nimport {\n createHistoryStateWithPreviousNextUrl,\n createPendingNavigationCommit,\n readHistoryStatePreviousNextUrl,\n resolveAndClassifyNavigationCommit,\n resolveInterceptionContextFromPreviousNextUrl,\n resolvePendingNavigationCommitDisposition,\n resolveServerActionRequestState,\n routerReducer,\n type AppRouterAction,\n type AppRouterState,\n} from \"./app-browser-state.js\";\nimport { ElementsContext, Slot } from \"../shims/slot.js\";\nimport { devOnCaughtError } from \"./app-browser-error.js\";\n\ntype SearchParamInput = ConstructorParameters<typeof URLSearchParams>[0];\n\ntype ServerActionResult = {\n root: AppWireElements;\n returnValue?: {\n ok: boolean;\n data: unknown;\n };\n};\n\ntype NavigationKind = \"navigate\" | \"traverse\" | \"refresh\";\n\n// Maps NavigationKind to the AppRouterAction type used by the reducer.\n// \"refresh\" is intentionally treated as \"navigate\" (merge, preserve absent slots).\n// Both call sites must stay in sync — update here if NavigationKind gains new values.\nfunction toActionType(kind: NavigationKind): \"navigate\" | \"traverse\" {\n return kind === \"traverse\" ? \"traverse\" : \"navigate\";\n}\n\ntype HistoryUpdateMode = \"push\" | \"replace\";\ntype VisitedResponseCacheEntry = {\n params: Record<string, string | string[]>;\n expiresAt: number;\n response: CachedRscResponse;\n};\n\nconst MAX_VISITED_RESPONSE_CACHE_SIZE = 50;\nconst VISITED_RESPONSE_CACHE_TTL = 5 * 60_000;\nconst MAX_TRAVERSAL_CACHE_TTL = 30 * 60_000;\n\n// These are plain module-level variables, unlike ClientNavigationState in\n// navigation.ts which uses Symbol.for to survive multiple Vite module instances.\n// The browser entry is loaded exactly once (via the RSC plugin's generated\n// bootstrap), so module-level state is safe here. If that assumption ever\n// changes, these should be migrated to a Symbol.for-backed global.\n//\n// The most severe consequence of multiple instances would be Map fragmentation:\n// pendingNavigationCommits and pendingNavigationPrePaintEffects would split\n// across instances, so drainPrePaintEffects in one instance could never drain\n// effects queued by the other, permanently leaking navigationSnapshotActiveCount\n// and causing hooks to prefer stale snapshot values indefinitely.\nlet nextNavigationRenderId = 0;\nlet activeNavigationId = 0;\nconst pendingNavigationCommits = new Map<number, () => void>();\nconst pendingNavigationPrePaintEffects = new Map<number, () => void>();\ntype PendingBrowserRouterState = {\n promise: Promise<AppRouterState>;\n resolve: (state: AppRouterState) => void;\n settled: boolean;\n};\n\nfunction isRouterStatePromise(\n value: AppRouterState | Promise<AppRouterState>,\n): value is Promise<AppRouterState> {\n return value instanceof Promise;\n}\n\nlet setBrowserRouterState: Dispatch<AppRouterState | Promise<AppRouterState>> | null = null;\nlet browserRouterStateRef: { current: AppRouterState } | null = null;\nlet activePendingBrowserRouterState: PendingBrowserRouterState | null = null;\nlet latestClientParams: Record<string, string | string[]> = {};\nconst visitedResponseCache = new Map<string, VisitedResponseCacheEntry>();\n\nfunction isServerActionResult(value: unknown): value is ServerActionResult {\n return !!value && typeof value === \"object\" && \"root\" in value;\n}\n\nfunction getBrowserRouterStateSetter(): Dispatch<AppRouterState | Promise<AppRouterState>> {\n if (!setBrowserRouterState) {\n throw new Error(\"[vinext] Browser router state setter is not initialized\");\n }\n return setBrowserRouterState;\n}\n\nfunction getBrowserRouterState(): AppRouterState {\n if (!browserRouterStateRef) {\n throw new Error(\"[vinext] Browser router state is not initialized\");\n }\n return browserRouterStateRef.current;\n}\n\nfunction beginPendingBrowserRouterState(): PendingBrowserRouterState {\n const setter = getBrowserRouterStateSetter();\n\n if (activePendingBrowserRouterState && !activePendingBrowserRouterState.settled) {\n activePendingBrowserRouterState.settled = true;\n activePendingBrowserRouterState.resolve(getBrowserRouterState());\n }\n\n let resolve!: (state: AppRouterState) => void;\n const promise = new Promise<AppRouterState>((resolvePromise) => {\n resolve = resolvePromise;\n });\n\n const pending: PendingBrowserRouterState = {\n promise,\n resolve,\n settled: false,\n };\n\n activePendingBrowserRouterState = pending;\n setter(promise);\n\n return pending;\n}\n\nfunction settlePendingBrowserRouterState(\n pending: PendingBrowserRouterState | null | undefined,\n): void {\n if (!pending || pending.settled) return;\n\n pending.settled = true;\n pending.resolve(getBrowserRouterState());\n\n if (activePendingBrowserRouterState === pending) {\n activePendingBrowserRouterState = null;\n }\n}\n\nfunction resolvePendingBrowserRouterState(\n pending: PendingBrowserRouterState | null | undefined,\n action: AppRouterAction,\n): void {\n if (!pending || pending.settled) return;\n\n pending.settled = true;\n pending.resolve(routerReducer(getBrowserRouterState(), action));\n\n if (activePendingBrowserRouterState === pending) {\n activePendingBrowserRouterState = null;\n }\n}\n\nfunction applyClientParams(params: Record<string, string | string[]>): void {\n latestClientParams = params;\n setClientParams(params);\n}\n\nfunction stageClientParams(params: Record<string, string | string[]>): void {\n // NB: latestClientParams diverges from ClientNavigationState.clientParams\n // between staging and commit. Server action snapshots (same-URL\n // commitSameUrlNavigatePayload() calls inside registerServerActionCallback)\n // read latestClientParams, so a\n // server action fired during this window would get the pending (not yet\n // committed) params. This is acceptable because the commit effect fires\n // before hooks observe the new URL state, keeping the window vanishingly small.\n latestClientParams = params;\n replaceClientParamsWithoutNotify(params);\n}\n\nfunction clearVisitedResponseCache(): void {\n visitedResponseCache.clear();\n}\n\nfunction clearPrefetchState(): void {\n getPrefetchCache().clear();\n getPrefetchedUrls().clear();\n}\n\nfunction clearClientNavigationCaches(): void {\n clearVisitedResponseCache();\n clearPrefetchState();\n}\n\nfunction queuePrePaintNavigationEffect(renderId: number, effect: (() => void) | null): void {\n if (!effect) {\n return;\n }\n pendingNavigationPrePaintEffects.set(renderId, effect);\n}\n\n/**\n * Run all queued pre-paint effects for renderIds up to and including the\n * given renderId. When React supersedes a startTransition update (rapid\n * clicks on same-route links), the superseded NavigationCommitSignal never\n * mounts, so its pre-paint effect never fires. By draining all effects\n * <= the committed renderId here, the winning transition cleans up after\n * any superseded ones, keeping the counter balanced.\n *\n * Invariant: each superseded navigation gets a commitClientNavigationState()\n * to balance the activateNavigationSnapshot() from its renderNavigationPayload call.\n */\nfunction drainPrePaintEffects(upToRenderId: number): void {\n for (const [id, effect] of pendingNavigationPrePaintEffects) {\n if (id <= upToRenderId) {\n pendingNavigationPrePaintEffects.delete(id);\n if (id === upToRenderId) {\n // Winning navigation: run its actual pre-paint effect\n effect();\n } else {\n // Superseded navigation: balance its activateNavigationSnapshot().\n // Pass undefined navId intentionally so this cleanup cannot clear\n // pendingPathname owned by the current active navigation.\n commitClientNavigationState(undefined);\n }\n }\n }\n}\n\nfunction createNavigationCommitEffect(\n href: string,\n historyUpdateMode: HistoryUpdateMode | undefined,\n navId: number,\n params: Record<string, string | string[]>,\n previousNextUrl: string | null,\n): () => void {\n return () => {\n // Only update URL if this is still the active navigation.\n // A newer navigation would have incremented activeNavigationId.\n if (navId !== activeNavigationId) {\n // This transition was superseded before commit; balance the active\n // snapshot counter without clearing pendingPathname ownership.\n commitClientNavigationState(undefined);\n return;\n }\n\n const targetHref = new URL(href, window.location.origin).href;\n stageClientParams(params);\n const preserveExistingState = historyUpdateMode === \"replace\";\n const historyState = createHistoryStateWithPreviousNextUrl(\n preserveExistingState ? window.history.state : null,\n previousNextUrl,\n );\n\n if (historyUpdateMode === \"replace\" && window.location.href !== targetHref) {\n replaceHistoryStateWithoutNotify(historyState, \"\", href);\n } else if (historyUpdateMode === \"push\" && window.location.href !== targetHref) {\n pushHistoryStateWithoutNotify(historyState, \"\", href);\n }\n\n commitClientNavigationState(navId);\n };\n}\n\nfunction evictVisitedResponseCacheIfNeeded(): void {\n while (visitedResponseCache.size >= MAX_VISITED_RESPONSE_CACHE_SIZE) {\n const oldest = visitedResponseCache.keys().next().value;\n if (oldest === undefined) {\n return;\n }\n visitedResponseCache.delete(oldest);\n }\n}\n\nfunction getVisitedResponse(\n rscUrl: string,\n interceptionContext: string | null,\n mountedSlotsHeader: string | null,\n navigationKind: NavigationKind,\n): VisitedResponseCacheEntry | null {\n const cacheKey = createAppPayloadCacheKey(rscUrl, interceptionContext);\n const cached = visitedResponseCache.get(cacheKey);\n if (!cached) {\n return null;\n }\n\n if ((cached.response.mountedSlotsHeader ?? null) !== mountedSlotsHeader) {\n visitedResponseCache.delete(cacheKey);\n return null;\n }\n\n if (navigationKind === \"refresh\") {\n return null;\n }\n\n if (navigationKind === \"traverse\") {\n const createdAt = cached.expiresAt - VISITED_RESPONSE_CACHE_TTL;\n if (Date.now() - createdAt >= MAX_TRAVERSAL_CACHE_TTL) {\n visitedResponseCache.delete(cacheKey);\n return null;\n }\n // LRU: promote to most-recently-used (delete + re-insert moves to end of Map)\n visitedResponseCache.delete(cacheKey);\n visitedResponseCache.set(cacheKey, cached);\n return cached;\n }\n\n if (cached.expiresAt > Date.now()) {\n // LRU: promote to most-recently-used\n visitedResponseCache.delete(cacheKey);\n visitedResponseCache.set(cacheKey, cached);\n return cached;\n }\n\n visitedResponseCache.delete(cacheKey);\n return null;\n}\n\nfunction storeVisitedResponseSnapshot(\n rscUrl: string,\n interceptionContext: string | null,\n snapshot: CachedRscResponse,\n params: Record<string, string | string[]>,\n): void {\n const cacheKey = createAppPayloadCacheKey(rscUrl, interceptionContext);\n visitedResponseCache.delete(cacheKey);\n evictVisitedResponseCacheIfNeeded();\n const now = Date.now();\n visitedResponseCache.set(cacheKey, {\n params,\n expiresAt: now + VISITED_RESPONSE_CACHE_TTL,\n response: snapshot,\n });\n}\n\ntype NavigationRequestState = {\n interceptionContext: string | null;\n previousNextUrl: string | null;\n};\n\nfunction getRequestState(\n navigationKind: NavigationKind,\n previousNextUrlOverride?: string | null,\n): NavigationRequestState {\n if (previousNextUrlOverride !== undefined) {\n return {\n interceptionContext: resolveInterceptionContextFromPreviousNextUrl(\n previousNextUrlOverride,\n __basePath,\n ),\n previousNextUrl: previousNextUrlOverride,\n };\n }\n\n switch (navigationKind) {\n case \"navigate\":\n return {\n interceptionContext: getCurrentInterceptionContext(),\n previousNextUrl: getCurrentNextUrl(),\n };\n case \"traverse\": {\n const previousNextUrl = readHistoryStatePreviousNextUrl(window.history.state);\n return {\n interceptionContext: resolveInterceptionContextFromPreviousNextUrl(\n previousNextUrl,\n __basePath,\n ),\n previousNextUrl,\n };\n }\n case \"refresh\": {\n const currentPreviousNextUrl = getBrowserRouterState().previousNextUrl;\n return {\n interceptionContext: resolveInterceptionContextFromPreviousNextUrl(\n currentPreviousNextUrl,\n __basePath,\n ),\n previousNextUrl: currentPreviousNextUrl,\n };\n }\n default: {\n const _exhaustive: never = navigationKind;\n throw new Error(\"[vinext] Unknown navigation kind: \" + String(_exhaustive));\n }\n }\n}\n\nfunction createRscRequestHeaders(interceptionContext: string | null): Headers {\n const headers = new Headers({ Accept: \"text/x-component\" });\n if (interceptionContext !== null) {\n headers.set(\"X-Vinext-Interception-Context\", interceptionContext);\n }\n return headers;\n}\n\n/**\n * Resolve all pending navigation commits with renderId <= the committed renderId.\n * Note: Map iteration handles concurrent deletion safely — entries are visited in\n * insertion order and deletion doesn't affect the iterator's view of remaining entries.\n * This pattern is also used in drainPrePaintEffects with the same semantics.\n */\nfunction resolveCommittedNavigations(renderId: number): void {\n for (const [pendingId, resolve] of pendingNavigationCommits) {\n if (pendingId <= renderId) {\n pendingNavigationCommits.delete(pendingId);\n resolve();\n }\n }\n}\n\nfunction NavigationCommitSignal({\n renderId,\n children,\n}: {\n renderId: number;\n children?: ReactNode;\n}) {\n useLayoutEffect(() => {\n drainPrePaintEffects(renderId);\n\n const frame = requestAnimationFrame(() => {\n resolveCommittedNavigations(renderId);\n });\n\n return () => {\n cancelAnimationFrame(frame);\n // Resolve pending commits to prevent callers from hanging if React\n // unmounts this component without committing (e.g., error boundary).\n resolveCommittedNavigations(renderId);\n };\n }, [renderId]);\n\n return children;\n}\n\nfunction normalizeAppElementsPromise(payload: Promise<AppWireElements>): Promise<AppElements> {\n // Wrap in Promise.resolve() because createFromReadableStream() returns a\n // React Flight thenable whose .then() returns undefined (not a new Promise).\n // Without the wrap, chaining .then() produces undefined → use() crashes.\n return Promise.resolve(payload).then((elements) => normalizeAppElements(elements));\n}\n\nasync function commitSameUrlNavigatePayload(\n nextElements: Promise<AppElements>,\n returnValue?: ServerActionResult[\"returnValue\"],\n): Promise<unknown> {\n const navigationSnapshot = createClientNavigationRenderSnapshot(\n window.location.href,\n latestClientParams,\n );\n const currentState = getBrowserRouterState();\n const startedNavigationId = activeNavigationId;\n const { disposition, pending } = await resolveAndClassifyNavigationCommit({\n activeNavigationId,\n currentState,\n navigationSnapshot,\n nextElements,\n renderId: ++nextNavigationRenderId,\n startedNavigationId,\n type: \"navigate\",\n });\n\n // Known limitation: if a same-URL navigation fully commits while this\n // server action is awaiting createPendingNavigationCommit(), the action\n // can still dispatch its older payload afterward. The old pre-2c code had\n // the same race, and Next.js has similar behavior. Tightening this would\n // need a stronger commit-version gate than activeNavigationId alone.\n if (disposition === \"hard-navigate\") {\n window.location.assign(window.location.href);\n return undefined;\n }\n\n if (disposition === \"dispatch\") {\n dispatchBrowserTree(\n pending.action.elements,\n navigationSnapshot,\n pending.action.renderId,\n \"navigate\",\n pending.interceptionContext,\n pending.action.layoutFlags,\n pending.previousNextUrl,\n pending.routeId,\n pending.rootLayoutTreePath,\n null,\n false,\n );\n }\n\n // Same-URL server actions still return their action value even if the UI\n // update was skipped due to a superseding navigation. That preserves the\n // existing caller contract; a future Phase 2 router state model could make\n // skipped UI updates observable to the caller without conflating them here.\n if (returnValue) {\n if (!returnValue.ok) {\n throw returnValue.data;\n }\n return returnValue.data;\n }\n\n return undefined;\n}\n\nfunction BrowserRoot({\n initialElements,\n initialNavigationSnapshot,\n}: {\n initialElements: Promise<AppElements>;\n initialNavigationSnapshot: ClientNavigationRenderSnapshot;\n}) {\n const resolvedElements = use(initialElements);\n const initialMetadata = readAppElementsMetadata(resolvedElements);\n const [treeStateValue, setTreeStateValue] = useState<AppRouterState | Promise<AppRouterState>>({\n elements: resolvedElements,\n interceptionContext: initialMetadata.interceptionContext,\n layoutFlags: initialMetadata.layoutFlags,\n navigationSnapshot: initialNavigationSnapshot,\n previousNextUrl: null,\n renderId: 0,\n rootLayoutTreePath: initialMetadata.rootLayoutTreePath,\n routeId: initialMetadata.routeId,\n });\n const treeState = isRouterStatePromise(treeStateValue) ? use(treeStateValue) : treeStateValue;\n\n // Keep the latest router state in a ref so external callers (navigate(),\n // server actions, HMR) always read the current state. Safe: those readers\n // run from events/effects, never from React render itself.\n // Note: stateRef.current is written during render, not in an effect, to\n // avoid a stale-read window between commit and layout effects. This mirrors\n // the same render-phase ref update pattern used by Next.js's own router.\n const stateRef = useRef(treeState);\n stateRef.current = treeState;\n\n // Publish the stable ref object and dispatch during layout commit. This keeps\n // the module-level escape hatches aligned with React's committed tree without\n // performing module writes during render. __VINEXT_RSC_NAVIGATE__ is assigned\n // after hydrateRoot() returns; by then this layout effect has already run for\n // the hydration commit, so getBrowserRouterState() never observes a null ref.\n useLayoutEffect(() => {\n setBrowserRouterState = setTreeStateValue;\n browserRouterStateRef = stateRef;\n return () => {\n if (setBrowserRouterState === setTreeStateValue) {\n setBrowserRouterState = null;\n }\n if (browserRouterStateRef === stateRef) {\n browserRouterStateRef = null;\n }\n setMountedSlotsHeader(null);\n };\n }, [setTreeStateValue]);\n\n useLayoutEffect(() => {\n setMountedSlotsHeader(getMountedSlotIdsHeader(stateRef.current.elements));\n }, [treeState.elements]);\n\n useLayoutEffect(() => {\n if (treeState.renderId !== 0) {\n return;\n }\n\n replaceHistoryStateWithoutNotify(\n createHistoryStateWithPreviousNextUrl(window.history.state, treeState.previousNextUrl),\n \"\",\n window.location.href,\n );\n }, [treeState.previousNextUrl, treeState.renderId]);\n\n const committedTree = createElement(\n NavigationCommitSignal,\n { renderId: treeState.renderId },\n createElement(\n ElementsContext.Provider,\n { value: treeState.elements },\n createElement(Slot, { id: treeState.routeId }),\n ),\n );\n\n const ClientNavigationRenderContext = getClientNavigationRenderContext();\n if (!ClientNavigationRenderContext) {\n return committedTree;\n }\n\n return createElement(\n ClientNavigationRenderContext.Provider,\n { value: treeState.navigationSnapshot },\n committedTree,\n );\n}\n\nfunction dispatchBrowserTree(\n elements: AppElements,\n navigationSnapshot: ClientNavigationRenderSnapshot,\n renderId: number,\n actionType: \"navigate\" | \"replace\" | \"traverse\",\n interceptionContext: string | null,\n layoutFlags: LayoutFlags,\n previousNextUrl: string | null,\n routeId: string,\n rootLayoutTreePath: string | null,\n pendingRouterState: PendingBrowserRouterState | null,\n useTransitionMode: boolean,\n): void {\n const setter = getBrowserRouterStateSetter();\n const action: AppRouterAction = {\n elements,\n interceptionContext,\n layoutFlags,\n navigationSnapshot,\n previousNextUrl,\n renderId,\n rootLayoutTreePath,\n routeId,\n type: actionType,\n };\n\n const applyAction = () => {\n if (pendingRouterState) {\n // The programmatic navigation is already running inside React.startTransition\n // (from router.push/replace/refresh), so resolving the deferred promise is\n // sufficient — no additional startTransition wrapper is needed below.\n resolvePendingBrowserRouterState(pendingRouterState, action);\n return;\n }\n\n setter(routerReducer(getBrowserRouterState(), action));\n };\n\n if (useTransitionMode) {\n startTransition(applyAction);\n } else {\n applyAction();\n }\n}\n\nasync function renderNavigationPayload(\n payload: Promise<AppElements>,\n navigationSnapshot: ClientNavigationRenderSnapshot,\n targetHref: string,\n navId: number,\n historyUpdateMode: HistoryUpdateMode | undefined,\n params: Record<string, string | string[]>,\n previousNextUrl: string | null,\n pendingRouterState: PendingBrowserRouterState | null,\n useTransition = true,\n actionType: \"navigate\" | \"replace\" | \"traverse\" = \"navigate\",\n): Promise<void> {\n const renderId = ++nextNavigationRenderId;\n const committed = new Promise<void>((resolve) => {\n pendingNavigationCommits.set(renderId, resolve);\n });\n\n let snapshotActivated = false;\n try {\n const currentState = getBrowserRouterState();\n const pending = await createPendingNavigationCommit({\n currentState,\n nextElements: payload,\n navigationSnapshot,\n previousNextUrl,\n renderId,\n type: actionType,\n });\n\n const disposition = resolvePendingNavigationCommitDisposition({\n activeNavigationId,\n currentRootLayoutTreePath: currentState.rootLayoutTreePath,\n nextRootLayoutTreePath: pending.rootLayoutTreePath,\n startedNavigationId: navId,\n });\n\n if (disposition === \"skip\") {\n settlePendingBrowserRouterState(pendingRouterState);\n const resolve = pendingNavigationCommits.get(renderId);\n pendingNavigationCommits.delete(renderId);\n resolve?.();\n return;\n }\n\n if (disposition === \"hard-navigate\") {\n settlePendingBrowserRouterState(pendingRouterState);\n pendingNavigationCommits.delete(renderId);\n window.location.assign(targetHref);\n return;\n }\n\n queuePrePaintNavigationEffect(\n renderId,\n createNavigationCommitEffect(\n targetHref,\n historyUpdateMode,\n navId,\n params,\n pending.previousNextUrl,\n ),\n );\n activateNavigationSnapshot();\n snapshotActivated = true;\n dispatchBrowserTree(\n pending.action.elements,\n navigationSnapshot,\n renderId,\n actionType,\n pending.interceptionContext,\n pending.action.layoutFlags,\n pending.previousNextUrl,\n pending.routeId,\n pending.rootLayoutTreePath,\n pendingRouterState,\n useTransition,\n );\n } catch (error) {\n // Clean up pending state on error. Only decrement the snapshot counter\n // if activateNavigationSnapshot() was actually called — if\n // createPendingNavigationCommit() threw, the counter was never\n // incremented so decrementing would underflow it.\n pendingNavigationPrePaintEffects.delete(renderId);\n const resolve = pendingNavigationCommits.get(renderId);\n pendingNavigationCommits.delete(renderId);\n if (snapshotActivated) {\n commitClientNavigationState(navId);\n }\n settlePendingBrowserRouterState(pendingRouterState);\n resolve?.();\n throw error;\n }\n\n return committed;\n}\n\nfunction restoreHydrationNavigationContext(\n pathname: string,\n searchParams: SearchParamInput,\n params: Record<string, string | string[]>,\n): void {\n setNavigationContext({\n pathname,\n searchParams: new URLSearchParams(searchParams),\n params,\n });\n}\n\nfunction restorePopstateScrollPosition(state: unknown): void {\n if (!(state && typeof state === \"object\" && \"__vinext_scrollY\" in state)) {\n return;\n }\n\n const y = Number(state.__vinext_scrollY);\n const x = \"__vinext_scrollX\" in state ? Number(state.__vinext_scrollX) : 0;\n\n requestAnimationFrame(() => {\n window.scrollTo(x, y);\n });\n}\n\nasync function readInitialRscStream(): Promise<ReadableStream<Uint8Array>> {\n const vinext = getVinextBrowserGlobal();\n\n if (vinext.__VINEXT_RSC__ || vinext.__VINEXT_RSC_CHUNKS__ || vinext.__VINEXT_RSC_DONE__) {\n if (vinext.__VINEXT_RSC__) {\n const embedData = vinext.__VINEXT_RSC__;\n delete vinext.__VINEXT_RSC__;\n\n const params = embedData.params ?? {};\n if (embedData.params) {\n applyClientParams(embedData.params);\n }\n if (embedData.nav) {\n restoreHydrationNavigationContext(\n embedData.nav.pathname,\n embedData.nav.searchParams,\n params,\n );\n }\n\n return chunksToReadableStream(embedData.rsc);\n }\n\n const params = vinext.__VINEXT_RSC_PARAMS__ ?? {};\n if (vinext.__VINEXT_RSC_PARAMS__) {\n applyClientParams(vinext.__VINEXT_RSC_PARAMS__);\n }\n if (vinext.__VINEXT_RSC_NAV__) {\n restoreHydrationNavigationContext(\n vinext.__VINEXT_RSC_NAV__.pathname,\n vinext.__VINEXT_RSC_NAV__.searchParams,\n params,\n );\n }\n\n return createProgressiveRscStream();\n }\n\n const rscResponse = await fetch(toRscUrl(window.location.pathname + window.location.search));\n\n let params: Record<string, string | string[]> = {};\n const paramsHeader = rscResponse.headers.get(\"X-Vinext-Params\");\n if (paramsHeader) {\n try {\n params = JSON.parse(decodeURIComponent(paramsHeader)) as Record<string, string | string[]>;\n applyClientParams(params);\n } catch {\n // Ignore malformed param headers and continue with hydration.\n }\n }\n\n restoreHydrationNavigationContext(window.location.pathname, window.location.search, params);\n\n if (!rscResponse.body) {\n throw new Error(\"[vinext] Initial RSC response had no body\");\n }\n\n return rscResponse.body;\n}\n\nfunction registerServerActionCallback(): void {\n setServerCallback(async (id, args) => {\n const temporaryReferences = createTemporaryReferenceSet();\n const body = await encodeReply(args, { temporaryReferences });\n\n // Carry the interception context + mounted slots from the current router\n // state so the server-action re-render rebuilds the intercepted tree\n // instead of replacing it with the direct page. Parity with Next.js,\n // which sends `Next-URL` on action POSTs when the current tree contains\n // an interception route.\n const currentState = getBrowserRouterState();\n const { headers } = resolveServerActionRequestState({\n actionId: id,\n basePath: __basePath,\n elements: currentState.elements,\n previousNextUrl: currentState.previousNextUrl,\n });\n\n const fetchResponse = await fetch(toRscUrl(window.location.pathname + window.location.search), {\n method: \"POST\",\n headers,\n body,\n });\n\n const actionRedirect = fetchResponse.headers.get(\"x-action-redirect\");\n if (actionRedirect) {\n // Check for external URLs that need a hard redirect.\n try {\n const redirectUrl = new URL(actionRedirect, window.location.origin);\n if (redirectUrl.origin !== window.location.origin) {\n window.location.href = actionRedirect;\n return undefined;\n }\n } catch {\n // Fall through to hard redirect below if URL parsing fails.\n }\n\n // Use hard redirect for all action redirects because vinext's server\n // currently returns an empty body for redirect responses. RSC navigation\n // requires a valid RSC payload. This is a known parity gap with Next.js,\n // which pre-renders the redirect target's RSC payload.\n const redirectType = fetchResponse.headers.get(\"x-action-redirect-type\") ?? \"replace\";\n if (redirectType === \"push\") {\n window.location.assign(actionRedirect);\n } else {\n window.location.replace(actionRedirect);\n }\n return undefined;\n }\n\n clearClientNavigationCaches();\n\n const result = await createFromFetch<ServerActionResult | AppWireElements>(\n Promise.resolve(fetchResponse),\n { temporaryReferences },\n );\n\n // Server actions stay on the same URL and use commitSameUrlNavigatePayload()\n // for merge-based dispatch. This path does not call\n // activateNavigationSnapshot() because there is no URL change to commit, so\n // hooks continue reading the live external-store values directly. If server\n // actions ever trigger URL changes via RSC payload (instead of hard\n // redirects), this would need renderNavigationPayload().\n if (isServerActionResult(result)) {\n return commitSameUrlNavigatePayload(\n Promise.resolve(normalizeAppElements(result.root)),\n result.returnValue,\n );\n }\n\n return commitSameUrlNavigatePayload(Promise.resolve(normalizeAppElements(result)));\n });\n}\n\nasync function main(): Promise<void> {\n registerServerActionCallback();\n\n const rscStream = await readInitialRscStream();\n const root = normalizeAppElementsPromise(createFromReadableStream<AppWireElements>(rscStream));\n const initialNavigationSnapshot = createClientNavigationRenderSnapshot(\n window.location.href,\n latestClientParams,\n );\n replaceHistoryStateWithoutNotify(\n createHistoryStateWithPreviousNextUrl(window.history.state, null),\n \"\",\n window.location.href,\n );\n\n window.__VINEXT_RSC_ROOT__ = hydrateRoot(\n document,\n createElement(BrowserRoot, {\n initialElements: root,\n initialNavigationSnapshot,\n }),\n import.meta.env.DEV ? { onCaughtError: devOnCaughtError } : undefined,\n );\n window.__VINEXT_HYDRATED_AT = performance.now();\n\n window.__VINEXT_RSC_NAVIGATE__ = async function navigateRsc(\n href: string,\n redirectDepth = 0,\n navigationKind: NavigationKind = \"navigate\",\n historyUpdateMode?: HistoryUpdateMode,\n previousNextUrlOverride?: string | null,\n programmaticTransition = false,\n ): Promise<void> {\n if (redirectDepth > 10) {\n console.error(\n \"[vinext] Too many RSC redirects — aborting navigation to prevent infinite loop.\",\n );\n window.location.href = href;\n return;\n }\n\n let _snapshotPending = false;\n let pendingRouterState: PendingBrowserRouterState | null = null;\n // Hoist navId above try so the catch block can guard against hard-navigating\n // to a stale URL when this navigation has already been superseded.\n const navId = ++activeNavigationId;\n try {\n if (programmaticTransition) {\n pendingRouterState = beginPendingBrowserRouterState();\n }\n\n const url = new URL(href, window.location.origin);\n const rscUrl = toRscUrl(url.pathname + url.search);\n const requestState = getRequestState(navigationKind, previousNextUrlOverride);\n const requestInterceptionContext = requestState.interceptionContext;\n const requestPreviousNextUrl = requestState.previousNextUrl;\n\n // Compare against previous pending navigation first, then committed state.\n // This avoids isSameRoute misclassification during rapid back-to-back clicks.\n const navState = getClientNavigationState();\n const currentPath =\n navState?.pendingPathname ??\n navState?.cachedPathname ??\n stripBasePath(window.location.pathname, __basePath);\n\n const targetPath = stripBasePath(url.pathname, __basePath);\n const isSameRoute = targetPath === currentPath;\n\n // Set this navigation as the pending pathname, overwriting any previous.\n // Pass navId so only this navigation (or a newer one) can clear it later.\n setPendingPathname(url.pathname, navId);\n\n const elementsAtNavStart = getBrowserRouterState().elements;\n const mountedSlotsHeader = getMountedSlotIdsHeader(elementsAtNavStart);\n const cachedRoute = getVisitedResponse(\n rscUrl,\n requestInterceptionContext,\n mountedSlotsHeader,\n navigationKind,\n );\n if (cachedRoute) {\n // Check stale-navigation before and after createFromFetch. The pre-check\n // avoids wasted parse work; the post-check catches supersessions that\n // occur during the await. createFromFetch on a buffered response is fast\n // but still async, so the window exists. The non-cached path (below) places\n // its heavyweight async steps (fetch, snapshotRscResponse, createFromFetch)\n // between navId checks consistently; the cached path omits the check between\n // createClientNavigationRenderSnapshot (synchronous) and createFromFetch\n // because there is no await in that gap.\n if (navId !== activeNavigationId) {\n settlePendingBrowserRouterState(pendingRouterState);\n return;\n }\n const cachedParams = cachedRoute.params;\n // createClientNavigationRenderSnapshot is synchronous (URL parsing + param\n // wrapping only) — no stale-navigation recheck needed between here and the\n // next await.\n const cachedNavigationSnapshot = createClientNavigationRenderSnapshot(href, cachedParams);\n const cachedPayload = normalizeAppElementsPromise(\n createFromFetch<AppWireElements>(\n Promise.resolve(restoreRscResponse(cachedRoute.response)),\n ),\n );\n if (navId !== activeNavigationId) {\n settlePendingBrowserRouterState(pendingRouterState);\n return;\n }\n _snapshotPending = true; // Set before renderNavigationPayload\n try {\n await renderNavigationPayload(\n cachedPayload,\n cachedNavigationSnapshot,\n href,\n navId,\n historyUpdateMode,\n cachedParams,\n requestPreviousNextUrl,\n pendingRouterState,\n isSameRoute,\n toActionType(navigationKind),\n );\n } finally {\n // Always clear _snapshotPending so the outer catch does not\n // double-decrement if renderNavigationPayload throws.\n _snapshotPending = false;\n }\n return;\n }\n\n // Continue using the slot state captured at navigation start for fetches\n // and prefetch compatibility decisions.\n\n let navResponse: Response | undefined;\n let navResponseUrl: string | null = null;\n if (navigationKind !== \"refresh\") {\n const prefetchedResponse = consumePrefetchResponse(\n rscUrl,\n requestInterceptionContext,\n mountedSlotsHeader,\n );\n if (prefetchedResponse) {\n navResponse = restoreRscResponse(prefetchedResponse, false);\n navResponseUrl = prefetchedResponse.url;\n }\n }\n\n if (!navResponse) {\n const requestHeaders = createRscRequestHeaders(requestInterceptionContext);\n if (mountedSlotsHeader) {\n requestHeaders.set(\"X-Vinext-Mounted-Slots\", mountedSlotsHeader);\n }\n navResponse = await fetch(rscUrl, {\n headers: requestHeaders,\n credentials: \"include\",\n });\n }\n\n if (navId !== activeNavigationId) {\n settlePendingBrowserRouterState(pendingRouterState);\n return;\n }\n\n const finalUrl = new URL(navResponseUrl ?? navResponse.url, window.location.origin);\n const requestedUrl = new URL(rscUrl, window.location.origin);\n\n if (finalUrl.pathname !== requestedUrl.pathname) {\n const destinationPath = finalUrl.pathname.replace(/\\.rsc$/, \"\") + finalUrl.search;\n replaceHistoryStateWithoutNotify(\n createHistoryStateWithPreviousNextUrl(null, requestPreviousNextUrl),\n \"\",\n destinationPath,\n );\n\n const navigate = window.__VINEXT_RSC_NAVIGATE__;\n if (!navigate) {\n settlePendingBrowserRouterState(pendingRouterState);\n window.location.href = destinationPath;\n return;\n }\n\n // Hand ownership of the pending transition off before recursing. The\n // recursive call will not receive pendingRouterState (programmaticTransition=false),\n // so if we left it unsettled its promise would orphan in the useState slot\n // until the next programmatic push caught it via the !settled branch in\n // beginPendingBrowserRouterState. Settling here with the current committed\n // state makes isPending flip false mid-redirect — a deliberate tradeoff\n // over leaning on React's internal transition-completion heuristic.\n settlePendingBrowserRouterState(pendingRouterState);\n\n // The URL has already been updated via replaceHistoryStateWithoutNotify above,\n // so the recursive navigation should NOT push/replace again. Pass undefined\n // for historyUpdateMode to make the commit effect a no-op for history updates.\n return navigate(\n destinationPath,\n redirectDepth + 1,\n navigationKind,\n undefined,\n requestPreviousNextUrl,\n false,\n );\n }\n\n let navParams: Record<string, string | string[]> = {};\n const paramsHeader = navResponse.headers.get(\"X-Vinext-Params\");\n if (paramsHeader) {\n try {\n navParams = JSON.parse(decodeURIComponent(paramsHeader)) as Record<\n string,\n string | string[]\n >;\n } catch {\n // navParams stays as {}\n }\n }\n // Build snapshot from local params, not latestClientParams\n const navigationSnapshot = createClientNavigationRenderSnapshot(href, navParams);\n\n const responseSnapshot = await snapshotRscResponse(navResponse);\n\n if (navId !== activeNavigationId) {\n settlePendingBrowserRouterState(pendingRouterState);\n return;\n }\n\n const rscPayload = normalizeAppElementsPromise(\n createFromFetch<AppWireElements>(Promise.resolve(restoreRscResponse(responseSnapshot))),\n );\n\n if (navId !== activeNavigationId) {\n settlePendingBrowserRouterState(pendingRouterState);\n return;\n }\n\n _snapshotPending = true; // Set before renderNavigationPayload\n try {\n await renderNavigationPayload(\n rscPayload,\n navigationSnapshot,\n href,\n navId,\n historyUpdateMode,\n navParams,\n requestPreviousNextUrl,\n pendingRouterState,\n isSameRoute,\n toActionType(navigationKind),\n );\n } finally {\n // Always clear _snapshotPending after renderNavigationPayload returns or\n // throws. renderNavigationPayload's inner catch already calls\n // commitClientNavigationState() on synchronous errors and re-throws, so\n // the outer catch must not call it again. Clearing here prevents the outer\n // catch from double-decrementing navigationSnapshotActiveCount.\n _snapshotPending = false;\n }\n // Don't cache the response if this navigation was superseded during\n // renderNavigationPayload's await — the elements were never dispatched.\n if (navId !== activeNavigationId) {\n settlePendingBrowserRouterState(pendingRouterState);\n return;\n }\n // Store the visited response only after renderNavigationPayload succeeds.\n // If we stored it before and renderNavigationPayload threw, a future\n // back/forward navigation could replay a snapshot from a navigation that\n // never actually rendered successfully.\n const resolvedElements = await rscPayload;\n const metadata = readAppElementsMetadata(resolvedElements);\n storeVisitedResponseSnapshot(\n rscUrl,\n resolveVisitedResponseInterceptionContext(\n requestInterceptionContext,\n metadata.interceptionContext,\n ),\n responseSnapshot,\n navParams,\n );\n return;\n } catch (error) {\n // Only decrement counter if snapshot was activated but not yet committed.\n // renderNavigationPayload clears _snapshotPending (via its inner try-finally)\n // before re-throwing, so this guard correctly skips the double-decrement case.\n if (_snapshotPending) {\n _snapshotPending = false;\n commitClientNavigationState(navId);\n }\n settlePendingBrowserRouterState(pendingRouterState);\n // Clear pending pathname on error so subsequent navigations compare correctly.\n // Only clear if this is still the active navigation — a newer navigation\n // has already overwritten pendingPathname with its own target.\n if (navId === activeNavigationId) {\n clearPendingPathname(navId);\n }\n // Don't hard-navigate to a stale URL if this navigation was superseded by\n // a newer one — the newer navigation is already in flight and would be clobbered.\n if (navId !== activeNavigationId) {\n return;\n }\n console.error(\"[vinext] RSC navigation error:\", error);\n window.location.href = href;\n }\n };\n\n if (\"scrollRestoration\" in history) {\n history.scrollRestoration = \"manual\";\n }\n\n // Note: This popstate handler runs for App Router (RSC navigation available).\n // It coordinates scroll restoration with the pending RSC navigation.\n // Pages Router scroll restoration is handled in shims/navigation.ts:1289 with\n // microtask-based deferral for compatibility with non-RSC navigation.\n // See: https://github.com/vercel/next.js/discussions/41934#discussioncomment-4602607\n window.addEventListener(\"popstate\", (event) => {\n notifyAppRouterTransitionStart(window.location.href, \"traverse\");\n const pendingNavigation =\n window.__VINEXT_RSC_NAVIGATE__?.(window.location.href, 0, \"traverse\") ?? Promise.resolve();\n window.__VINEXT_RSC_PENDING__ = pendingNavigation;\n void pendingNavigation.finally(() => {\n restorePopstateScrollPosition(event.state);\n if (window.__VINEXT_RSC_PENDING__ === pendingNavigation) {\n window.__VINEXT_RSC_PENDING__ = null;\n }\n });\n });\n\n if (import.meta.hot) {\n import.meta.hot.on(\"rsc:update\", async () => {\n try {\n clearClientNavigationCaches();\n const navigationSnapshot = createClientNavigationRenderSnapshot(\n window.location.href,\n latestClientParams,\n );\n // Interception context on HMR re-renders is intentionally deferred:\n // preserving intercepted modal state across HMR reloads is out of scope\n // for the previousNextUrl mechanism.\n const pending = await createPendingNavigationCommit({\n currentState: getBrowserRouterState(),\n nextElements: normalizeAppElementsPromise(\n createFromFetch<AppWireElements>(\n fetch(toRscUrl(window.location.pathname + window.location.search)),\n ),\n ),\n navigationSnapshot,\n renderId: ++nextNavigationRenderId,\n type: \"replace\",\n });\n dispatchBrowserTree(\n pending.action.elements,\n navigationSnapshot,\n pending.action.renderId,\n \"replace\",\n pending.interceptionContext,\n pending.action.layoutFlags,\n pending.previousNextUrl,\n pending.routeId,\n pending.rootLayoutTreePath,\n null,\n false,\n );\n } catch (error) {\n console.error(\"[vinext] RSC HMR error:\", error);\n }\n });\n }\n}\n\nif (typeof document !== \"undefined\") {\n void main();\n}\n"],"mappings":";;;;;;;;;;;;;AA8FA,SAAS,aAAa,MAA+C;AACnE,QAAO,SAAS,aAAa,aAAa;;AAU5C,MAAM,kCAAkC;AACxC,MAAM,6BAA6B,IAAI;AACvC,MAAM,0BAA0B,KAAK;AAarC,IAAI,yBAAyB;AAC7B,IAAI,qBAAqB;AACzB,MAAM,2CAA2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C,MAAI;AACF,gCAA6B;GAC7B,MAAM,qBAAqB,qCACzB,OAAO,SAAS,MAChB,mBACD;GAID,MAAM,UAAU,MAAM,8BAA8B;IAClD,cAAc,uBAAuB;IACrC,cAAc,4BACZ,gBACE,MAAM,SAAS,OAAO,SAAS,WAAW,OAAO,SAAS,OAAO,CAAC,CACnE,CACF;IACD;IACA,UAAU,EAAE;IACZ,MAAM;IACP,CAAC;AACF,uBACE,QAAQ,OAAO,UACf,oBACA,QAAQ,OAAO,UACf,WACA,QAAQ,qBACR,QAAQ,OAAO,aACf,QAAQ,iBACR,QAAQ,SACR,QAAQ,oBACR,MACA,MACD;WACM,OAAO;AACd,WAAQ,MAAM,2BAA2B,MAAM;;GAEjD;;AAIN,IAAI,OAAO,aAAa,YACjB,OAAM"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { buildRouteHandlerAllowHeader, collectRouteHandlerMethods } from "./app-route-handler-runtime.js";
|
|
2
2
|
//#region src/server/app-route-handler-policy.ts
|
|
3
3
|
function getAppRouteHandlerRevalidateSeconds(handler) {
|
|
4
|
-
|
|
4
|
+
const { revalidate } = handler;
|
|
5
|
+
if (typeof revalidate !== "number" || !Number.isFinite(revalidate) || revalidate < 0) return null;
|
|
6
|
+
return revalidate;
|
|
5
7
|
}
|
|
6
8
|
function hasAppRouteHandlerDefaultExport(handler) {
|
|
7
9
|
return typeof handler.default === "function";
|
|
@@ -25,13 +27,13 @@ function resolveAppRouteHandlerMethod(handler, method) {
|
|
|
25
27
|
};
|
|
26
28
|
}
|
|
27
29
|
function shouldReadAppRouteHandlerCache(options) {
|
|
28
|
-
return options.isProduction && options.revalidateSeconds !== null && options.dynamicConfig !== "force-dynamic" && !options.isKnownDynamic && (options.method === "GET" || options.isAutoHead) && typeof options.handlerFn === "function";
|
|
30
|
+
return options.isProduction && options.revalidateSeconds !== null && options.revalidateSeconds > 0 && options.dynamicConfig !== "force-dynamic" && !options.isKnownDynamic && (options.method === "GET" || options.isAutoHead) && typeof options.handlerFn === "function";
|
|
29
31
|
}
|
|
30
32
|
function shouldApplyAppRouteHandlerRevalidateHeader(options) {
|
|
31
33
|
return options.revalidateSeconds !== null && !options.dynamicUsedInHandler && (options.method === "GET" || options.isAutoHead) && !options.handlerSetCacheControl;
|
|
32
34
|
}
|
|
33
35
|
function shouldWriteAppRouteHandlerCache(options) {
|
|
34
|
-
return options.isProduction && options.revalidateSeconds !== null && options.dynamicConfig !== "force-dynamic" && shouldApplyAppRouteHandlerRevalidateHeader(options);
|
|
36
|
+
return options.isProduction && options.revalidateSeconds !== null && options.revalidateSeconds > 0 && options.dynamicConfig !== "force-dynamic" && shouldApplyAppRouteHandlerRevalidateHeader(options);
|
|
35
37
|
}
|
|
36
38
|
function resolveAppRouteHandlerSpecialError(error, requestUrl) {
|
|
37
39
|
if (!(error && typeof error === "object" && "digest" in error)) return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-route-handler-policy.js","names":[],"sources":["../../src/server/app-route-handler-policy.ts"],"sourcesContent":["import {\n buildRouteHandlerAllowHeader,\n collectRouteHandlerMethods,\n type RouteHandlerHttpMethod,\n type RouteHandlerModule,\n} from \"./app-route-handler-runtime.js\";\n\nexport type AppRouteHandlerModule = {\n dynamic?: string;\n revalidate?: unknown;\n} & RouteHandlerModule;\n\ntype AppRouteHandlerFunction = (...args: unknown[]) => unknown;\n\nexport type ResolvedAppRouteHandlerMethod = {\n allowHeaderForOptions: string;\n exportedMethods: RouteHandlerHttpMethod[];\n handlerFn: AppRouteHandlerFunction | undefined;\n isAutoHead: boolean;\n shouldAutoRespondToOptions: boolean;\n};\n\nexport type AppRouteHandlerCacheReadOptions = {\n dynamicConfig?: string;\n handlerFn: unknown;\n isAutoHead: boolean;\n isKnownDynamic: boolean;\n isProduction: boolean;\n method: string;\n revalidateSeconds: number | null;\n};\n\nexport type AppRouteHandlerResponseCacheOptions = {\n dynamicConfig?: string;\n dynamicUsedInHandler: boolean;\n handlerSetCacheControl: boolean;\n isAutoHead: boolean;\n isProduction: boolean;\n method: string;\n revalidateSeconds: number | null;\n};\n\nexport type AppRouteHandlerSpecialError =\n | {\n kind: \"redirect\";\n location: string;\n statusCode: number;\n }\n | {\n kind: \"status\";\n statusCode: number;\n };\n\nexport function getAppRouteHandlerRevalidateSeconds(\n handler: Pick<AppRouteHandlerModule, \"revalidate\">,\n): number | null {\n
|
|
1
|
+
{"version":3,"file":"app-route-handler-policy.js","names":[],"sources":["../../src/server/app-route-handler-policy.ts"],"sourcesContent":["import {\n buildRouteHandlerAllowHeader,\n collectRouteHandlerMethods,\n type RouteHandlerHttpMethod,\n type RouteHandlerModule,\n} from \"./app-route-handler-runtime.js\";\n\nexport type AppRouteHandlerModule = {\n dynamic?: string;\n revalidate?: unknown;\n} & RouteHandlerModule;\n\ntype AppRouteHandlerFunction = (...args: unknown[]) => unknown;\n\nexport type ResolvedAppRouteHandlerMethod = {\n allowHeaderForOptions: string;\n exportedMethods: RouteHandlerHttpMethod[];\n handlerFn: AppRouteHandlerFunction | undefined;\n isAutoHead: boolean;\n shouldAutoRespondToOptions: boolean;\n};\n\nexport type AppRouteHandlerCacheReadOptions = {\n dynamicConfig?: string;\n handlerFn: unknown;\n isAutoHead: boolean;\n isKnownDynamic: boolean;\n isProduction: boolean;\n method: string;\n revalidateSeconds: number | null;\n};\n\nexport type AppRouteHandlerResponseCacheOptions = {\n dynamicConfig?: string;\n dynamicUsedInHandler: boolean;\n handlerSetCacheControl: boolean;\n isAutoHead: boolean;\n isProduction: boolean;\n method: string;\n revalidateSeconds: number | null;\n};\n\nexport type AppRouteHandlerSpecialError =\n | {\n kind: \"redirect\";\n location: string;\n statusCode: number;\n }\n | {\n kind: \"status\";\n statusCode: number;\n };\n\nexport function getAppRouteHandlerRevalidateSeconds(\n handler: Pick<AppRouteHandlerModule, \"revalidate\">,\n): number | null {\n // 0 is a meaningful value (\"never cache\") and must be preserved so the\n // header path can emit a no-store Cache-Control. Non-finite values\n // (Infinity, NaN) are not valid revalidate durations and fall back to\n // the null (\"no revalidate configured\") branch along with negatives.\n const { revalidate } = handler;\n if (typeof revalidate !== \"number\" || !Number.isFinite(revalidate) || revalidate < 0) {\n return null;\n }\n return revalidate;\n}\n\nexport function hasAppRouteHandlerDefaultExport(handler: RouteHandlerModule): boolean {\n return typeof handler.default === \"function\";\n}\n\nexport function resolveAppRouteHandlerMethod(\n handler: AppRouteHandlerModule,\n method: string,\n): ResolvedAppRouteHandlerMethod {\n const exportedMethods = collectRouteHandlerMethods(handler);\n const allowHeaderForOptions = buildRouteHandlerAllowHeader(exportedMethods);\n const shouldAutoRespondToOptions = method === \"OPTIONS\" && typeof handler.OPTIONS !== \"function\";\n\n let handlerFn =\n typeof handler[method as RouteHandlerHttpMethod] === \"function\"\n ? (handler[method as RouteHandlerHttpMethod] as AppRouteHandlerFunction)\n : undefined;\n let isAutoHead = false;\n\n if (\n method === \"HEAD\" &&\n typeof handler.HEAD !== \"function\" &&\n typeof handler.GET === \"function\"\n ) {\n handlerFn = handler.GET as AppRouteHandlerFunction;\n isAutoHead = true;\n }\n\n return {\n allowHeaderForOptions,\n exportedMethods,\n handlerFn,\n isAutoHead,\n shouldAutoRespondToOptions,\n };\n}\n\nexport function shouldReadAppRouteHandlerCache(options: AppRouteHandlerCacheReadOptions): boolean {\n // revalidateSeconds === 0 means \"never cache\" and must skip the ISR read.\n // A previously written entry (e.g. from before the handler opted out)\n // must never be replayed once the author set revalidate = 0.\n return (\n options.isProduction &&\n options.revalidateSeconds !== null &&\n options.revalidateSeconds > 0 &&\n options.dynamicConfig !== \"force-dynamic\" &&\n !options.isKnownDynamic &&\n (options.method === \"GET\" || options.isAutoHead) &&\n typeof options.handlerFn === \"function\"\n );\n}\n\nexport function shouldApplyAppRouteHandlerRevalidateHeader(\n options: Omit<AppRouteHandlerResponseCacheOptions, \"dynamicConfig\" | \"isProduction\">,\n): boolean {\n // Includes revalidateSeconds === 0. That case emits the no-store\n // Cache-Control, which is exactly the header a never-cache handler\n // needs to suppress heuristic caching.\n return (\n options.revalidateSeconds !== null &&\n !options.dynamicUsedInHandler &&\n (options.method === \"GET\" || options.isAutoHead) &&\n !options.handlerSetCacheControl\n );\n}\n\nexport function shouldWriteAppRouteHandlerCache(\n options: AppRouteHandlerResponseCacheOptions,\n): boolean {\n // Excludes revalidateSeconds === 0. A never-cache response must not be\n // persisted to ISR, even though it still needs a Cache-Control header.\n return (\n options.isProduction &&\n options.revalidateSeconds !== null &&\n options.revalidateSeconds > 0 &&\n options.dynamicConfig !== \"force-dynamic\" &&\n shouldApplyAppRouteHandlerRevalidateHeader(options)\n );\n}\n\nexport function resolveAppRouteHandlerSpecialError(\n error: unknown,\n requestUrl: string,\n): AppRouteHandlerSpecialError | null {\n if (!(error && typeof error === \"object\" && \"digest\" in error)) {\n return null;\n }\n\n const digest = String(error.digest);\n if (digest.startsWith(\"NEXT_REDIRECT;\")) {\n const parts = digest.split(\";\");\n const redirectUrl = decodeURIComponent(parts[2]);\n return {\n kind: \"redirect\",\n location: new URL(redirectUrl, requestUrl).toString(),\n statusCode: parts[3] ? parseInt(parts[3], 10) : 307,\n };\n }\n\n if (digest === \"NEXT_NOT_FOUND\" || digest.startsWith(\"NEXT_HTTP_ERROR_FALLBACK;\")) {\n return {\n kind: \"status\",\n statusCode: digest === \"NEXT_NOT_FOUND\" ? 404 : parseInt(digest.split(\";\")[1], 10),\n };\n }\n\n return null;\n}\n"],"mappings":";;AAqDA,SAAgB,oCACd,SACe;CAKf,MAAM,EAAE,eAAe;AACvB,KAAI,OAAO,eAAe,YAAY,CAAC,OAAO,SAAS,WAAW,IAAI,aAAa,EACjF,QAAO;AAET,QAAO;;AAGT,SAAgB,gCAAgC,SAAsC;AACpF,QAAO,OAAO,QAAQ,YAAY;;AAGpC,SAAgB,6BACd,SACA,QAC+B;CAC/B,MAAM,kBAAkB,2BAA2B,QAAQ;CAC3D,MAAM,wBAAwB,6BAA6B,gBAAgB;CAC3E,MAAM,6BAA6B,WAAW,aAAa,OAAO,Q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}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
2
2
|
//#region src/server/app-route-handler-response.ts
|
|
3
|
+
const NEVER_CACHE_CONTROL = "private, no-cache, no-store, max-age=0, must-revalidate";
|
|
3
4
|
function buildRouteHandlerCacheControl(cacheState, revalidateSeconds) {
|
|
5
|
+
if (revalidateSeconds === 0) return NEVER_CACHE_CONTROL;
|
|
4
6
|
if (cacheState === "STALE") return "s-maxage=0, stale-while-revalidate";
|
|
5
7
|
return `s-maxage=${revalidateSeconds}, stale-while-revalidate`;
|
|
6
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-route-handler-response.js","names":[],"sources":["../../src/server/app-route-handler-response.ts"],"sourcesContent":["import type { CachedRouteValue } from \"../shims/cache.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\n\nexport type RouteHandlerMiddlewareContext = {\n headers: Headers | null;\n status: number | null;\n};\n\nexport type BuildRouteHandlerCachedResponseOptions = {\n cacheState: \"HIT\" | \"STALE\";\n isHead: boolean;\n revalidateSeconds: number;\n};\n\nexport type FinalizeRouteHandlerResponseOptions = {\n pendingCookies: string[];\n draftCookie?: string | null;\n isHead: boolean;\n};\n\nfunction buildRouteHandlerCacheControl(\n cacheState: BuildRouteHandlerCachedResponseOptions[\"cacheState\"],\n revalidateSeconds: number,\n): string {\n if (cacheState === \"STALE\") {\n return \"s-maxage=0, stale-while-revalidate\";\n }\n\n return `s-maxage=${revalidateSeconds}, stale-while-revalidate`;\n}\n\nexport function applyRouteHandlerMiddlewareContext(\n response: Response,\n middlewareContext: RouteHandlerMiddlewareContext,\n): Response {\n if (!middlewareContext.headers && middlewareContext.status == null) {\n return response;\n }\n\n const responseHeaders = new Headers(response.headers);\n mergeMiddlewareResponseHeaders(responseHeaders, middlewareContext.headers);\n\n return new Response(response.body, {\n status: middlewareContext.status ?? response.status,\n statusText: response.statusText,\n headers: responseHeaders,\n });\n}\n\nexport function buildRouteHandlerCachedResponse(\n cachedValue: CachedRouteValue,\n options: BuildRouteHandlerCachedResponseOptions,\n): Response {\n const headers = new Headers();\n for (const [key, value] of Object.entries(cachedValue.headers)) {\n if (Array.isArray(value)) {\n for (const entry of value) {\n headers.append(key, entry);\n }\n } else {\n headers.set(key, value);\n }\n }\n headers.set(\"X-Vinext-Cache\", options.cacheState);\n headers.set(\n \"Cache-Control\",\n buildRouteHandlerCacheControl(options.cacheState, options.revalidateSeconds),\n );\n\n return new Response(options.isHead ? null : cachedValue.body, {\n status: cachedValue.status,\n headers,\n });\n}\n\nexport function applyRouteHandlerRevalidateHeader(\n response: Response,\n revalidateSeconds: number,\n): void {\n response.headers.set(\"cache-control\", buildRouteHandlerCacheControl(\"HIT\", revalidateSeconds));\n}\n\nexport function markRouteHandlerCacheMiss(response: Response): void {\n response.headers.set(\"X-Vinext-Cache\", \"MISS\");\n}\n\nexport async function buildAppRouteCacheValue(response: Response): Promise<CachedRouteValue> {\n const body = await response.arrayBuffer();\n const headers: CachedRouteValue[\"headers\"] = {};\n\n response.headers.forEach((value, key) => {\n if (key === \"set-cookie\" || key === \"x-vinext-cache\" || key === \"cache-control\") return;\n headers[key] = value;\n });\n const setCookies = response.headers.getSetCookie?.() ?? [];\n if (setCookies.length > 0) {\n headers[\"set-cookie\"] = setCookies;\n }\n\n return {\n kind: \"APP_ROUTE\",\n body,\n status: response.status,\n headers,\n };\n}\n\nexport function finalizeRouteHandlerResponse(\n response: Response,\n options: FinalizeRouteHandlerResponseOptions,\n): Response {\n const { pendingCookies, draftCookie, isHead } = options;\n if (pendingCookies.length === 0 && !draftCookie && !isHead) {\n return response;\n }\n\n const headers = new Headers(response.headers);\n for (const cookie of pendingCookies) {\n headers.append(\"Set-Cookie\", cookie);\n }\n if (draftCookie) {\n headers.append(\"Set-Cookie\", draftCookie);\n }\n\n return new Response(isHead ? null : response.body, {\n status: response.status,\n statusText: response.statusText,\n headers,\n });\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"app-route-handler-response.js","names":[],"sources":["../../src/server/app-route-handler-response.ts"],"sourcesContent":["import type { CachedRouteValue } from \"../shims/cache.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\n\nexport type RouteHandlerMiddlewareContext = {\n headers: Headers | null;\n status: number | null;\n};\n\nexport type BuildRouteHandlerCachedResponseOptions = {\n cacheState: \"HIT\" | \"STALE\";\n isHead: boolean;\n revalidateSeconds: number;\n};\n\nexport type FinalizeRouteHandlerResponseOptions = {\n pendingCookies: string[];\n draftCookie?: string | null;\n isHead: boolean;\n};\n\n// Matches Next.js's getCacheControlHeader for revalidate === 0.\n// See .nextjs-ref/packages/next/src/server/lib/cache-control.ts.\nconst NEVER_CACHE_CONTROL = \"private, no-cache, no-store, max-age=0, must-revalidate\";\n\nfunction buildRouteHandlerCacheControl(\n cacheState: BuildRouteHandlerCachedResponseOptions[\"cacheState\"],\n revalidateSeconds: number,\n): string {\n if (revalidateSeconds === 0) {\n // A cached response is never produced for revalidate = 0 (the ISR write\n // path skips it), so only the HIT/STALE->fresh rewrite can arrive here\n // with a 0 value, via applyRouteHandlerRevalidateHeader. In all such\n // cases the author opted out of caching entirely.\n return NEVER_CACHE_CONTROL;\n }\n\n if (cacheState === \"STALE\") {\n return \"s-maxage=0, stale-while-revalidate\";\n }\n\n return `s-maxage=${revalidateSeconds}, stale-while-revalidate`;\n}\n\nexport function applyRouteHandlerMiddlewareContext(\n response: Response,\n middlewareContext: RouteHandlerMiddlewareContext,\n): Response {\n if (!middlewareContext.headers && middlewareContext.status == null) {\n return response;\n }\n\n const responseHeaders = new Headers(response.headers);\n mergeMiddlewareResponseHeaders(responseHeaders, middlewareContext.headers);\n\n return new Response(response.body, {\n status: middlewareContext.status ?? response.status,\n statusText: response.statusText,\n headers: responseHeaders,\n });\n}\n\nexport function buildRouteHandlerCachedResponse(\n cachedValue: CachedRouteValue,\n options: BuildRouteHandlerCachedResponseOptions,\n): Response {\n const headers = new Headers();\n for (const [key, value] of Object.entries(cachedValue.headers)) {\n if (Array.isArray(value)) {\n for (const entry of value) {\n headers.append(key, entry);\n }\n } else {\n headers.set(key, value);\n }\n }\n headers.set(\"X-Vinext-Cache\", options.cacheState);\n headers.set(\n \"Cache-Control\",\n buildRouteHandlerCacheControl(options.cacheState, options.revalidateSeconds),\n );\n\n return new Response(options.isHead ? null : cachedValue.body, {\n status: cachedValue.status,\n headers,\n });\n}\n\nexport function applyRouteHandlerRevalidateHeader(\n response: Response,\n revalidateSeconds: number,\n): void {\n response.headers.set(\"cache-control\", buildRouteHandlerCacheControl(\"HIT\", revalidateSeconds));\n}\n\nexport function markRouteHandlerCacheMiss(response: Response): void {\n response.headers.set(\"X-Vinext-Cache\", \"MISS\");\n}\n\nexport async function buildAppRouteCacheValue(response: Response): Promise<CachedRouteValue> {\n const body = await response.arrayBuffer();\n const headers: CachedRouteValue[\"headers\"] = {};\n\n response.headers.forEach((value, key) => {\n if (key === \"set-cookie\" || key === \"x-vinext-cache\" || key === \"cache-control\") return;\n headers[key] = value;\n });\n const setCookies = response.headers.getSetCookie?.() ?? [];\n if (setCookies.length > 0) {\n headers[\"set-cookie\"] = setCookies;\n }\n\n return {\n kind: \"APP_ROUTE\",\n body,\n status: response.status,\n headers,\n };\n}\n\nexport function finalizeRouteHandlerResponse(\n response: Response,\n options: FinalizeRouteHandlerResponseOptions,\n): Response {\n const { pendingCookies, draftCookie, isHead } = options;\n if (pendingCookies.length === 0 && !draftCookie && !isHead) {\n return response;\n }\n\n const headers = new Headers(response.headers);\n for (const cookie of pendingCookies) {\n headers.append(\"Set-Cookie\", cookie);\n }\n if (draftCookie) {\n headers.append(\"Set-Cookie\", draftCookie);\n }\n\n return new Response(isHead ? null : response.body, {\n status: response.status,\n statusText: response.statusText,\n headers,\n });\n}\n"],"mappings":";;AAsBA,MAAM,sBAAsB;AAE5B,SAAS,8BACP,YACA,mBACQ;AACR,KAAI,sBAAsB,EAK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E;AAC1D,KAAI,WAAW,SAAS,EACtB,SAAQ,gBAAgB;AAG1B,QAAO;EACL,MAAM;EACN;EACA,QAAQ,SAAS;EACjB;EACD;;AAGH,SAAgB,6BACd,UACA,SACU;CACV,MAAM,EAAE,gBAAgB,aAAa,WAAW;AAChD,KAAI,eAAe,WAAW,KAAK,CAAC,eAAe,CAAC,OAClD,QAAO;CAGT,MAAM,UAAU,IAAI,QAAQ,SAAS,QAAQ;AAC7C,MAAK,MAAM,UAAU,eACnB,SAAQ,OAAO,cAAc,OAAO;AAEtC,KAAI,YACF,SAAQ,OAAO,cAAc,YAAY;AAG3C,QAAO,IAAI,SAAS,SAAS,OAAO,SAAS,MAAM;EACjD,QAAQ,SAAS;EACjB,YAAY,SAAS;EACrB;EACD,CAAC"}
|
|
@@ -212,7 +212,7 @@ declare function replaceHistoryStateWithoutNotify(data: unknown, unused: string,
|
|
|
212
212
|
/**
|
|
213
213
|
* Navigate to a URL, handling external URLs, hash-only changes, and RSC navigation.
|
|
214
214
|
*/
|
|
215
|
-
declare function navigateClientSide(href: string, mode: "push" | "replace", scroll: boolean): Promise<void>;
|
|
215
|
+
declare function navigateClientSide(href: string, mode: "push" | "replace", scroll: boolean, programmaticTransition?: boolean): Promise<void>;
|
|
216
216
|
/**
|
|
217
217
|
* App Router's useRouter — returns push/replace/back/forward/refresh.
|
|
218
218
|
* Different from Pages Router's useRouter (next/router).
|
package/dist/shims/navigation.js
CHANGED
|
@@ -642,7 +642,7 @@ function restoreScrollPosition(state) {
|
|
|
642
642
|
/**
|
|
643
643
|
* Navigate to a URL, handling external URLs, hash-only changes, and RSC navigation.
|
|
644
644
|
*/
|
|
645
|
-
async function navigateClientSide(href, mode, scroll) {
|
|
645
|
+
async function navigateClientSide(href, mode, scroll, programmaticTransition = false) {
|
|
646
646
|
let normalizedHref = href;
|
|
647
647
|
if (isExternalUrl(href)) {
|
|
648
648
|
const localPath = toSameOriginAppPath(href, __basePath);
|
|
@@ -666,7 +666,7 @@ async function navigateClientSide(href, mode, scroll) {
|
|
|
666
666
|
}
|
|
667
667
|
const hashIdx = fullHref.indexOf("#");
|
|
668
668
|
const hash = hashIdx !== -1 ? fullHref.slice(hashIdx) : "";
|
|
669
|
-
if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") await window.__VINEXT_RSC_NAVIGATE__(fullHref, 0, "navigate", mode);
|
|
669
|
+
if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") await window.__VINEXT_RSC_NAVIGATE__(fullHref, 0, "navigate", mode, void 0, programmaticTransition);
|
|
670
670
|
else {
|
|
671
671
|
if (mode === "replace") replaceHistoryStateWithoutNotify(null, "", fullHref);
|
|
672
672
|
else pushHistoryStateWithoutNotify(null, "", fullHref);
|
|
@@ -678,11 +678,15 @@ async function navigateClientSide(href, mode, scroll) {
|
|
|
678
678
|
const _appRouter = {
|
|
679
679
|
push(href, options) {
|
|
680
680
|
if (isServer) return;
|
|
681
|
-
|
|
681
|
+
React$1.startTransition(() => {
|
|
682
|
+
navigateClientSide(href, "push", options?.scroll !== false, true);
|
|
683
|
+
});
|
|
682
684
|
},
|
|
683
685
|
replace(href, options) {
|
|
684
686
|
if (isServer) return;
|
|
685
|
-
|
|
687
|
+
React$1.startTransition(() => {
|
|
688
|
+
navigateClientSide(href, "replace", options?.scroll !== false, true);
|
|
689
|
+
});
|
|
686
690
|
},
|
|
687
691
|
back() {
|
|
688
692
|
if (isServer) return;
|
|
@@ -694,7 +698,13 @@ const _appRouter = {
|
|
|
694
698
|
},
|
|
695
699
|
refresh() {
|
|
696
700
|
if (isServer) return;
|
|
697
|
-
|
|
701
|
+
const rscNavigate = window.__VINEXT_RSC_NAVIGATE__;
|
|
702
|
+
if (typeof rscNavigate === "function") {
|
|
703
|
+
const navigate = () => {
|
|
704
|
+
rscNavigate(window.location.href, 0, "refresh", void 0, void 0, true);
|
|
705
|
+
};
|
|
706
|
+
React$1.startTransition(navigate);
|
|
707
|
+
}
|
|
698
708
|
},
|
|
699
709
|
prefetch(href) {
|
|
700
710
|
if (isServer) return;
|