vinext 0.0.36 → 0.0.38
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/README.md +2 -2
- package/dist/cache.d.ts +2 -0
- package/dist/cache.js +2 -0
- package/dist/cli.js +6 -22
- package/dist/cli.js.map +1 -1
- package/dist/client/empty-module.d.ts +1 -0
- package/dist/client/empty-module.js +1 -0
- package/dist/client/entry.js +2 -0
- package/dist/client/entry.js.map +1 -1
- package/dist/client/instrumentation-client-state.d.ts +10 -0
- package/dist/client/instrumentation-client-state.js +19 -0
- package/dist/client/instrumentation-client-state.js.map +1 -0
- package/dist/client/instrumentation-client.d.ts +8 -0
- package/dist/client/instrumentation-client.js +8 -0
- package/dist/client/instrumentation-client.js.map +1 -0
- package/dist/cloudflare/tpr.js +1 -3
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/deploy.js +9 -3
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-rsc-entry.js +34 -22
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.js +2 -0
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +41 -260
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/entries/runtime-entry-module.d.ts +13 -1
- package/dist/entries/runtime-entry-module.js +18 -4
- package/dist/entries/runtime-entry-module.js.map +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/index.js +101 -696
- package/dist/index.js.map +1 -1
- package/dist/plugins/fix-use-server-closure-collision.d.ts +29 -0
- package/dist/plugins/fix-use-server-closure-collision.js +204 -0
- package/dist/plugins/fix-use-server-closure-collision.js.map +1 -0
- package/dist/plugins/fonts.d.ts +39 -0
- package/dist/plugins/fonts.js +432 -0
- package/dist/plugins/fonts.js.map +1 -0
- package/dist/plugins/instrumentation-client.d.ts +7 -0
- package/dist/plugins/instrumentation-client.js +29 -0
- package/dist/plugins/instrumentation-client.js.map +1 -0
- package/dist/plugins/og-assets.d.ts +26 -0
- package/dist/plugins/og-assets.js +118 -0
- package/dist/plugins/og-assets.js.map +1 -0
- package/dist/server/api-handler.js +6 -23
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-browser-entry.js +5 -1
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/dev-server.js +3 -1
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/instrumentation.d.ts +5 -1
- package/dist/server/instrumentation.js +15 -6
- package/dist/server/instrumentation.js.map +1 -1
- package/dist/server/middleware.d.ts +2 -0
- package/dist/server/middleware.js +14 -7
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/normalize-path.d.ts +22 -1
- package/dist/server/normalize-path.js +32 -1
- package/dist/server/normalize-path.js.map +1 -1
- package/dist/server/pages-api-route.d.ts +23 -0
- package/dist/server/pages-api-route.js +40 -0
- package/dist/server/pages-api-route.js.map +1 -0
- package/dist/server/pages-media-type.d.ts +16 -0
- package/dist/server/pages-media-type.js +25 -0
- package/dist/server/pages-media-type.js.map +1 -0
- package/dist/server/pages-node-compat.d.ts +45 -0
- package/dist/server/pages-node-compat.js +148 -0
- package/dist/server/pages-node-compat.js.map +1 -0
- package/dist/server/prod-server.js +1 -0
- package/dist/server/prod-server.js.map +1 -1
- package/dist/shims/cache-for-request.d.ts +58 -0
- package/dist/shims/cache-for-request.js +74 -0
- package/dist/shims/cache-for-request.js.map +1 -0
- package/dist/shims/dynamic.js +25 -10
- package/dist/shims/dynamic.js.map +1 -1
- package/dist/shims/headers.js +1 -1
- package/dist/shims/image.js +24 -8
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/layout-segment-context.js +9 -3
- package/dist/shims/layout-segment-context.js.map +1 -1
- package/dist/shims/link.js +2 -0
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/navigation.js +2 -0
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/server.d.ts +1 -0
- package/dist/shims/server.js +3 -0
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +2 -0
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/shims/unified-request-context.js.map +1 -1
- package/package.json +8 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.js","names":["React"],"sources":["../../src/shims/navigation.ts"],"sourcesContent":["/**\n * next/navigation shim\n *\n * App Router navigation hooks. These work on both server (RSC) and client.\n * Server-side: reads from a request context set by the RSC handler.\n * Client-side: reads from browser Location API and provides navigation.\n */\n\n// Use namespace import for RSC safety: the react-server condition doesn't export\n// createContext/useContext/useSyncExternalStore as named exports, and strict ESM\n// would throw at link time for missing bindings. With `import * as React`, the\n// bindings are just `undefined` on the namespace object and we can guard at runtime.\nimport * as React from \"react\";\nimport { toBrowserNavigationHref, toSameOriginAppPath } from \"./url-utils.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport { ReadonlyURLSearchParams } from \"./readonly-url-search-params.js\";\n\n// ─── Layout segment context ───────────────────────────────────────────────────\n// Stores the child segments below the current layout. Each layout wraps its\n// children with a provider whose value is the remaining route tree segments\n// (including route groups, with dynamic params resolved to actual values).\n// Created lazily because `React.createContext` is NOT available in the\n// react-server condition of React. In the RSC environment, this remains null.\n// The shared context lives behind a global singleton so provider/hook pairs\n// still line up if Vite loads this shim through multiple resolved module IDs.\nconst _LAYOUT_SEGMENT_CTX_KEY = Symbol.for(\"vinext.layoutSegmentContext\");\nconst _SERVER_INSERTED_HTML_CTX_KEY = Symbol.for(\"vinext.serverInsertedHTMLContext\");\ntype _LayoutSegmentGlobal = typeof globalThis & {\n [_LAYOUT_SEGMENT_CTX_KEY]?: React.Context<string[]> | null;\n [_SERVER_INSERTED_HTML_CTX_KEY]?: React.Context<\n ((callback: () => unknown) => void) | null\n > | null;\n};\n\n// ─── ServerInsertedHTML context ────────────────────────────────────────────────\n// Used by CSS-in-JS libraries (Apollo Client, styled-components, emotion) to\n// register HTML injection callbacks during SSR via useContext().\n// The SSR entry wraps the rendered tree with a Provider whose value is a\n// callback registration function (useServerInsertedHTML).\n//\n// In Next.js, ServerInsertedHTMLContext holds a function:\n// (callback: () => React.ReactNode) => void\n// Libraries call useContext(ServerInsertedHTMLContext) to get this function,\n// then call it to register callbacks that inject HTML during SSR.\n//\n// Created eagerly at module load time. In the RSC environment (react-server\n// condition), createContext isn't available so this will be null.\n\nfunction getServerInsertedHTMLContext(): React.Context<\n ((callback: () => unknown) => void) | null\n> | null {\n if (typeof React.createContext !== \"function\") return null;\n\n const globalState = globalThis as _LayoutSegmentGlobal;\n if (!globalState[_SERVER_INSERTED_HTML_CTX_KEY]) {\n globalState[_SERVER_INSERTED_HTML_CTX_KEY] = React.createContext<\n ((callback: () => unknown) => void) | null\n >(null);\n }\n\n return globalState[_SERVER_INSERTED_HTML_CTX_KEY] ?? null;\n}\n\nexport const ServerInsertedHTMLContext: React.Context<\n ((callback: () => unknown) => void) | null\n> | null = getServerInsertedHTMLContext();\n\n/**\n * Get or create the layout segment context.\n * Returns null in the RSC environment (createContext unavailable).\n */\nexport function getLayoutSegmentContext(): React.Context<string[]> | null {\n if (typeof React.createContext !== \"function\") return null;\n\n const globalState = globalThis as _LayoutSegmentGlobal;\n if (!globalState[_LAYOUT_SEGMENT_CTX_KEY]) {\n globalState[_LAYOUT_SEGMENT_CTX_KEY] = React.createContext<string[]>([]);\n }\n\n return globalState[_LAYOUT_SEGMENT_CTX_KEY] ?? null;\n}\n\n/**\n * Read the child segments below the current layout from context.\n * Returns [] if no context is available (RSC environment, outside React tree).\n */\nfunction useChildSegments(): string[] {\n const ctx = getLayoutSegmentContext();\n if (!ctx) return [];\n // useContext is safe here because if createContext exists, useContext does too.\n // This branch is only taken in SSR/Browser, never in RSC.\n // Try/catch for unit tests that call this hook outside a React render tree.\n try {\n return React.useContext(ctx);\n } catch {\n return [];\n }\n}\n\n// ---------------------------------------------------------------------------\n// Server-side request context (set by the RSC entry before rendering)\n// ---------------------------------------------------------------------------\n\nexport interface NavigationContext {\n pathname: string;\n searchParams: URLSearchParams;\n params: Record<string, string | string[]>;\n}\n\nconst _READONLY_SEARCH_PARAMS = Symbol(\"vinext.navigation.readonlySearchParams\");\nconst _READONLY_SEARCH_PARAMS_SOURCE = Symbol(\"vinext.navigation.readonlySearchParamsSource\");\n\ntype NavigationContextWithReadonlyCache = NavigationContext & {\n [_READONLY_SEARCH_PARAMS]?: ReadonlyURLSearchParams;\n [_READONLY_SEARCH_PARAMS_SOURCE]?: URLSearchParams;\n};\n\n// ---------------------------------------------------------------------------\n// Server-side navigation state lives in a separate server-only module\n// (navigation-state.ts) that uses AsyncLocalStorage for request isolation.\n// This module is bundled for the browser, so it can't import node:async_hooks.\n//\n// On the server: state functions are set by navigation-state.ts at import time.\n// On the client: _serverContext falls back to null (hooks use window instead).\n//\n// Global accessor pattern (issue #688):\n// Vite's multi-environment dev mode can create separate module instances of\n// this file for the SSR entry vs \"use client\" components. When that happens,\n// _registerStateAccessors only updates the SSR entry's instance, leaving the\n// \"use client\" instance with the default (null) fallbacks.\n//\n// To fix this, navigation-state.ts also stores the accessors on globalThis\n// via Symbol.for, and the defaults here check for that global before falling\n// back to module-level state. This ensures all module instances can reach the\n// ALS-backed state regardless of which instance was registered.\n// ---------------------------------------------------------------------------\n\ninterface _StateAccessors {\n getServerContext: () => NavigationContext | null;\n setServerContext: (ctx: NavigationContext | null) => void;\n getInsertedHTMLCallbacks: () => Array<() => unknown>;\n clearInsertedHTMLCallbacks: () => void;\n}\n\nexport const GLOBAL_ACCESSORS_KEY = Symbol.for(\"vinext.navigation.globalAccessors\");\nconst _GLOBAL_ACCESSORS_KEY = GLOBAL_ACCESSORS_KEY;\ntype _GlobalWithAccessors = typeof globalThis & { [_GLOBAL_ACCESSORS_KEY]?: _StateAccessors };\n\nfunction _getGlobalAccessors(): _StateAccessors | undefined {\n return (globalThis as _GlobalWithAccessors)[_GLOBAL_ACCESSORS_KEY];\n}\n\nlet _serverContext: NavigationContext | null = null;\nlet _serverInsertedHTMLCallbacks: Array<() => unknown> = [];\n\n// These are overridden by navigation-state.ts on the server to use ALS.\n// The defaults check globalThis for cross-module-instance access (issue #688).\nlet _getServerContext = (): NavigationContext | null => {\n const g = _getGlobalAccessors();\n return g ? g.getServerContext() : _serverContext;\n};\nlet _setServerContext = (ctx: NavigationContext | null): void => {\n const g = _getGlobalAccessors();\n if (g) {\n g.setServerContext(ctx);\n } else {\n _serverContext = ctx;\n }\n};\nlet _getInsertedHTMLCallbacks = (): Array<() => unknown> => {\n const g = _getGlobalAccessors();\n return g ? g.getInsertedHTMLCallbacks() : _serverInsertedHTMLCallbacks;\n};\nlet _clearInsertedHTMLCallbacks = (): void => {\n const g = _getGlobalAccessors();\n if (g) {\n g.clearInsertedHTMLCallbacks();\n } else {\n _serverInsertedHTMLCallbacks = [];\n }\n};\n\n/**\n * Register ALS-backed state accessors. Called by navigation-state.ts on import.\n * @internal\n */\nexport function _registerStateAccessors(accessors: _StateAccessors): void {\n _getServerContext = accessors.getServerContext;\n _setServerContext = accessors.setServerContext;\n _getInsertedHTMLCallbacks = accessors.getInsertedHTMLCallbacks;\n _clearInsertedHTMLCallbacks = accessors.clearInsertedHTMLCallbacks;\n}\n\n/**\n * Get the navigation context for the current SSR/RSC render.\n * Reads from AsyncLocalStorage when available (concurrent-safe),\n * otherwise falls back to module-level state.\n */\nexport function getNavigationContext(): NavigationContext | null {\n return _getServerContext();\n}\n\n/**\n * Set the navigation context for the current SSR/RSC render.\n * Called by the framework entry before rendering each request.\n */\nexport function setNavigationContext(ctx: NavigationContext | null): void {\n _setServerContext(ctx);\n}\n\n// ---------------------------------------------------------------------------\n// Client-side state\n// ---------------------------------------------------------------------------\n\nconst isServer = typeof window === \"undefined\";\n\n/** basePath from next.config.js, injected by the plugin at build time */\nconst __basePath: string = process.env.__NEXT_ROUTER_BASEPATH ?? \"\";\n\n// ---------------------------------------------------------------------------\n// RSC prefetch cache utilities (shared between link.tsx and browser entry)\n// ---------------------------------------------------------------------------\n\n/** Maximum number of entries in the RSC prefetch cache. */\nexport const MAX_PREFETCH_CACHE_SIZE = 50;\n\n/** TTL for prefetch cache entries in ms (matches Next.js static prefetch TTL). */\nexport const PREFETCH_CACHE_TTL = 30_000;\n\nexport interface PrefetchCacheEntry {\n response: Response;\n timestamp: number;\n}\n\n/**\n * Convert a pathname (with optional query/hash) to its .rsc URL.\n * Strips trailing slashes before appending `.rsc` so that cache keys\n * are consistent regardless of the `trailingSlash` config setting.\n */\nexport function toRscUrl(href: string): string {\n const [beforeHash] = href.split(\"#\");\n const qIdx = beforeHash.indexOf(\"?\");\n const pathname = qIdx === -1 ? beforeHash : beforeHash.slice(0, qIdx);\n const query = qIdx === -1 ? \"\" : beforeHash.slice(qIdx);\n // Strip trailing slash (but preserve \"/\" root) for consistent cache keys\n const normalizedPath =\n pathname.length > 1 && pathname.endsWith(\"/\") ? pathname.slice(0, -1) : pathname;\n return normalizedPath + \".rsc\" + query;\n}\n\n/** Get or create the shared in-memory RSC prefetch cache on window. */\nexport function getPrefetchCache(): Map<string, PrefetchCacheEntry> {\n if (isServer) return new Map();\n if (!window.__VINEXT_RSC_PREFETCH_CACHE__) {\n window.__VINEXT_RSC_PREFETCH_CACHE__ = new Map<string, PrefetchCacheEntry>();\n }\n return window.__VINEXT_RSC_PREFETCH_CACHE__;\n}\n\n/**\n * Get or create the shared set of already-prefetched RSC URLs on window.\n * Keyed by rscUrl so that the browser entry can clear entries when consumed.\n */\nexport function getPrefetchedUrls(): Set<string> {\n if (isServer) return new Set();\n if (!window.__VINEXT_RSC_PREFETCHED_URLS__) {\n window.__VINEXT_RSC_PREFETCHED_URLS__ = new Set<string>();\n }\n return window.__VINEXT_RSC_PREFETCHED_URLS__;\n}\n\n/**\n * Store a prefetched RSC response in the cache.\n * Enforces a maximum cache size to prevent unbounded memory growth on\n * link-heavy pages.\n */\nexport function storePrefetchResponse(rscUrl: string, response: Response): void {\n const cache = getPrefetchCache();\n const now = Date.now();\n\n // Sweep expired entries before resorting to FIFO eviction\n if (cache.size >= MAX_PREFETCH_CACHE_SIZE) {\n const prefetched = getPrefetchedUrls();\n for (const [key, entry] of cache) {\n if (now - entry.timestamp >= PREFETCH_CACHE_TTL) {\n cache.delete(key);\n prefetched.delete(key);\n }\n }\n }\n\n // FIFO fallback if still at capacity after sweep\n if (cache.size >= MAX_PREFETCH_CACHE_SIZE) {\n const oldest = cache.keys().next().value;\n if (oldest !== undefined) {\n cache.delete(oldest);\n getPrefetchedUrls().delete(oldest);\n }\n }\n\n cache.set(rscUrl, { response, timestamp: now });\n}\n\n// Client navigation listeners\ntype NavigationListener = () => void;\nconst _listeners: Set<NavigationListener> = new Set();\n\nfunction notifyListeners(): void {\n for (const fn of _listeners) fn();\n}\n\n// Cached URLSearchParams, pathname, etc. for referential stability\n// useSyncExternalStore compares snapshots with Object.is — avoid creating\n// new instances on every render (infinite re-renders).\nlet _cachedSearch = !isServer ? window.location.search : \"\";\nlet _cachedReadonlySearchParams = new ReadonlyURLSearchParams(_cachedSearch);\nlet _cachedEmptyServerSearchParams: ReadonlyURLSearchParams | null = null;\nlet _cachedPathname = !isServer ? stripBasePath(window.location.pathname, __basePath) : \"/\";\n\nfunction getPathnameSnapshot(): string {\n const current = stripBasePath(window.location.pathname, __basePath);\n if (current !== _cachedPathname) {\n _cachedPathname = current;\n }\n return _cachedPathname;\n}\n\nfunction getSearchParamsSnapshot(): ReadonlyURLSearchParams {\n const current = window.location.search;\n if (current !== _cachedSearch) {\n _cachedSearch = current;\n _cachedReadonlySearchParams = new ReadonlyURLSearchParams(current);\n }\n return _cachedReadonlySearchParams;\n}\n\nfunction getServerSearchParamsSnapshot(): ReadonlyURLSearchParams {\n const ctx = _getServerContext() as NavigationContextWithReadonlyCache | null;\n if (ctx != null) {\n const searchParams = ctx.searchParams;\n if (ctx[_READONLY_SEARCH_PARAMS_SOURCE] !== searchParams) {\n ctx[_READONLY_SEARCH_PARAMS_SOURCE] = searchParams;\n ctx[_READONLY_SEARCH_PARAMS] = new ReadonlyURLSearchParams(searchParams);\n }\n return ctx[_READONLY_SEARCH_PARAMS]!;\n }\n if (_cachedEmptyServerSearchParams === null) {\n _cachedEmptyServerSearchParams = new ReadonlyURLSearchParams();\n }\n return _cachedEmptyServerSearchParams;\n}\n\n// Track client-side params (set during RSC hydration/navigation)\n// We cache the params object for referential stability — only create a new\n// object when the params actually change (shallow key/value comparison).\nconst _EMPTY_PARAMS: Record<string, string | string[]> = {};\nlet _clientParams: Record<string, string | string[]> = _EMPTY_PARAMS;\nlet _clientParamsJson = \"{}\";\n\nexport function setClientParams(params: Record<string, string | string[]>): void {\n const json = JSON.stringify(params);\n if (json !== _clientParamsJson) {\n _clientParams = params;\n _clientParamsJson = json;\n // Notify useSyncExternalStore subscribers so useParams() re-renders.\n notifyListeners();\n }\n}\n\n/** Get the current client params (for testing referential stability). */\nexport function getClientParams(): Record<string, string | string[]> {\n return _clientParams;\n}\n\nfunction getClientParamsSnapshot(): Record<string, string | string[]> {\n return _clientParams;\n}\n\nfunction getServerParamsSnapshot(): Record<string, string | string[]> {\n return _getServerContext()?.params ?? _EMPTY_PARAMS;\n}\n\nfunction subscribeToNavigation(cb: () => void): () => void {\n _listeners.add(cb);\n return () => {\n _listeners.delete(cb);\n };\n}\n\n// ---------------------------------------------------------------------------\n// Hooks\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the current pathname.\n * Server: from request context. Client: from window.location.\n */\nexport function usePathname(): string {\n if (isServer) {\n // During SSR of \"use client\" components, the navigation context may not be set.\n // Return a safe fallback — the client will hydrate with the real value.\n return _getServerContext()?.pathname ?? \"/\";\n }\n // Client-side: use the hook system for reactivity\n return React.useSyncExternalStore(\n subscribeToNavigation,\n getPathnameSnapshot,\n () => _getServerContext()?.pathname ?? \"/\",\n );\n}\n\n/**\n * Returns the current search params as a read-only URLSearchParams.\n */\nexport function useSearchParams(): ReadonlyURLSearchParams {\n if (isServer) {\n // During SSR of \"use client\" components, the navigation context may not be set.\n // Return a safe fallback — the client will hydrate with the real value.\n return getServerSearchParamsSnapshot();\n }\n return React.useSyncExternalStore(\n subscribeToNavigation,\n getSearchParamsSnapshot,\n getServerSearchParamsSnapshot,\n );\n}\n\n/**\n * Returns the dynamic params for the current route.\n */\nexport function useParams<\n T extends Record<string, string | string[]> = Record<string, string | string[]>,\n>(): T {\n if (isServer) {\n // During SSR of \"use client\" components, the navigation context may not be set.\n return (_getServerContext()?.params ?? _EMPTY_PARAMS) as T;\n }\n return React.useSyncExternalStore(\n subscribeToNavigation,\n getClientParamsSnapshot as () => T,\n getServerParamsSnapshot as () => T,\n );\n}\n\n/**\n * Check if a href is an external URL (any URL scheme per RFC 3986, or protocol-relative).\n */\nfunction isExternalUrl(href: string): boolean {\n return /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith(\"//\");\n}\n\n/**\n * Check if a href is only a hash change relative to the current URL.\n */\nfunction isHashOnlyChange(href: string): boolean {\n if (typeof window === \"undefined\") return false;\n if (href.startsWith(\"#\")) return true;\n try {\n const current = new URL(window.location.href);\n const next = new URL(href, window.location.href);\n return current.pathname === next.pathname && current.search === next.search && next.hash !== \"\";\n } catch {\n return false;\n }\n}\n\n/**\n * Scroll to a hash target element, or to the top if no hash.\n */\nfunction scrollToHash(hash: string): void {\n if (!hash || hash === \"#\") {\n window.scrollTo(0, 0);\n return;\n }\n const id = hash.slice(1);\n const element = document.getElementById(id);\n if (element) {\n element.scrollIntoView({ behavior: \"auto\" });\n }\n}\n\n/**\n * Reference to the native history.replaceState before patching.\n * Used internally to avoid triggering the interception for internal operations\n * (e.g. saving scroll position shouldn't cause re-renders).\n * Captured before the history method patching at the bottom of this module.\n */\nconst _nativeReplaceState: typeof window.history.replaceState | null = !isServer\n ? window.history.replaceState.bind(window.history)\n : null;\n\n/**\n * Save the current scroll position into the current history state.\n * Called before every navigation to enable scroll restoration on back/forward.\n *\n * Uses _nativeReplaceState to avoid triggering the history.replaceState\n * interception (which would cause spurious re-renders from notifyListeners).\n */\nfunction saveScrollPosition(): void {\n if (!_nativeReplaceState) return;\n const state = window.history.state ?? {};\n _nativeReplaceState.call(\n window.history,\n { ...state, __vinext_scrollX: window.scrollX, __vinext_scrollY: window.scrollY },\n \"\",\n );\n}\n\n/**\n * Restore scroll position from a history state object (used on popstate).\n *\n * When an RSC navigation is in flight (back/forward triggers both this\n * handler and the browser entry's popstate handler which calls\n * __VINEXT_RSC_NAVIGATE__), we must wait for the new content to render\n * before scrolling. Otherwise the user sees old content flash at the\n * restored scroll position.\n *\n * This handler fires before the browser entry's popstate handler (because\n * navigation.ts is loaded before hydration completes), so we defer via a\n * microtask to give the browser entry handler a chance to set\n * __VINEXT_RSC_PENDING__ first.\n */\nfunction restoreScrollPosition(state: unknown): void {\n if (state && typeof state === \"object\" && \"__vinext_scrollY\" in state) {\n const { __vinext_scrollX: x, __vinext_scrollY: y } = state as {\n __vinext_scrollX: number;\n __vinext_scrollY: number;\n };\n\n // Defer to allow other popstate listeners (browser entry) to run first\n // and set __VINEXT_RSC_PENDING__. Promise.resolve() schedules a microtask\n // that runs after all synchronous event listeners have completed.\n void Promise.resolve().then(() => {\n const pending: Promise<void> | null = window.__VINEXT_RSC_PENDING__ ?? null;\n\n if (pending) {\n // Wait for the RSC navigation to finish rendering, then scroll.\n void pending.then(() => {\n requestAnimationFrame(() => {\n window.scrollTo(x, y);\n });\n });\n } else {\n // No RSC navigation in flight (Pages Router or already settled).\n requestAnimationFrame(() => {\n window.scrollTo(x, y);\n });\n }\n });\n }\n}\n\n/**\n * Navigate to a URL, handling external URLs, hash-only changes, and RSC navigation.\n */\nasync function navigateImpl(\n href: string,\n mode: \"push\" | \"replace\",\n scroll: boolean,\n): Promise<void> {\n // Normalize same-origin absolute URLs to local paths for SPA navigation\n let normalizedHref = href;\n if (isExternalUrl(href)) {\n const localPath = toSameOriginAppPath(href, __basePath);\n if (localPath == null) {\n // Truly external: use full page navigation\n if (mode === \"replace\") {\n window.location.replace(href);\n } else {\n window.location.assign(href);\n }\n return;\n }\n normalizedHref = localPath;\n }\n\n const fullHref = toBrowserNavigationHref(normalizedHref, window.location.href, __basePath);\n\n // Save scroll position before navigating (for back/forward restoration)\n if (mode === \"push\") {\n saveScrollPosition();\n }\n\n // Hash-only change: update URL and scroll to target, skip RSC fetch\n if (isHashOnlyChange(fullHref)) {\n const hash = fullHref.includes(\"#\") ? fullHref.slice(fullHref.indexOf(\"#\")) : \"\";\n if (mode === \"replace\") {\n window.history.replaceState(null, \"\", fullHref);\n } else {\n window.history.pushState(null, \"\", fullHref);\n }\n notifyListeners();\n if (scroll) {\n scrollToHash(hash);\n }\n return;\n }\n\n // Extract hash for post-navigation scrolling\n const hashIdx = fullHref.indexOf(\"#\");\n const hash = hashIdx !== -1 ? fullHref.slice(hashIdx) : \"\";\n\n if (mode === \"replace\") {\n window.history.replaceState(null, \"\", fullHref);\n } else {\n window.history.pushState(null, \"\", fullHref);\n }\n notifyListeners();\n\n // Trigger RSC re-fetch if available, and wait for the new content to render\n // before scrolling. This prevents the old page from visibly jumping to the\n // top before the new content paints.\n if (typeof window.__VINEXT_RSC_NAVIGATE__ === \"function\") {\n await window.__VINEXT_RSC_NAVIGATE__(fullHref);\n }\n\n if (scroll) {\n if (hash) {\n scrollToHash(hash);\n } else {\n window.scrollTo(0, 0);\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// App Router router singleton\n//\n// All methods close over module-level state (navigateImpl, withBasePath, etc.)\n// and carry no per-render data, so the object can be created once and reused.\n// Next.js returns the same router reference on every call to useRouter(), which\n// matters for components that rely on referential equality (e.g. useMemo /\n// useEffect dependency arrays, React.memo bailouts).\n// ---------------------------------------------------------------------------\n\nconst _appRouter = {\n push(href: string, options?: { scroll?: boolean }): void {\n if (isServer) return;\n void navigateImpl(href, \"push\", options?.scroll !== false);\n },\n replace(href: string, options?: { scroll?: boolean }): void {\n if (isServer) return;\n void navigateImpl(href, \"replace\", options?.scroll !== false);\n },\n back(): void {\n if (isServer) return;\n window.history.back();\n },\n forward(): void {\n if (isServer) return;\n window.history.forward();\n },\n refresh(): void {\n if (isServer) return;\n // Re-fetch the current page's RSC stream\n if (typeof window.__VINEXT_RSC_NAVIGATE__ === \"function\") {\n void window.__VINEXT_RSC_NAVIGATE__(window.location.href);\n }\n },\n prefetch(href: string): void {\n if (isServer) return;\n // Prefetch the RSC payload for the target route and store in cache\n const fullHref = toBrowserNavigationHref(href, window.location.href, __basePath);\n const rscUrl = toRscUrl(fullHref);\n const prefetched = getPrefetchedUrls();\n if (prefetched.has(rscUrl)) return;\n prefetched.add(rscUrl);\n fetch(rscUrl, {\n headers: { Accept: \"text/x-component\" },\n credentials: \"include\",\n priority: \"low\" as RequestInit[\"priority\"],\n })\n .then((response) => {\n if (response.ok) {\n storePrefetchResponse(rscUrl, response);\n } else {\n // Non-ok response: allow retry on next prefetch() call\n prefetched.delete(rscUrl);\n }\n })\n .catch(() => {\n // Network error: allow retry on next prefetch() call\n prefetched.delete(rscUrl);\n });\n },\n};\n\n/**\n * App Router's useRouter — returns push/replace/back/forward/refresh.\n * Different from Pages Router's useRouter (next/router).\n *\n * Returns a stable singleton: the same object reference on every call,\n * matching Next.js behavior so components using referential equality\n * (e.g. useMemo / useEffect deps, React.memo) don't re-render unnecessarily.\n */\nexport function useRouter() {\n return _appRouter;\n}\n\n/**\n * Returns the active child segment one level below the layout where it's called.\n *\n * Returns the first segment from the route tree below this layout, including\n * route groups (e.g., \"(marketing)\") and resolved dynamic params. Returns null\n * if at the leaf (no child segments).\n *\n * @param parallelRoutesKey - Which parallel route to read (default: \"children\")\n */\nexport function useSelectedLayoutSegment(\n // parallelRoutesKey is accepted for API compat but not yet supported —\n // vinext doesn't implement parallel routes with separate segment tracking.\n _parallelRoutesKey?: string,\n): string | null {\n const segments = useSelectedLayoutSegments(_parallelRoutesKey);\n return segments.length > 0 ? segments[0] : null;\n}\n\n/**\n * Returns all active segments below the layout where it's called.\n *\n * Each layout in the App Router tree wraps its children with a\n * LayoutSegmentProvider whose value is the remaining route tree segments\n * (including route groups, with dynamic params resolved to actual values\n * and catch-all segments joined with \"/\"). This hook reads those segments\n * directly from context.\n *\n * @param parallelRoutesKey - Which parallel route to read (default: \"children\")\n */\nexport function useSelectedLayoutSegments(\n // parallelRoutesKey is accepted for API compat but not yet supported —\n // vinext doesn't implement parallel routes with separate segment tracking.\n _parallelRoutesKey?: string,\n): string[] {\n return useChildSegments();\n}\n\nexport { ReadonlyURLSearchParams };\n\n/**\n * useServerInsertedHTML — inject HTML during SSR from client components.\n *\n * Used by CSS-in-JS libraries (styled-components, emotion, StyleX) to inject\n * <style> tags during SSR so styles appear in the initial HTML (no FOUC).\n *\n * The callback is called once after each SSR render pass. The returned JSX/HTML\n * is serialized and injected into the HTML stream.\n *\n * Usage (in a \"use client\" component wrapping children):\n * useServerInsertedHTML(() => {\n * const styles = sheet.getStyleElement();\n * sheet.instance.clearTag();\n * return <>{styles}</>;\n * });\n */\n\nexport function useServerInsertedHTML(callback: () => unknown): void {\n if (typeof document !== \"undefined\") {\n // Client-side: no-op (styles are already in the DOM)\n return;\n }\n _getInsertedHTMLCallbacks().push(callback);\n}\n\n/**\n * Flush all collected useServerInsertedHTML callbacks.\n * Returns an array of results (React elements or strings).\n * Clears the callback list so the next render starts fresh.\n *\n * Called by the SSR entry after renderToReadableStream completes.\n */\nexport function flushServerInsertedHTML(): unknown[] {\n const callbacks = _getInsertedHTMLCallbacks();\n const results: unknown[] = [];\n for (const cb of callbacks) {\n try {\n const result = cb();\n if (result != null) results.push(result);\n } catch {\n // Ignore errors from individual callbacks\n }\n }\n callbacks.length = 0;\n return results;\n}\n\n/**\n * Clear all collected useServerInsertedHTML callbacks without flushing.\n * Used for cleanup between requests.\n */\nexport function clearServerInsertedHTML(): void {\n _clearInsertedHTMLCallbacks();\n}\n\n// ---------------------------------------------------------------------------\n// Non-hook utilities (can be called from Server Components)\n// ---------------------------------------------------------------------------\n\n/**\n * HTTP Access Fallback error code — shared prefix for notFound/forbidden/unauthorized.\n * Matches Next.js 16's unified error handling approach.\n */\nexport const HTTP_ERROR_FALLBACK_ERROR_CODE = \"NEXT_HTTP_ERROR_FALLBACK\";\n\n/**\n * Check if an error is an HTTP Access Fallback error (notFound, forbidden, unauthorized).\n */\nexport function isHTTPAccessFallbackError(error: unknown): boolean {\n if (error && typeof error === \"object\" && \"digest\" in error) {\n const digest = String((error as { digest: unknown }).digest);\n return (\n digest === \"NEXT_NOT_FOUND\" || // legacy compat\n digest.startsWith(`${HTTP_ERROR_FALLBACK_ERROR_CODE};`)\n );\n }\n return false;\n}\n\n/**\n * Extract the HTTP status code from an HTTP Access Fallback error.\n * Returns 404 for legacy NEXT_NOT_FOUND errors.\n */\nexport function getAccessFallbackHTTPStatus(error: unknown): number {\n if (error && typeof error === \"object\" && \"digest\" in error) {\n const digest = String((error as { digest: unknown }).digest);\n if (digest === \"NEXT_NOT_FOUND\") return 404;\n if (digest.startsWith(`${HTTP_ERROR_FALLBACK_ERROR_CODE};`)) {\n return parseInt(digest.split(\";\")[1], 10);\n }\n }\n return 404;\n}\n\n/**\n * Enum matching Next.js RedirectType for type-safe redirect calls.\n */\nexport enum RedirectType {\n push = \"push\",\n replace = \"replace\",\n}\n\n/**\n * Internal error class used by redirect/notFound/forbidden/unauthorized.\n * The `digest` field is the serialised control-flow signal read by the\n * framework's error boundary and server-side request handlers.\n */\nclass VinextNavigationError extends Error {\n readonly digest: string;\n constructor(message: string, digest: string) {\n super(message);\n this.digest = digest;\n }\n}\n\n/**\n * Throw a redirect. Caught by the framework to send a redirect response.\n */\nexport function redirect(url: string, type?: \"replace\" | \"push\" | RedirectType): never {\n throw new VinextNavigationError(\n `NEXT_REDIRECT:${url}`,\n `NEXT_REDIRECT;${type ?? \"replace\"};${encodeURIComponent(url)}`,\n );\n}\n\n/**\n * Trigger a permanent redirect (308).\n */\nexport function permanentRedirect(url: string): never {\n throw new VinextNavigationError(\n `NEXT_REDIRECT:${url}`,\n `NEXT_REDIRECT;replace;${encodeURIComponent(url)};308`,\n );\n}\n\n/**\n * Trigger a not-found response (404). Caught by the framework.\n */\nexport function notFound(): never {\n throw new VinextNavigationError(\"NEXT_NOT_FOUND\", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);\n}\n\n/**\n * Trigger a forbidden response (403). Caught by the framework.\n * In Next.js, this is gated behind experimental.authInterrupts — we\n * support it unconditionally for maximum compatibility.\n */\nexport function forbidden(): never {\n throw new VinextNavigationError(\"NEXT_FORBIDDEN\", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);\n}\n\n/**\n * Trigger an unauthorized response (401). Caught by the framework.\n * In Next.js, this is gated behind experimental.authInterrupts — we\n * support it unconditionally for maximum compatibility.\n */\nexport function unauthorized(): never {\n throw new VinextNavigationError(\"NEXT_UNAUTHORIZED\", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n// React hooks are imported at the top level via ESM.\n\n// Listen for popstate on the client\nif (!isServer) {\n window.addEventListener(\"popstate\", (event) => {\n notifyListeners();\n // Restore scroll position for back/forward navigation\n restoreScrollPosition(event.state);\n });\n\n // ---------------------------------------------------------------------------\n // history.pushState / replaceState interception (shallow routing)\n //\n // Next.js intercepts these native methods so that when user code calls\n // `window.history.pushState(null, '', '/new-path?filter=abc')` directly,\n // React hooks like usePathname() and useSearchParams() re-render with\n // the new URL. This is the foundation for shallow routing patterns\n // (filter UIs, tabs, URL search param state, etc.).\n //\n // We wrap the original methods, call through to the native implementation,\n // then notify our listener system so useSyncExternalStore picks up the\n // URL change.\n // ---------------------------------------------------------------------------\n const originalPushState = window.history.pushState.bind(window.history);\n const originalReplaceState = window.history.replaceState.bind(window.history);\n\n window.history.pushState = function patchedPushState(\n data: unknown,\n unused: string,\n url?: string | URL | null,\n ): void {\n originalPushState(data, unused, url);\n notifyListeners();\n };\n\n window.history.replaceState = function patchedReplaceState(\n data: unknown,\n unused: string,\n url?: string | URL | null,\n ): void {\n originalReplaceState(data, unused, url);\n notifyListeners();\n };\n}\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAM,0BAA0B,OAAO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;AACd,OAAK,SAAS;;;;;;AAOlB,SAAgB,SAAS,KAAa,MAAiD;AACrF,OAAM,IAAI,sBACR,iBAAiB,OACjB,iBAAiB,QAAQ,UAAU,GAAG,mBAAmB,IAAI,GAC9D;;;;;AAMH,SAAgB,kBAAkB,KAAoB;AACpD,OAAM,IAAI,sBACR,iBAAiB,OACjB,yBAAyB,mBAAmB,IAAI,CAAC,MAClD;;;;;AAMH,SAAgB,WAAkB;AAChC,OAAM,IAAI,sBAAsB,kBAAkB,GAAG,+BAA+B,MAAM;;;;;;;AAQ5F,SAAgB,YAAmB;AACjC,OAAM,IAAI,sBAAsB,kBAAkB,GAAG,+BAA+B,MAAM;;;;;;;AAQ5F,SAAgB,eAAsB;AACpC,OAAM,IAAI,sBAAsB,qBAAqB,GAAG,+BAA+B,MAAM;;AAU/F,IAAI,CAAC,UAAU;AACb,QAAO,iBAAiB,aAAa,UAAU;AAC7C,mBAAiB;AAEjB,wBAAsB,MAAM,MAAM;GAClC;CAeF,MAAM,oBAAoB,OAAO,QAAQ,UAAU,KAAK,OAAO,QAAQ;CACvE,MAAM,uBAAuB,OAAO,QAAQ,aAAa,KAAK,OAAO,QAAQ;AAE7E,QAAO,QAAQ,YAAY,SAAS,iBAClC,MACA,QACA,KACM;AACN,oBAAkB,MAAM,QAAQ,IAAI;AACpC,mBAAiB;;AAGnB,QAAO,QAAQ,eAAe,SAAS,oBACrC,MACA,QACA,KACM;AACN,uBAAqB,MAAM,QAAQ,IAAI;AACvC,mBAAiB"}
|
|
1
|
+
{"version":3,"file":"navigation.js","names":["React"],"sources":["../../src/shims/navigation.ts"],"sourcesContent":["/**\n * next/navigation shim\n *\n * App Router navigation hooks. These work on both server (RSC) and client.\n * Server-side: reads from a request context set by the RSC handler.\n * Client-side: reads from browser Location API and provides navigation.\n */\n\n// Use namespace import for RSC safety: the react-server condition doesn't export\n// createContext/useContext/useSyncExternalStore as named exports, and strict ESM\n// would throw at link time for missing bindings. With `import * as React`, the\n// bindings are just `undefined` on the namespace object and we can guard at runtime.\nimport * as React from \"react\";\nimport { notifyAppRouterTransitionStart } from \"../client/instrumentation-client-state.js\";\nimport { toBrowserNavigationHref, toSameOriginAppPath } from \"./url-utils.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport { ReadonlyURLSearchParams } from \"./readonly-url-search-params.js\";\n\n// ─── Layout segment context ───────────────────────────────────────────────────\n// Stores the child segments below the current layout. Each layout wraps its\n// children with a provider whose value is the remaining route tree segments\n// (including route groups, with dynamic params resolved to actual values).\n// Created lazily because `React.createContext` is NOT available in the\n// react-server condition of React. In the RSC environment, this remains null.\n// The shared context lives behind a global singleton so provider/hook pairs\n// still line up if Vite loads this shim through multiple resolved module IDs.\nconst _LAYOUT_SEGMENT_CTX_KEY = Symbol.for(\"vinext.layoutSegmentContext\");\nconst _SERVER_INSERTED_HTML_CTX_KEY = Symbol.for(\"vinext.serverInsertedHTMLContext\");\ntype _LayoutSegmentGlobal = typeof globalThis & {\n [_LAYOUT_SEGMENT_CTX_KEY]?: React.Context<string[]> | null;\n [_SERVER_INSERTED_HTML_CTX_KEY]?: React.Context<\n ((callback: () => unknown) => void) | null\n > | null;\n};\n\n// ─── ServerInsertedHTML context ────────────────────────────────────────────────\n// Used by CSS-in-JS libraries (Apollo Client, styled-components, emotion) to\n// register HTML injection callbacks during SSR via useContext().\n// The SSR entry wraps the rendered tree with a Provider whose value is a\n// callback registration function (useServerInsertedHTML).\n//\n// In Next.js, ServerInsertedHTMLContext holds a function:\n// (callback: () => React.ReactNode) => void\n// Libraries call useContext(ServerInsertedHTMLContext) to get this function,\n// then call it to register callbacks that inject HTML during SSR.\n//\n// Created eagerly at module load time. In the RSC environment (react-server\n// condition), createContext isn't available so this will be null.\n\nfunction getServerInsertedHTMLContext(): React.Context<\n ((callback: () => unknown) => void) | null\n> | null {\n if (typeof React.createContext !== \"function\") return null;\n\n const globalState = globalThis as _LayoutSegmentGlobal;\n if (!globalState[_SERVER_INSERTED_HTML_CTX_KEY]) {\n globalState[_SERVER_INSERTED_HTML_CTX_KEY] = React.createContext<\n ((callback: () => unknown) => void) | null\n >(null);\n }\n\n return globalState[_SERVER_INSERTED_HTML_CTX_KEY] ?? null;\n}\n\nexport const ServerInsertedHTMLContext: React.Context<\n ((callback: () => unknown) => void) | null\n> | null = getServerInsertedHTMLContext();\n\n/**\n * Get or create the layout segment context.\n * Returns null in the RSC environment (createContext unavailable).\n */\nexport function getLayoutSegmentContext(): React.Context<string[]> | null {\n if (typeof React.createContext !== \"function\") return null;\n\n const globalState = globalThis as _LayoutSegmentGlobal;\n if (!globalState[_LAYOUT_SEGMENT_CTX_KEY]) {\n globalState[_LAYOUT_SEGMENT_CTX_KEY] = React.createContext<string[]>([]);\n }\n\n return globalState[_LAYOUT_SEGMENT_CTX_KEY] ?? null;\n}\n\n/**\n * Read the child segments below the current layout from context.\n * Returns [] if no context is available (RSC environment, outside React tree).\n */\nfunction useChildSegments(): string[] {\n const ctx = getLayoutSegmentContext();\n if (!ctx) return [];\n // useContext is safe here because if createContext exists, useContext does too.\n // This branch is only taken in SSR/Browser, never in RSC.\n // Try/catch for unit tests that call this hook outside a React render tree.\n try {\n return React.useContext(ctx);\n } catch {\n return [];\n }\n}\n\n// ---------------------------------------------------------------------------\n// Server-side request context (set by the RSC entry before rendering)\n// ---------------------------------------------------------------------------\n\nexport interface NavigationContext {\n pathname: string;\n searchParams: URLSearchParams;\n params: Record<string, string | string[]>;\n}\n\nconst _READONLY_SEARCH_PARAMS = Symbol(\"vinext.navigation.readonlySearchParams\");\nconst _READONLY_SEARCH_PARAMS_SOURCE = Symbol(\"vinext.navigation.readonlySearchParamsSource\");\n\ntype NavigationContextWithReadonlyCache = NavigationContext & {\n [_READONLY_SEARCH_PARAMS]?: ReadonlyURLSearchParams;\n [_READONLY_SEARCH_PARAMS_SOURCE]?: URLSearchParams;\n};\n\n// ---------------------------------------------------------------------------\n// Server-side navigation state lives in a separate server-only module\n// (navigation-state.ts) that uses AsyncLocalStorage for request isolation.\n// This module is bundled for the browser, so it can't import node:async_hooks.\n//\n// On the server: state functions are set by navigation-state.ts at import time.\n// On the client: _serverContext falls back to null (hooks use window instead).\n//\n// Global accessor pattern (issue #688):\n// Vite's multi-environment dev mode can create separate module instances of\n// this file for the SSR entry vs \"use client\" components. When that happens,\n// _registerStateAccessors only updates the SSR entry's instance, leaving the\n// \"use client\" instance with the default (null) fallbacks.\n//\n// To fix this, navigation-state.ts also stores the accessors on globalThis\n// via Symbol.for, and the defaults here check for that global before falling\n// back to module-level state. This ensures all module instances can reach the\n// ALS-backed state regardless of which instance was registered.\n// ---------------------------------------------------------------------------\n\ninterface _StateAccessors {\n getServerContext: () => NavigationContext | null;\n setServerContext: (ctx: NavigationContext | null) => void;\n getInsertedHTMLCallbacks: () => Array<() => unknown>;\n clearInsertedHTMLCallbacks: () => void;\n}\n\nexport const GLOBAL_ACCESSORS_KEY = Symbol.for(\"vinext.navigation.globalAccessors\");\nconst _GLOBAL_ACCESSORS_KEY = GLOBAL_ACCESSORS_KEY;\ntype _GlobalWithAccessors = typeof globalThis & { [_GLOBAL_ACCESSORS_KEY]?: _StateAccessors };\n\nfunction _getGlobalAccessors(): _StateAccessors | undefined {\n return (globalThis as _GlobalWithAccessors)[_GLOBAL_ACCESSORS_KEY];\n}\n\nlet _serverContext: NavigationContext | null = null;\nlet _serverInsertedHTMLCallbacks: Array<() => unknown> = [];\n\n// These are overridden by navigation-state.ts on the server to use ALS.\n// The defaults check globalThis for cross-module-instance access (issue #688).\nlet _getServerContext = (): NavigationContext | null => {\n const g = _getGlobalAccessors();\n return g ? g.getServerContext() : _serverContext;\n};\nlet _setServerContext = (ctx: NavigationContext | null): void => {\n const g = _getGlobalAccessors();\n if (g) {\n g.setServerContext(ctx);\n } else {\n _serverContext = ctx;\n }\n};\nlet _getInsertedHTMLCallbacks = (): Array<() => unknown> => {\n const g = _getGlobalAccessors();\n return g ? g.getInsertedHTMLCallbacks() : _serverInsertedHTMLCallbacks;\n};\nlet _clearInsertedHTMLCallbacks = (): void => {\n const g = _getGlobalAccessors();\n if (g) {\n g.clearInsertedHTMLCallbacks();\n } else {\n _serverInsertedHTMLCallbacks = [];\n }\n};\n\n/**\n * Register ALS-backed state accessors. Called by navigation-state.ts on import.\n * @internal\n */\nexport function _registerStateAccessors(accessors: _StateAccessors): void {\n _getServerContext = accessors.getServerContext;\n _setServerContext = accessors.setServerContext;\n _getInsertedHTMLCallbacks = accessors.getInsertedHTMLCallbacks;\n _clearInsertedHTMLCallbacks = accessors.clearInsertedHTMLCallbacks;\n}\n\n/**\n * Get the navigation context for the current SSR/RSC render.\n * Reads from AsyncLocalStorage when available (concurrent-safe),\n * otherwise falls back to module-level state.\n */\nexport function getNavigationContext(): NavigationContext | null {\n return _getServerContext();\n}\n\n/**\n * Set the navigation context for the current SSR/RSC render.\n * Called by the framework entry before rendering each request.\n */\nexport function setNavigationContext(ctx: NavigationContext | null): void {\n _setServerContext(ctx);\n}\n\n// ---------------------------------------------------------------------------\n// Client-side state\n// ---------------------------------------------------------------------------\n\nconst isServer = typeof window === \"undefined\";\n\n/** basePath from next.config.js, injected by the plugin at build time */\nconst __basePath: string = process.env.__NEXT_ROUTER_BASEPATH ?? \"\";\n\n// ---------------------------------------------------------------------------\n// RSC prefetch cache utilities (shared between link.tsx and browser entry)\n// ---------------------------------------------------------------------------\n\n/** Maximum number of entries in the RSC prefetch cache. */\nexport const MAX_PREFETCH_CACHE_SIZE = 50;\n\n/** TTL for prefetch cache entries in ms (matches Next.js static prefetch TTL). */\nexport const PREFETCH_CACHE_TTL = 30_000;\n\nexport interface PrefetchCacheEntry {\n response: Response;\n timestamp: number;\n}\n\n/**\n * Convert a pathname (with optional query/hash) to its .rsc URL.\n * Strips trailing slashes before appending `.rsc` so that cache keys\n * are consistent regardless of the `trailingSlash` config setting.\n */\nexport function toRscUrl(href: string): string {\n const [beforeHash] = href.split(\"#\");\n const qIdx = beforeHash.indexOf(\"?\");\n const pathname = qIdx === -1 ? beforeHash : beforeHash.slice(0, qIdx);\n const query = qIdx === -1 ? \"\" : beforeHash.slice(qIdx);\n // Strip trailing slash (but preserve \"/\" root) for consistent cache keys\n const normalizedPath =\n pathname.length > 1 && pathname.endsWith(\"/\") ? pathname.slice(0, -1) : pathname;\n return normalizedPath + \".rsc\" + query;\n}\n\n/** Get or create the shared in-memory RSC prefetch cache on window. */\nexport function getPrefetchCache(): Map<string, PrefetchCacheEntry> {\n if (isServer) return new Map();\n if (!window.__VINEXT_RSC_PREFETCH_CACHE__) {\n window.__VINEXT_RSC_PREFETCH_CACHE__ = new Map<string, PrefetchCacheEntry>();\n }\n return window.__VINEXT_RSC_PREFETCH_CACHE__;\n}\n\n/**\n * Get or create the shared set of already-prefetched RSC URLs on window.\n * Keyed by rscUrl so that the browser entry can clear entries when consumed.\n */\nexport function getPrefetchedUrls(): Set<string> {\n if (isServer) return new Set();\n if (!window.__VINEXT_RSC_PREFETCHED_URLS__) {\n window.__VINEXT_RSC_PREFETCHED_URLS__ = new Set<string>();\n }\n return window.__VINEXT_RSC_PREFETCHED_URLS__;\n}\n\n/**\n * Store a prefetched RSC response in the cache.\n * Enforces a maximum cache size to prevent unbounded memory growth on\n * link-heavy pages.\n */\nexport function storePrefetchResponse(rscUrl: string, response: Response): void {\n const cache = getPrefetchCache();\n const now = Date.now();\n\n // Sweep expired entries before resorting to FIFO eviction\n if (cache.size >= MAX_PREFETCH_CACHE_SIZE) {\n const prefetched = getPrefetchedUrls();\n for (const [key, entry] of cache) {\n if (now - entry.timestamp >= PREFETCH_CACHE_TTL) {\n cache.delete(key);\n prefetched.delete(key);\n }\n }\n }\n\n // FIFO fallback if still at capacity after sweep\n if (cache.size >= MAX_PREFETCH_CACHE_SIZE) {\n const oldest = cache.keys().next().value;\n if (oldest !== undefined) {\n cache.delete(oldest);\n getPrefetchedUrls().delete(oldest);\n }\n }\n\n cache.set(rscUrl, { response, timestamp: now });\n}\n\n// Client navigation listeners\ntype NavigationListener = () => void;\nconst _listeners: Set<NavigationListener> = new Set();\n\nfunction notifyListeners(): void {\n for (const fn of _listeners) fn();\n}\n\n// Cached URLSearchParams, pathname, etc. for referential stability\n// useSyncExternalStore compares snapshots with Object.is — avoid creating\n// new instances on every render (infinite re-renders).\nlet _cachedSearch = !isServer ? window.location.search : \"\";\nlet _cachedReadonlySearchParams = new ReadonlyURLSearchParams(_cachedSearch);\nlet _cachedEmptyServerSearchParams: ReadonlyURLSearchParams | null = null;\nlet _cachedPathname = !isServer ? stripBasePath(window.location.pathname, __basePath) : \"/\";\n\nfunction getPathnameSnapshot(): string {\n const current = stripBasePath(window.location.pathname, __basePath);\n if (current !== _cachedPathname) {\n _cachedPathname = current;\n }\n return _cachedPathname;\n}\n\nfunction getSearchParamsSnapshot(): ReadonlyURLSearchParams {\n const current = window.location.search;\n if (current !== _cachedSearch) {\n _cachedSearch = current;\n _cachedReadonlySearchParams = new ReadonlyURLSearchParams(current);\n }\n return _cachedReadonlySearchParams;\n}\n\nfunction getServerSearchParamsSnapshot(): ReadonlyURLSearchParams {\n const ctx = _getServerContext() as NavigationContextWithReadonlyCache | null;\n if (ctx != null) {\n const searchParams = ctx.searchParams;\n if (ctx[_READONLY_SEARCH_PARAMS_SOURCE] !== searchParams) {\n ctx[_READONLY_SEARCH_PARAMS_SOURCE] = searchParams;\n ctx[_READONLY_SEARCH_PARAMS] = new ReadonlyURLSearchParams(searchParams);\n }\n return ctx[_READONLY_SEARCH_PARAMS]!;\n }\n if (_cachedEmptyServerSearchParams === null) {\n _cachedEmptyServerSearchParams = new ReadonlyURLSearchParams();\n }\n return _cachedEmptyServerSearchParams;\n}\n\n// Track client-side params (set during RSC hydration/navigation)\n// We cache the params object for referential stability — only create a new\n// object when the params actually change (shallow key/value comparison).\nconst _EMPTY_PARAMS: Record<string, string | string[]> = {};\nlet _clientParams: Record<string, string | string[]> = _EMPTY_PARAMS;\nlet _clientParamsJson = \"{}\";\n\nexport function setClientParams(params: Record<string, string | string[]>): void {\n const json = JSON.stringify(params);\n if (json !== _clientParamsJson) {\n _clientParams = params;\n _clientParamsJson = json;\n // Notify useSyncExternalStore subscribers so useParams() re-renders.\n notifyListeners();\n }\n}\n\n/** Get the current client params (for testing referential stability). */\nexport function getClientParams(): Record<string, string | string[]> {\n return _clientParams;\n}\n\nfunction getClientParamsSnapshot(): Record<string, string | string[]> {\n return _clientParams;\n}\n\nfunction getServerParamsSnapshot(): Record<string, string | string[]> {\n return _getServerContext()?.params ?? _EMPTY_PARAMS;\n}\n\nfunction subscribeToNavigation(cb: () => void): () => void {\n _listeners.add(cb);\n return () => {\n _listeners.delete(cb);\n };\n}\n\n// ---------------------------------------------------------------------------\n// Hooks\n// ---------------------------------------------------------------------------\n\n/**\n * Returns the current pathname.\n * Server: from request context. Client: from window.location.\n */\nexport function usePathname(): string {\n if (isServer) {\n // During SSR of \"use client\" components, the navigation context may not be set.\n // Return a safe fallback — the client will hydrate with the real value.\n return _getServerContext()?.pathname ?? \"/\";\n }\n // Client-side: use the hook system for reactivity\n return React.useSyncExternalStore(\n subscribeToNavigation,\n getPathnameSnapshot,\n () => _getServerContext()?.pathname ?? \"/\",\n );\n}\n\n/**\n * Returns the current search params as a read-only URLSearchParams.\n */\nexport function useSearchParams(): ReadonlyURLSearchParams {\n if (isServer) {\n // During SSR of \"use client\" components, the navigation context may not be set.\n // Return a safe fallback — the client will hydrate with the real value.\n return getServerSearchParamsSnapshot();\n }\n return React.useSyncExternalStore(\n subscribeToNavigation,\n getSearchParamsSnapshot,\n getServerSearchParamsSnapshot,\n );\n}\n\n/**\n * Returns the dynamic params for the current route.\n */\nexport function useParams<\n T extends Record<string, string | string[]> = Record<string, string | string[]>,\n>(): T {\n if (isServer) {\n // During SSR of \"use client\" components, the navigation context may not be set.\n return (_getServerContext()?.params ?? _EMPTY_PARAMS) as T;\n }\n return React.useSyncExternalStore(\n subscribeToNavigation,\n getClientParamsSnapshot as () => T,\n getServerParamsSnapshot as () => T,\n );\n}\n\n/**\n * Check if a href is an external URL (any URL scheme per RFC 3986, or protocol-relative).\n */\nfunction isExternalUrl(href: string): boolean {\n return /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith(\"//\");\n}\n\n/**\n * Check if a href is only a hash change relative to the current URL.\n */\nfunction isHashOnlyChange(href: string): boolean {\n if (typeof window === \"undefined\") return false;\n if (href.startsWith(\"#\")) return true;\n try {\n const current = new URL(window.location.href);\n const next = new URL(href, window.location.href);\n return current.pathname === next.pathname && current.search === next.search && next.hash !== \"\";\n } catch {\n return false;\n }\n}\n\n/**\n * Scroll to a hash target element, or to the top if no hash.\n */\nfunction scrollToHash(hash: string): void {\n if (!hash || hash === \"#\") {\n window.scrollTo(0, 0);\n return;\n }\n const id = hash.slice(1);\n const element = document.getElementById(id);\n if (element) {\n element.scrollIntoView({ behavior: \"auto\" });\n }\n}\n\n/**\n * Reference to the native history.replaceState before patching.\n * Used internally to avoid triggering the interception for internal operations\n * (e.g. saving scroll position shouldn't cause re-renders).\n * Captured before the history method patching at the bottom of this module.\n */\nconst _nativeReplaceState: typeof window.history.replaceState | null = !isServer\n ? window.history.replaceState.bind(window.history)\n : null;\n\n/**\n * Save the current scroll position into the current history state.\n * Called before every navigation to enable scroll restoration on back/forward.\n *\n * Uses _nativeReplaceState to avoid triggering the history.replaceState\n * interception (which would cause spurious re-renders from notifyListeners).\n */\nfunction saveScrollPosition(): void {\n if (!_nativeReplaceState) return;\n const state = window.history.state ?? {};\n _nativeReplaceState.call(\n window.history,\n { ...state, __vinext_scrollX: window.scrollX, __vinext_scrollY: window.scrollY },\n \"\",\n );\n}\n\n/**\n * Restore scroll position from a history state object (used on popstate).\n *\n * When an RSC navigation is in flight (back/forward triggers both this\n * handler and the browser entry's popstate handler which calls\n * __VINEXT_RSC_NAVIGATE__), we must wait for the new content to render\n * before scrolling. Otherwise the user sees old content flash at the\n * restored scroll position.\n *\n * This handler fires before the browser entry's popstate handler (because\n * navigation.ts is loaded before hydration completes), so we defer via a\n * microtask to give the browser entry handler a chance to set\n * __VINEXT_RSC_PENDING__ first.\n */\nfunction restoreScrollPosition(state: unknown): void {\n if (state && typeof state === \"object\" && \"__vinext_scrollY\" in state) {\n const { __vinext_scrollX: x, __vinext_scrollY: y } = state as {\n __vinext_scrollX: number;\n __vinext_scrollY: number;\n };\n\n // Defer to allow other popstate listeners (browser entry) to run first\n // and set __VINEXT_RSC_PENDING__. Promise.resolve() schedules a microtask\n // that runs after all synchronous event listeners have completed.\n void Promise.resolve().then(() => {\n const pending: Promise<void> | null = window.__VINEXT_RSC_PENDING__ ?? null;\n\n if (pending) {\n // Wait for the RSC navigation to finish rendering, then scroll.\n void pending.then(() => {\n requestAnimationFrame(() => {\n window.scrollTo(x, y);\n });\n });\n } else {\n // No RSC navigation in flight (Pages Router or already settled).\n requestAnimationFrame(() => {\n window.scrollTo(x, y);\n });\n }\n });\n }\n}\n\n/**\n * Navigate to a URL, handling external URLs, hash-only changes, and RSC navigation.\n */\nasync function navigateImpl(\n href: string,\n mode: \"push\" | \"replace\",\n scroll: boolean,\n): Promise<void> {\n // Normalize same-origin absolute URLs to local paths for SPA navigation\n let normalizedHref = href;\n if (isExternalUrl(href)) {\n const localPath = toSameOriginAppPath(href, __basePath);\n if (localPath == null) {\n // Truly external: use full page navigation\n if (mode === \"replace\") {\n window.location.replace(href);\n } else {\n window.location.assign(href);\n }\n return;\n }\n normalizedHref = localPath;\n }\n\n const fullHref = toBrowserNavigationHref(normalizedHref, window.location.href, __basePath);\n // Match Next.js: App Router reports navigation start before dispatching,\n // including hash-only navigations that short-circuit after URL update.\n notifyAppRouterTransitionStart(fullHref, mode);\n\n // Save scroll position before navigating (for back/forward restoration)\n if (mode === \"push\") {\n saveScrollPosition();\n }\n\n // Hash-only change: update URL and scroll to target, skip RSC fetch\n if (isHashOnlyChange(fullHref)) {\n const hash = fullHref.includes(\"#\") ? fullHref.slice(fullHref.indexOf(\"#\")) : \"\";\n if (mode === \"replace\") {\n window.history.replaceState(null, \"\", fullHref);\n } else {\n window.history.pushState(null, \"\", fullHref);\n }\n notifyListeners();\n if (scroll) {\n scrollToHash(hash);\n }\n return;\n }\n\n // Extract hash for post-navigation scrolling\n const hashIdx = fullHref.indexOf(\"#\");\n const hash = hashIdx !== -1 ? fullHref.slice(hashIdx) : \"\";\n\n if (mode === \"replace\") {\n window.history.replaceState(null, \"\", fullHref);\n } else {\n window.history.pushState(null, \"\", fullHref);\n }\n notifyListeners();\n\n // Trigger RSC re-fetch if available, and wait for the new content to render\n // before scrolling. This prevents the old page from visibly jumping to the\n // top before the new content paints.\n if (typeof window.__VINEXT_RSC_NAVIGATE__ === \"function\") {\n await window.__VINEXT_RSC_NAVIGATE__(fullHref);\n }\n\n if (scroll) {\n if (hash) {\n scrollToHash(hash);\n } else {\n window.scrollTo(0, 0);\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// App Router router singleton\n//\n// All methods close over module-level state (navigateImpl, withBasePath, etc.)\n// and carry no per-render data, so the object can be created once and reused.\n// Next.js returns the same router reference on every call to useRouter(), which\n// matters for components that rely on referential equality (e.g. useMemo /\n// useEffect dependency arrays, React.memo bailouts).\n// ---------------------------------------------------------------------------\n\nconst _appRouter = {\n push(href: string, options?: { scroll?: boolean }): void {\n if (isServer) return;\n void navigateImpl(href, \"push\", options?.scroll !== false);\n },\n replace(href: string, options?: { scroll?: boolean }): void {\n if (isServer) return;\n void navigateImpl(href, \"replace\", options?.scroll !== false);\n },\n back(): void {\n if (isServer) return;\n window.history.back();\n },\n forward(): void {\n if (isServer) return;\n window.history.forward();\n },\n refresh(): void {\n if (isServer) return;\n // Re-fetch the current page's RSC stream\n if (typeof window.__VINEXT_RSC_NAVIGATE__ === \"function\") {\n void window.__VINEXT_RSC_NAVIGATE__(window.location.href);\n }\n },\n prefetch(href: string): void {\n if (isServer) return;\n // Prefetch the RSC payload for the target route and store in cache\n const fullHref = toBrowserNavigationHref(href, window.location.href, __basePath);\n const rscUrl = toRscUrl(fullHref);\n const prefetched = getPrefetchedUrls();\n if (prefetched.has(rscUrl)) return;\n prefetched.add(rscUrl);\n fetch(rscUrl, {\n headers: { Accept: \"text/x-component\" },\n credentials: \"include\",\n priority: \"low\" as RequestInit[\"priority\"],\n })\n .then((response) => {\n if (response.ok) {\n storePrefetchResponse(rscUrl, response);\n } else {\n // Non-ok response: allow retry on next prefetch() call\n prefetched.delete(rscUrl);\n }\n })\n .catch(() => {\n // Network error: allow retry on next prefetch() call\n prefetched.delete(rscUrl);\n });\n },\n};\n\n/**\n * App Router's useRouter — returns push/replace/back/forward/refresh.\n * Different from Pages Router's useRouter (next/router).\n *\n * Returns a stable singleton: the same object reference on every call,\n * matching Next.js behavior so components using referential equality\n * (e.g. useMemo / useEffect deps, React.memo) don't re-render unnecessarily.\n */\nexport function useRouter() {\n return _appRouter;\n}\n\n/**\n * Returns the active child segment one level below the layout where it's called.\n *\n * Returns the first segment from the route tree below this layout, including\n * route groups (e.g., \"(marketing)\") and resolved dynamic params. Returns null\n * if at the leaf (no child segments).\n *\n * @param parallelRoutesKey - Which parallel route to read (default: \"children\")\n */\nexport function useSelectedLayoutSegment(\n // parallelRoutesKey is accepted for API compat but not yet supported —\n // vinext doesn't implement parallel routes with separate segment tracking.\n _parallelRoutesKey?: string,\n): string | null {\n const segments = useSelectedLayoutSegments(_parallelRoutesKey);\n return segments.length > 0 ? segments[0] : null;\n}\n\n/**\n * Returns all active segments below the layout where it's called.\n *\n * Each layout in the App Router tree wraps its children with a\n * LayoutSegmentProvider whose value is the remaining route tree segments\n * (including route groups, with dynamic params resolved to actual values\n * and catch-all segments joined with \"/\"). This hook reads those segments\n * directly from context.\n *\n * @param parallelRoutesKey - Which parallel route to read (default: \"children\")\n */\nexport function useSelectedLayoutSegments(\n // parallelRoutesKey is accepted for API compat but not yet supported —\n // vinext doesn't implement parallel routes with separate segment tracking.\n _parallelRoutesKey?: string,\n): string[] {\n return useChildSegments();\n}\n\nexport { ReadonlyURLSearchParams };\n\n/**\n * useServerInsertedHTML — inject HTML during SSR from client components.\n *\n * Used by CSS-in-JS libraries (styled-components, emotion, StyleX) to inject\n * <style> tags during SSR so styles appear in the initial HTML (no FOUC).\n *\n * The callback is called once after each SSR render pass. The returned JSX/HTML\n * is serialized and injected into the HTML stream.\n *\n * Usage (in a \"use client\" component wrapping children):\n * useServerInsertedHTML(() => {\n * const styles = sheet.getStyleElement();\n * sheet.instance.clearTag();\n * return <>{styles}</>;\n * });\n */\n\nexport function useServerInsertedHTML(callback: () => unknown): void {\n if (typeof document !== \"undefined\") {\n // Client-side: no-op (styles are already in the DOM)\n return;\n }\n _getInsertedHTMLCallbacks().push(callback);\n}\n\n/**\n * Flush all collected useServerInsertedHTML callbacks.\n * Returns an array of results (React elements or strings).\n * Clears the callback list so the next render starts fresh.\n *\n * Called by the SSR entry after renderToReadableStream completes.\n */\nexport function flushServerInsertedHTML(): unknown[] {\n const callbacks = _getInsertedHTMLCallbacks();\n const results: unknown[] = [];\n for (const cb of callbacks) {\n try {\n const result = cb();\n if (result != null) results.push(result);\n } catch {\n // Ignore errors from individual callbacks\n }\n }\n callbacks.length = 0;\n return results;\n}\n\n/**\n * Clear all collected useServerInsertedHTML callbacks without flushing.\n * Used for cleanup between requests.\n */\nexport function clearServerInsertedHTML(): void {\n _clearInsertedHTMLCallbacks();\n}\n\n// ---------------------------------------------------------------------------\n// Non-hook utilities (can be called from Server Components)\n// ---------------------------------------------------------------------------\n\n/**\n * HTTP Access Fallback error code — shared prefix for notFound/forbidden/unauthorized.\n * Matches Next.js 16's unified error handling approach.\n */\nexport const HTTP_ERROR_FALLBACK_ERROR_CODE = \"NEXT_HTTP_ERROR_FALLBACK\";\n\n/**\n * Check if an error is an HTTP Access Fallback error (notFound, forbidden, unauthorized).\n */\nexport function isHTTPAccessFallbackError(error: unknown): boolean {\n if (error && typeof error === \"object\" && \"digest\" in error) {\n const digest = String((error as { digest: unknown }).digest);\n return (\n digest === \"NEXT_NOT_FOUND\" || // legacy compat\n digest.startsWith(`${HTTP_ERROR_FALLBACK_ERROR_CODE};`)\n );\n }\n return false;\n}\n\n/**\n * Extract the HTTP status code from an HTTP Access Fallback error.\n * Returns 404 for legacy NEXT_NOT_FOUND errors.\n */\nexport function getAccessFallbackHTTPStatus(error: unknown): number {\n if (error && typeof error === \"object\" && \"digest\" in error) {\n const digest = String((error as { digest: unknown }).digest);\n if (digest === \"NEXT_NOT_FOUND\") return 404;\n if (digest.startsWith(`${HTTP_ERROR_FALLBACK_ERROR_CODE};`)) {\n return parseInt(digest.split(\";\")[1], 10);\n }\n }\n return 404;\n}\n\n/**\n * Enum matching Next.js RedirectType for type-safe redirect calls.\n */\nexport enum RedirectType {\n push = \"push\",\n replace = \"replace\",\n}\n\n/**\n * Internal error class used by redirect/notFound/forbidden/unauthorized.\n * The `digest` field is the serialised control-flow signal read by the\n * framework's error boundary and server-side request handlers.\n */\nclass VinextNavigationError extends Error {\n readonly digest: string;\n constructor(message: string, digest: string) {\n super(message);\n this.digest = digest;\n }\n}\n\n/**\n * Throw a redirect. Caught by the framework to send a redirect response.\n */\nexport function redirect(url: string, type?: \"replace\" | \"push\" | RedirectType): never {\n throw new VinextNavigationError(\n `NEXT_REDIRECT:${url}`,\n `NEXT_REDIRECT;${type ?? \"replace\"};${encodeURIComponent(url)}`,\n );\n}\n\n/**\n * Trigger a permanent redirect (308).\n */\nexport function permanentRedirect(url: string): never {\n throw new VinextNavigationError(\n `NEXT_REDIRECT:${url}`,\n `NEXT_REDIRECT;replace;${encodeURIComponent(url)};308`,\n );\n}\n\n/**\n * Trigger a not-found response (404). Caught by the framework.\n */\nexport function notFound(): never {\n throw new VinextNavigationError(\"NEXT_NOT_FOUND\", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);\n}\n\n/**\n * Trigger a forbidden response (403). Caught by the framework.\n * In Next.js, this is gated behind experimental.authInterrupts — we\n * support it unconditionally for maximum compatibility.\n */\nexport function forbidden(): never {\n throw new VinextNavigationError(\"NEXT_FORBIDDEN\", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);\n}\n\n/**\n * Trigger an unauthorized response (401). Caught by the framework.\n * In Next.js, this is gated behind experimental.authInterrupts — we\n * support it unconditionally for maximum compatibility.\n */\nexport function unauthorized(): never {\n throw new VinextNavigationError(\"NEXT_UNAUTHORIZED\", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n// React hooks are imported at the top level via ESM.\n\n// Listen for popstate on the client\nif (!isServer) {\n window.addEventListener(\"popstate\", (event) => {\n notifyListeners();\n // Restore scroll position for back/forward navigation\n restoreScrollPosition(event.state);\n });\n\n // ---------------------------------------------------------------------------\n // history.pushState / replaceState interception (shallow routing)\n //\n // Next.js intercepts these native methods so that when user code calls\n // `window.history.pushState(null, '', '/new-path?filter=abc')` directly,\n // React hooks like usePathname() and useSearchParams() re-render with\n // the new URL. This is the foundation for shallow routing patterns\n // (filter UIs, tabs, URL search param state, etc.).\n //\n // We wrap the original methods, call through to the native implementation,\n // then notify our listener system so useSyncExternalStore picks up the\n // URL change.\n // ---------------------------------------------------------------------------\n const originalPushState = window.history.pushState.bind(window.history);\n const originalReplaceState = window.history.replaceState.bind(window.history);\n\n window.history.pushState = function patchedPushState(\n data: unknown,\n unused: string,\n url?: string | URL | null,\n ): void {\n originalPushState(data, unused, url);\n notifyListeners();\n };\n\n window.history.replaceState = function patchedReplaceState(\n data: unknown,\n unused: string,\n url?: string | URL | null,\n ): void {\n originalReplaceState(data, unused, url);\n notifyListeners();\n };\n}\n"],"mappings":";;;;;;;;;;;;;AA0BA,MAAM,0BAA0B,OAAO,IAAI,8BAA8B;AACzE,MAAM,gCAAgC,OAAO,IAAI,mCAAmC;AAsBpF,SAAS,+BAEA;AACP,KAAI,OAAOA,QAAM,kBAAkB,WAAY,QAAO;CAEtD,MAAM,cAAc;AACpB,KAAI,CAAC,YAAY,+BACf,aAAY,iCAAiCA,QAAM,cAEjD,KAAK;AAGT,QAAO,YAAY,kCAAkC;;AAGvD,MAAa,4BAEF,8BAA8B;;;;;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,CAAC,MAClD;;;;;AAMH,SAAgB,WAAkB;AAChC,OAAM,IAAI,sBAAsB,kBAAkB,GAAG,+BAA+B,MAAM;;;;;;;AAQ5F,SAAgB,YAAmB;AACjC,OAAM,IAAI,sBAAsB,kBAAkB,GAAG,+BAA+B,MAAM;;;;;;;AAQ5F,SAAgB,eAAsB;AACpC,OAAM,IAAI,sBAAsB,qBAAqB,GAAG,+BAA+B,MAAM;;AAU/F,IAAI,CAAC,UAAU;AACb,QAAO,iBAAiB,aAAa,UAAU;AAC7C,mBAAiB;AAEjB,wBAAsB,MAAM,MAAM;GAClC;CAeF,MAAM,oBAAoB,OAAO,QAAQ,UAAU,KAAK,OAAO,QAAQ;CACvE,MAAM,uBAAuB,OAAO,QAAQ,aAAa,KAAK,OAAO,QAAQ;AAE7E,QAAO,QAAQ,YAAY,SAAS,iBAClC,MACA,QACA,KACM;AACN,oBAAkB,MAAM,QAAQ,IAAI;AACpC,mBAAiB;;AAGnB,QAAO,QAAQ,eAAe,SAAS,oBACrC,MACA,QACA,KACM;AACN,uBAAqB,MAAM,QAAQ,IAAI;AACvC,mBAAiB"}
|
package/dist/shims/server.d.ts
CHANGED
|
@@ -191,6 +191,7 @@ declare class NextFetchEvent {
|
|
|
191
191
|
page: string;
|
|
192
192
|
});
|
|
193
193
|
waitUntil(promise: Promise<unknown>): void;
|
|
194
|
+
get waitUntilPromises(): Promise<unknown>[];
|
|
194
195
|
/** Drain all waitUntil promises. Returns a single promise that settles when all are done. */
|
|
195
196
|
drainWaitUntil(): Promise<PromiseSettledResult<unknown>[]>;
|
|
196
197
|
}
|
package/dist/shims/server.js
CHANGED
|
@@ -498,6 +498,9 @@ var NextFetchEvent = class {
|
|
|
498
498
|
waitUntil(promise) {
|
|
499
499
|
this._waitUntilPromises.push(promise);
|
|
500
500
|
}
|
|
501
|
+
get waitUntilPromises() {
|
|
502
|
+
return this._waitUntilPromises;
|
|
503
|
+
}
|
|
501
504
|
/** Drain all waitUntil promises. Returns a single promise that settles when all are done. */
|
|
502
505
|
drainWaitUntil() {
|
|
503
506
|
return Promise.allSettled(this._waitUntilPromises);
|
package/dist/shims/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":[],"sources":["../../src/shims/server.ts"],"sourcesContent":["/**\n * next/server shim\n *\n * Provides NextRequest, NextResponse, and related types that work with\n * standard Web APIs (Request/Response). This means they work on Node,\n * Cloudflare Workers, Deno, and any WinterCG-compatible runtime.\n *\n * This is a pragmatic subset — we implement the most commonly used APIs\n * rather than bug-for-bug parity with Next.js internals.\n */\n\nimport { encodeMiddlewareRequestHeaders } from \"../server/middleware-request-headers.js\";\nimport { parseCookieHeader } from \"./internal/parse-cookie-header.js\";\nimport { getRequestExecutionContext } from \"./request-context.js\";\n\n// ---------------------------------------------------------------------------\n// Inlined cache-scope guard for after()\n//\n// We cannot statically import throwIfInsideCacheScope from headers.ts here\n// because headers.ts contains the \"use cache\" directive string in its error\n// message, which causes Vite's use-cache transform to include it in the module\n// graph. If headers.ts is pulled in via static import from server.ts, the\n// transform fires on it in Pages Router fixtures that lack @vitejs/plugin-rsc.\n//\n// The connection() function in this file avoids the same problem by using\n// `await import(\"./headers.js\")` (dynamic import, async function). after()\n// must remain synchronous, so we inline the check using the same Symbol.for\n// keys that cache-runtime.ts and cache.ts register their ALS instances with.\n// ---------------------------------------------------------------------------\n\nconst _USE_CACHE_ALS_KEY = Symbol.for(\"vinext.cacheRuntime.contextAls\");\nconst _UNSTABLE_CACHE_ALS_KEY = Symbol.for(\"vinext.unstableCache.als\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\n\nfunction _throwIfInsideCacheScope(apiName: string): void {\n const cacheAls = _g[_USE_CACHE_ALS_KEY] as { getStore(): unknown } | undefined;\n if (cacheAls?.getStore() != null) {\n throw new Error(\n `\\`${apiName}\\` cannot be called inside \"use cache\". ` +\n `If you need this data inside a cached function, call \\`${apiName}\\` ` +\n \"outside and pass the required data as an argument.\",\n );\n }\n const unstableAls = _g[_UNSTABLE_CACHE_ALS_KEY] as { getStore(): unknown } | undefined;\n if (unstableAls?.getStore() === true) {\n throw new Error(\n `\\`${apiName}\\` cannot be called inside a function cached with \\`unstable_cache()\\`. ` +\n `If you need this data inside a cached function, call \\`${apiName}\\` ` +\n \"outside and pass the required data as an argument.\",\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextRequest\n// ---------------------------------------------------------------------------\n\nexport class NextRequest extends Request {\n private _nextUrl: NextURL;\n private _cookies: RequestCookies;\n\n constructor(\n input: URL | RequestInfo,\n init?: RequestInit & {\n nextConfig?: {\n basePath?: string;\n i18n?: { locales: string[]; defaultLocale: string };\n };\n },\n ) {\n // Strip nextConfig before passing to super() — it's vinext-internal,\n // not a valid RequestInit property.\n const { nextConfig: _nextConfig, ...requestInit } = init ?? {};\n // Handle the case where input is a Request object - we need to extract URL and init\n // to avoid Node.js undici issues with passing Request objects directly to super()\n if (input instanceof Request) {\n const req = input;\n super(req.url, {\n method: req.method,\n headers: req.headers,\n body: req.body,\n // @ts-expect-error - duplex is not in RequestInit type but needed for streams\n duplex: req.body ? \"half\" : undefined,\n ...requestInit,\n });\n } else {\n super(input, requestInit);\n }\n const url =\n typeof input === \"string\"\n ? new URL(input, \"http://localhost\")\n : input instanceof URL\n ? input\n : new URL(input.url, \"http://localhost\");\n const urlConfig: NextURLConfig | undefined = _nextConfig\n ? { basePath: _nextConfig.basePath, nextConfig: { i18n: _nextConfig.i18n } }\n : undefined;\n this._nextUrl = new NextURL(url, undefined, urlConfig);\n this._cookies = new RequestCookies(this.headers);\n }\n\n get nextUrl(): NextURL {\n return this._nextUrl;\n }\n\n get cookies(): RequestCookies {\n return this._cookies;\n }\n\n /**\n * Client IP address. Prefers Cloudflare's trusted CF-Connecting-IP header\n * over the spoofable X-Forwarded-For. Returns undefined if unavailable.\n */\n get ip(): string | undefined {\n return (\n this.headers.get(\"cf-connecting-ip\") ??\n this.headers.get(\"x-real-ip\") ??\n this.headers.get(\"x-forwarded-for\")?.split(\",\")[0]?.trim() ??\n undefined\n );\n }\n\n /**\n * Geolocation data. Platform-dependent (e.g., Cloudflare, Vercel).\n * Returns undefined if not available.\n */\n get geo():\n | { city?: string; country?: string; region?: string; latitude?: string; longitude?: string }\n | undefined {\n // Check Cloudflare-style headers, Vercel-style headers\n const country =\n this.headers.get(\"cf-ipcountry\") ?? this.headers.get(\"x-vercel-ip-country\") ?? undefined;\n if (!country) return undefined;\n return {\n country,\n city: this.headers.get(\"cf-ipcity\") ?? this.headers.get(\"x-vercel-ip-city\") ?? undefined,\n region:\n this.headers.get(\"cf-region\") ??\n this.headers.get(\"x-vercel-ip-country-region\") ??\n undefined,\n latitude:\n this.headers.get(\"cf-iplatitude\") ?? this.headers.get(\"x-vercel-ip-latitude\") ?? undefined,\n longitude:\n this.headers.get(\"cf-iplongitude\") ??\n this.headers.get(\"x-vercel-ip-longitude\") ??\n undefined,\n };\n }\n\n /**\n * The build ID of the Next.js application.\n * Delegates to `nextUrl.buildId` to match Next.js API surface.\n * Can be used in middleware to detect deployment skew between client and server.\n */\n get buildId(): string | undefined {\n return this._nextUrl.buildId;\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextResponse\n// ---------------------------------------------------------------------------\n\nexport class NextResponse<_Body = unknown> extends Response {\n private _cookies: ResponseCookies;\n\n constructor(body?: BodyInit | null, init?: ResponseInit) {\n super(body, init);\n this._cookies = new ResponseCookies(this.headers);\n }\n\n get cookies(): ResponseCookies {\n return this._cookies;\n }\n\n /**\n * Create a JSON response.\n */\n static json<JsonBody>(body: JsonBody, init?: ResponseInit): NextResponse<JsonBody> {\n const headers = new Headers(init?.headers);\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n return new NextResponse(JSON.stringify(body), {\n ...init,\n headers,\n }) as NextResponse<JsonBody>;\n }\n\n /**\n * Create a redirect response.\n */\n static redirect(url: string | URL, init?: number | ResponseInit): NextResponse {\n const status = typeof init === \"number\" ? init : (init?.status ?? 307);\n const destination = typeof url === \"string\" ? url : url.toString();\n const headers = new Headers(typeof init === \"object\" ? init?.headers : undefined);\n headers.set(\"Location\", destination);\n return new NextResponse(null, { status, headers });\n }\n\n /**\n * Create a rewrite response (middleware pattern).\n * Sets the x-middleware-rewrite header.\n */\n static rewrite(destination: string | URL, init?: MiddlewareResponseInit): NextResponse {\n const url = typeof destination === \"string\" ? destination : destination.toString();\n const headers = new Headers(init?.headers);\n headers.set(\"x-middleware-rewrite\", url);\n if (init?.request?.headers) {\n encodeMiddlewareRequestHeaders(headers, init.request.headers);\n }\n return new NextResponse(null, { ...init, headers });\n }\n\n /**\n * Continue to the next handler (middleware pattern).\n * Sets the x-middleware-next header.\n */\n static next(init?: MiddlewareResponseInit): NextResponse {\n const headers = new Headers(init?.headers);\n headers.set(\"x-middleware-next\", \"1\");\n if (init?.request?.headers) {\n encodeMiddlewareRequestHeaders(headers, init.request.headers);\n }\n return new NextResponse(null, { ...init, headers });\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextURL — lightweight URL wrapper with pathname helpers\n// ---------------------------------------------------------------------------\n\nexport interface NextURLConfig {\n basePath?: string;\n nextConfig?: {\n i18n?: {\n locales: string[];\n defaultLocale: string;\n };\n };\n}\n\nexport class NextURL {\n /** Internal URL stores the pathname WITHOUT basePath or locale prefix. */\n private _url: URL;\n private _basePath: string;\n private _locale: string | undefined;\n private _defaultLocale: string | undefined;\n private _locales: string[] | undefined;\n\n constructor(input: string | URL, base?: string | URL, config?: NextURLConfig) {\n this._url = new URL(input.toString(), base);\n this._basePath = config?.basePath ?? \"\";\n this._stripBasePath();\n const i18n = config?.nextConfig?.i18n;\n if (i18n) {\n this._locales = [...i18n.locales];\n this._defaultLocale = i18n.defaultLocale;\n this._analyzeLocale(this._locales);\n }\n }\n\n /** Strip basePath prefix from the internal pathname. */\n private _stripBasePath(): void {\n if (!this._basePath) return;\n const { pathname } = this._url;\n if (pathname === this._basePath || pathname.startsWith(this._basePath + \"/\")) {\n this._url.pathname = pathname.slice(this._basePath.length) || \"/\";\n }\n }\n\n /** Extract locale from pathname, stripping it from the internal URL. */\n private _analyzeLocale(locales: string[]): void {\n const segments = this._url.pathname.split(\"/\");\n const candidate = segments[1]?.toLowerCase();\n const match = locales.find((l) => l.toLowerCase() === candidate);\n if (match) {\n this._locale = match;\n this._url.pathname = \"/\" + segments.slice(2).join(\"/\");\n } else {\n this._locale = this._defaultLocale;\n }\n }\n\n /**\n * Reconstruct the full pathname with basePath + locale prefix.\n * Mirrors Next.js's internal formatPathname().\n */\n private _formatPathname(): string {\n // Build prefix: basePath + locale (skip defaultLocale — Next.js omits it)\n let prefix = this._basePath;\n if (this._locale && this._locale !== this._defaultLocale) {\n prefix += \"/\" + this._locale;\n }\n if (!prefix) return this._url.pathname;\n const inner = this._url.pathname;\n return inner === \"/\" ? prefix : prefix + inner;\n }\n\n get href(): string {\n const formatted = this._formatPathname();\n if (formatted === this._url.pathname) return this._url.href;\n // Replace pathname in href via string slicing — avoids URL allocation.\n // URL.href is always <origin+auth><pathname><search><hash>.\n const { href, pathname, search, hash } = this._url;\n const baseEnd = href.length - pathname.length - search.length - hash.length;\n return href.slice(0, baseEnd) + formatted + search + hash;\n }\n set href(value: string) {\n this._url.href = value;\n this._stripBasePath();\n if (this._locales) this._analyzeLocale(this._locales);\n }\n\n get origin(): string {\n return this._url.origin;\n }\n\n get protocol(): string {\n return this._url.protocol;\n }\n set protocol(value: string) {\n this._url.protocol = value;\n }\n\n get username(): string {\n return this._url.username;\n }\n set username(value: string) {\n this._url.username = value;\n }\n\n get password(): string {\n return this._url.password;\n }\n set password(value: string) {\n this._url.password = value;\n }\n\n get host(): string {\n return this._url.host;\n }\n set host(value: string) {\n this._url.host = value;\n }\n\n get hostname(): string {\n return this._url.hostname;\n }\n set hostname(value: string) {\n this._url.hostname = value;\n }\n\n get port(): string {\n return this._url.port;\n }\n set port(value: string) {\n this._url.port = value;\n }\n\n /** Returns the pathname WITHOUT basePath or locale prefix. */\n get pathname(): string {\n return this._url.pathname;\n }\n set pathname(value: string) {\n this._url.pathname = value;\n }\n\n get search(): string {\n return this._url.search;\n }\n set search(value: string) {\n this._url.search = value;\n }\n\n get searchParams(): URLSearchParams {\n return this._url.searchParams;\n }\n\n get hash(): string {\n return this._url.hash;\n }\n set hash(value: string) {\n this._url.hash = value;\n }\n\n get basePath(): string {\n return this._basePath;\n }\n set basePath(value: string) {\n this._basePath = value === \"\" ? \"\" : value.startsWith(\"/\") ? value : \"/\" + value;\n }\n\n get locale(): string {\n return this._locale ?? \"\";\n }\n set locale(value: string | undefined) {\n if (this._locales) {\n if (!value) {\n this._locale = this._defaultLocale;\n return;\n }\n if (!this._locales.includes(value)) {\n throw new TypeError(\n `The locale \"${value}\" is not in the configured locales: ${this._locales.join(\", \")}`,\n );\n }\n }\n this._locale = this._locales ? value : this._locale;\n }\n\n get defaultLocale(): string | undefined {\n return this._defaultLocale;\n }\n\n get locales(): string[] | undefined {\n return this._locales ? [...this._locales] : undefined;\n }\n\n clone(): NextURL {\n const config: NextURLConfig = {\n basePath: this._basePath,\n nextConfig: this._locales\n ? { i18n: { locales: [...this._locales], defaultLocale: this._defaultLocale! } }\n : undefined,\n };\n // Pass the full href (with locale/basePath re-added) so the constructor\n // can re-analyze and extract locale correctly.\n return new NextURL(this.href, undefined, config);\n }\n\n toString(): string {\n return this.href;\n }\n\n /**\n * The build ID of the Next.js application.\n * Set from `generateBuildId` in next.config.js, or a random UUID if not configured.\n * Can be used in middleware to detect deployment skew between client and server.\n * Matches the Next.js API: `request.nextUrl.buildId`.\n */\n get buildId(): string | undefined {\n return process.env.__VINEXT_BUILD_ID ?? undefined;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cookie helpers (minimal implementations)\n// ---------------------------------------------------------------------------\n\ninterface CookieEntry {\n name: string;\n value: string;\n}\n\nexport class RequestCookies {\n private _headers: Headers;\n private _parsed: Map<string, string>;\n\n constructor(headers: Headers) {\n this._headers = headers;\n this._parsed = parseCookieHeader(headers.get(\"cookie\") ?? \"\");\n }\n\n get(name: string): CookieEntry | undefined {\n const value = this._parsed.get(name);\n return value !== undefined ? { name, value } : undefined;\n }\n\n getAll(nameOrOptions?: string | CookieEntry): CookieEntry[] {\n const name = typeof nameOrOptions === \"string\" ? nameOrOptions : nameOrOptions?.name;\n return [...this._parsed.entries()]\n .filter(([cookieName]) => name === undefined || cookieName === name)\n .map(([cookieName, value]) => ({ name: cookieName, value }));\n }\n\n has(name: string): boolean {\n return this._parsed.has(name);\n }\n\n set(nameOrOptions: string | CookieEntry, value?: string): this {\n let cookieName: string;\n let cookieValue: string;\n if (typeof nameOrOptions === \"string\") {\n cookieName = nameOrOptions;\n cookieValue = value ?? \"\";\n } else {\n cookieName = nameOrOptions.name;\n cookieValue = nameOrOptions.value;\n }\n this._parsed.set(cookieName, cookieValue);\n this._syncHeader();\n return this;\n }\n\n delete(names: string | string[]): boolean | boolean[] {\n if (Array.isArray(names)) {\n const results = names.map((name) => this._parsed.delete(name));\n this._syncHeader();\n return results;\n }\n const result = this._parsed.delete(names);\n this._syncHeader();\n return result;\n }\n\n clear(): this {\n this._parsed.clear();\n this._syncHeader();\n return this;\n }\n\n get size(): number {\n return this._parsed.size;\n }\n\n toString(): string {\n return this._serialize();\n }\n\n private _serialize(): string {\n return [...this._parsed.entries()].map(([n, v]) => `${n}=${encodeURIComponent(v)}`).join(\"; \");\n }\n\n private _syncHeader(): void {\n if (this._parsed.size === 0) {\n this._headers.delete(\"cookie\");\n } else {\n this._headers.set(\"cookie\", this._serialize());\n }\n }\n\n [Symbol.iterator](): IterableIterator<[string, CookieEntry]> {\n const entries = this.getAll().map((c) => [c.name, c] as [string, CookieEntry]);\n return entries[Symbol.iterator]();\n }\n}\n\n/**\n * RFC 6265 §4.1.1: cookie-name is a token (RFC 2616 §2.2).\n * Allowed: any visible ASCII (0x21-0x7E) except separators: ()<>@,;:\\\"/[]?={}\n */\nconst VALID_COOKIE_NAME_RE =\n /^[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2E\\x30-\\x39\\x41-\\x5A\\x5E-\\x7A\\x7C\\x7E]+$/;\n\nfunction validateCookieName(name: string): void {\n if (!name || !VALID_COOKIE_NAME_RE.test(name)) {\n throw new Error(`Invalid cookie name: ${JSON.stringify(name)}`);\n }\n}\n\nfunction validateCookieAttributeValue(value: string, attributeName: string): void {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n if (code <= 0x1f || code === 0x7f || value[i] === \";\") {\n throw new Error(`Invalid cookie ${attributeName} value: ${JSON.stringify(value)}`);\n }\n }\n}\n\nexport class ResponseCookies {\n private _headers: Headers;\n\n constructor(headers: Headers) {\n this._headers = headers;\n }\n\n set(name: string, value: string, options?: CookieOptions): this {\n validateCookieName(name);\n const parts = [`${name}=${encodeURIComponent(value)}`];\n if (options?.path) {\n validateCookieAttributeValue(options.path, \"Path\");\n parts.push(`Path=${options.path}`);\n }\n if (options?.domain) {\n validateCookieAttributeValue(options.domain, \"Domain\");\n parts.push(`Domain=${options.domain}`);\n }\n if (options?.maxAge !== undefined) parts.push(`Max-Age=${options.maxAge}`);\n if (options?.expires) parts.push(`Expires=${options.expires.toUTCString()}`);\n if (options?.httpOnly) parts.push(\"HttpOnly\");\n if (options?.secure) parts.push(\"Secure\");\n if (options?.sameSite) parts.push(`SameSite=${options.sameSite}`);\n this._headers.append(\"Set-Cookie\", parts.join(\"; \"));\n return this;\n }\n\n get(name: string): CookieEntry | undefined {\n for (const header of this._headers.getSetCookie()) {\n const eq = header.indexOf(\"=\");\n if (eq === -1) continue;\n const cookieName = header.slice(0, eq);\n if (cookieName === name) {\n const semi = header.indexOf(\";\", eq);\n const raw = header.slice(eq + 1, semi === -1 ? undefined : semi);\n let value: string;\n try {\n value = decodeURIComponent(raw);\n } catch {\n value = raw;\n }\n return { name, value };\n }\n }\n return undefined;\n }\n\n has(name: string): boolean {\n return this.get(name) !== undefined;\n }\n\n getAll(): CookieEntry[] {\n const entries: CookieEntry[] = [];\n for (const header of this._headers.getSetCookie()) {\n const eq = header.indexOf(\"=\");\n if (eq === -1) continue;\n const cookieName = header.slice(0, eq);\n const semi = header.indexOf(\";\", eq);\n const raw = header.slice(eq + 1, semi === -1 ? undefined : semi);\n let value: string;\n try {\n value = decodeURIComponent(raw);\n } catch {\n value = raw;\n }\n entries.push({ name: cookieName, value });\n }\n return entries;\n }\n\n delete(name: string): this {\n this.set(name, \"\", { maxAge: 0, path: \"/\" });\n return this;\n }\n\n [Symbol.iterator](): IterableIterator<[string, CookieEntry]> {\n const entries: [string, CookieEntry][] = [];\n for (const header of this._headers.getSetCookie()) {\n const eq = header.indexOf(\"=\");\n if (eq === -1) continue;\n const cookieName = header.slice(0, eq);\n const semi = header.indexOf(\";\", eq);\n const raw = header.slice(eq + 1, semi === -1 ? undefined : semi);\n let value: string;\n try {\n value = decodeURIComponent(raw);\n } catch {\n value = raw;\n }\n entries.push([cookieName, { name: cookieName, value }]);\n }\n return entries[Symbol.iterator]();\n }\n}\n\ninterface CookieOptions {\n path?: string;\n domain?: string;\n maxAge?: number;\n expires?: Date;\n httpOnly?: boolean;\n secure?: boolean;\n sameSite?: \"Strict\" | \"Lax\" | \"None\";\n}\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface MiddlewareResponseInit extends ResponseInit {\n request?: {\n headers?: Headers;\n };\n}\n\nexport type NextMiddlewareResult = NextResponse | Response | null | undefined | void;\n\nexport type NextMiddleware = (\n request: NextRequest,\n event: NextFetchEvent,\n) => NextMiddlewareResult | Promise<NextMiddlewareResult>;\n\n/**\n * Minimal NextFetchEvent — extends FetchEvent where available,\n * otherwise provides the waitUntil pattern standalone.\n */\nexport class NextFetchEvent {\n sourcePage: string;\n private _waitUntilPromises: Promise<unknown>[] = [];\n\n constructor(params: { page: string }) {\n this.sourcePage = params.page;\n }\n\n waitUntil(promise: Promise<unknown>): void {\n this._waitUntilPromises.push(promise);\n }\n\n /** Drain all waitUntil promises. Returns a single promise that settles when all are done. */\n drainWaitUntil(): Promise<PromiseSettledResult<unknown>[]> {\n return Promise.allSettled(this._waitUntilPromises);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Utility exports\n// ---------------------------------------------------------------------------\n\n/**\n * Parse user agent string. Minimal implementation — for full UA parsing,\n * apps should use a dedicated library like `ua-parser-js`.\n */\nexport function userAgentFromString(ua: string | undefined): UserAgent {\n const input = ua ?? \"\";\n return {\n isBot: /bot|crawler|spider|crawling/i.test(input),\n ua: input,\n browser: {},\n device: {},\n engine: {},\n os: {},\n cpu: {},\n };\n}\n\nexport function userAgent({ headers }: { headers: Headers }): UserAgent {\n return userAgentFromString(headers.get(\"user-agent\") ?? undefined);\n}\n\nexport interface UserAgent {\n isBot: boolean;\n ua: string;\n browser: { name?: string; version?: string; major?: string };\n device: { model?: string; type?: string; vendor?: string };\n engine: { name?: string; version?: string };\n os: { name?: string; version?: string };\n cpu: { architecture?: string };\n}\n\n/**\n * after() — schedule work after the response is sent.\n *\n * Uses the platform's `waitUntil` (via the per-request ExecutionContext) when\n * available so the task survives past the response on Cloudflare Workers.\n * Falls back to a fire-and-forget microtask on runtimes without an execution\n * context (e.g. Node.js dev server).\n *\n * Throws when called inside a cached scope — request-specific\n * side-effects must not leak into cached results.\n */\nexport function after<T>(task: Promise<T> | (() => T | Promise<T>)): void {\n _throwIfInsideCacheScope(\"after()\");\n\n const promise = typeof task === \"function\" ? Promise.resolve().then(task) : task;\n // NOTE: vinext runs function tasks concurrently with response streaming (next microtask),\n // whereas Next.js queues them to run strictly after the response is sent via onClose.\n // This is a known simplification — function tasks here are not guaranteed to run\n // after the response completes, only after the current synchronous execution.\n //\n // `.catch()` is attached synchronously in the same tick as `promise` is created, so\n // there is no window where a pre-rejected `task` promise could trigger an\n // `unhandledrejection` event before the handler is in place.\n const guarded = promise.catch((err) => {\n console.error(\"[vinext] after() task failed:\", err);\n });\n\n // TODO: Next.js throws when after() is called outside a request context or when\n // waitUntil is unavailable, preventing silent task loss. vinext falls back to\n // fire-and-forget here, which is correct for the Node.js dev server (where\n // getRequestExecutionContext() always returns null). On Workers, a misconfigured\n // entry that omits runWithExecutionContext would silently drop tasks — consider\n // a one-time console.warn on the fallback path, gated to production only (e.g.\n // `process.env.NODE_ENV === 'production'` or `typeof caches !== 'undefined'` for\n // a Workers runtime check) with a module-level `let _warned = false` guard so it\n // fires at most once and doesn't spam the dev-server console.\n getRequestExecutionContext()?.waitUntil(guarded);\n}\n\n/**\n * connection() — signals that the response requires a live connection\n * (not a static/cached response). Opts the page out of ISR caching\n * and sets Cache-Control: no-store on the response.\n */\nexport async function connection(): Promise<void> {\n const { markDynamicUsage, throwIfInsideCacheScope } = await import(\"./headers.js\");\n throwIfInsideCacheScope(\"connection()\");\n markDynamicUsage();\n}\n\n/**\n * URLPattern re-export — used in middleware for route matching.\n * Available natively in Node 20+, Cloudflare Workers, Deno.\n * Falls back to urlpattern-polyfill if the global is not available.\n */\nexport const URLPattern: typeof globalThis.URLPattern =\n globalThis.URLPattern ??\n (() => {\n throw new Error(\n \"URLPattern is not available in this runtime. \" +\n \"Install the `urlpattern-polyfill` package or upgrade to Node 20+.\",\n );\n });\n"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAM,qBAAqB,OAAO,IAAI,iCAAiC;AACvE,MAAM,0BAA0B,OAAO,IAAI,2BAA2B;AACtE,MAAM,KAAK;AAEX,SAAS,yBAAyB,SAAuB;AAEvD,KADiB,GAAG,qBACN,UAAU,IAAI,KAC1B,OAAM,IAAI,MACR,KAAK,QAAQ,iGAC+C,QAAQ,uDAErE;AAGH,KADoB,GAAG,0BACN,UAAU,KAAK,KAC9B,OAAM,IAAI,MACR,KAAK,QAAQ,iIAC+C,QAAQ,uDAErE;;AAQL,IAAa,cAAb,cAAiC,QAAQ;CACvC;CACA;CAEA,YACE,OACA,MAMA;EAGA,MAAM,EAAE,YAAY,aAAa,GAAG,gBAAgB,QAAQ,EAAE;AAG9D,MAAI,iBAAiB,SAAS;GAC5B,MAAM,MAAM;AACZ,SAA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ent":["/**\n * next/server shim\n *\n * Provides NextRequest, NextResponse, and related types that work with\n * standard Web APIs (Request/Response). This means they work on Node,\n * Cloudflare Workers, Deno, and any WinterCG-compatible runtime.\n *\n * This is a pragmatic subset — we implement the most commonly used APIs\n * rather than bug-for-bug parity with Next.js internals.\n */\n\nimport { encodeMiddlewareRequestHeaders } from \"../server/middleware-request-headers.js\";\nimport { parseCookieHeader } from \"./internal/parse-cookie-header.js\";\nimport { getRequestExecutionContext } from \"./request-context.js\";\n\n// ---------------------------------------------------------------------------\n// Inlined cache-scope guard for after()\n//\n// We cannot statically import throwIfInsideCacheScope from headers.ts here\n// because headers.ts contains the \"use cache\" directive string in its error\n// message, which causes Vite's use-cache transform to include it in the module\n// graph. If headers.ts is pulled in via static import from server.ts, the\n// transform fires on it in Pages Router fixtures that lack @vitejs/plugin-rsc.\n//\n// The connection() function in this file avoids the same problem by using\n// `await import(\"./headers.js\")` (dynamic import, async function). after()\n// must remain synchronous, so we inline the check using the same Symbol.for\n// keys that cache-runtime.ts and cache.ts register their ALS instances with.\n// ---------------------------------------------------------------------------\n\nconst _USE_CACHE_ALS_KEY = Symbol.for(\"vinext.cacheRuntime.contextAls\");\nconst _UNSTABLE_CACHE_ALS_KEY = Symbol.for(\"vinext.unstableCache.als\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\n\nfunction _throwIfInsideCacheScope(apiName: string): void {\n const cacheAls = _g[_USE_CACHE_ALS_KEY] as { getStore(): unknown } | undefined;\n if (cacheAls?.getStore() != null) {\n throw new Error(\n `\\`${apiName}\\` cannot be called inside \"use cache\". ` +\n `If you need this data inside a cached function, call \\`${apiName}\\` ` +\n \"outside and pass the required data as an argument.\",\n );\n }\n const unstableAls = _g[_UNSTABLE_CACHE_ALS_KEY] as { getStore(): unknown } | undefined;\n if (unstableAls?.getStore() === true) {\n throw new Error(\n `\\`${apiName}\\` cannot be called inside a function cached with \\`unstable_cache()\\`. ` +\n `If you need this data inside a cached function, call \\`${apiName}\\` ` +\n \"outside and pass the required data as an argument.\",\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextRequest\n// ---------------------------------------------------------------------------\n\nexport class NextRequest extends Request {\n private _nextUrl: NextURL;\n private _cookies: RequestCookies;\n\n constructor(\n input: URL | RequestInfo,\n init?: RequestInit & {\n nextConfig?: {\n basePath?: string;\n i18n?: { locales: string[]; defaultLocale: string };\n };\n },\n ) {\n // Strip nextConfig before passing to super() — it's vinext-internal,\n // not a valid RequestInit property.\n const { nextConfig: _nextConfig, ...requestInit } = init ?? {};\n // Handle the case where input is a Request object - we need to extract URL and init\n // to avoid Node.js undici issues with passing Request objects directly to super()\n if (input instanceof Request) {\n const req = input;\n super(req.url, {\n method: req.method,\n headers: req.headers,\n body: req.body,\n // @ts-expect-error - duplex is not in RequestInit type but needed for streams\n duplex: req.body ? \"half\" : undefined,\n ...requestInit,\n });\n } else {\n super(input, requestInit);\n }\n const url =\n typeof input === \"string\"\n ? new URL(input, \"http://localhost\")\n : input instanceof URL\n ? input\n : new URL(input.url, \"http://localhost\");\n const urlConfig: NextURLConfig | undefined = _nextConfig\n ? { basePath: _nextConfig.basePath, nextConfig: { i18n: _nextConfig.i18n } }\n : undefined;\n this._nextUrl = new NextURL(url, undefined, urlConfig);\n this._cookies = new RequestCookies(this.headers);\n }\n\n get nextUrl(): NextURL {\n return this._nextUrl;\n }\n\n get cookies(): RequestCookies {\n return this._cookies;\n }\n\n /**\n * Client IP address. Prefers Cloudflare's trusted CF-Connecting-IP header\n * over the spoofable X-Forwarded-For. Returns undefined if unavailable.\n */\n get ip(): string | undefined {\n return (\n this.headers.get(\"cf-connecting-ip\") ??\n this.headers.get(\"x-real-ip\") ??\n this.headers.get(\"x-forwarded-for\")?.split(\",\")[0]?.trim() ??\n undefined\n );\n }\n\n /**\n * Geolocation data. Platform-dependent (e.g., Cloudflare, Vercel).\n * Returns undefined if not available.\n */\n get geo():\n | { city?: string; country?: string; region?: string; latitude?: string; longitude?: string }\n | undefined {\n // Check Cloudflare-style headers, Vercel-style headers\n const country =\n this.headers.get(\"cf-ipcountry\") ?? this.headers.get(\"x-vercel-ip-country\") ?? undefined;\n if (!country) return undefined;\n return {\n country,\n city: this.headers.get(\"cf-ipcity\") ?? this.headers.get(\"x-vercel-ip-city\") ?? undefined,\n region:\n this.headers.get(\"cf-region\") ??\n this.headers.get(\"x-vercel-ip-country-region\") ??\n undefined,\n latitude:\n this.headers.get(\"cf-iplatitude\") ?? this.headers.get(\"x-vercel-ip-latitude\") ?? undefined,\n longitude:\n this.headers.get(\"cf-iplongitude\") ??\n this.headers.get(\"x-vercel-ip-longitude\") ??\n undefined,\n };\n }\n\n /**\n * The build ID of the Next.js application.\n * Delegates to `nextUrl.buildId` to match Next.js API surface.\n * Can be used in middleware to detect deployment skew between client and server.\n */\n get buildId(): string | undefined {\n return this._nextUrl.buildId;\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextResponse\n// ---------------------------------------------------------------------------\n\nexport class NextResponse<_Body = unknown> extends Response {\n private _cookies: ResponseCookies;\n\n constructor(body?: BodyInit | null, init?: ResponseInit) {\n super(body, init);\n this._cookies = new ResponseCookies(this.headers);\n }\n\n get cookies(): ResponseCookies {\n return this._cookies;\n }\n\n /**\n * Create a JSON response.\n */\n static json<JsonBody>(body: JsonBody, init?: ResponseInit): NextResponse<JsonBody> {\n const headers = new Headers(init?.headers);\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n return new NextResponse(JSON.stringify(body), {\n ...init,\n headers,\n }) as NextResponse<JsonBody>;\n }\n\n /**\n * Create a redirect response.\n */\n static redirect(url: string | URL, init?: number | ResponseInit): NextResponse {\n const status = typeof init === \"number\" ? init : (init?.status ?? 307);\n const destination = typeof url === \"string\" ? url : url.toString();\n const headers = new Headers(typeof init === \"object\" ? init?.headers : undefined);\n headers.set(\"Location\", destination);\n return new NextResponse(null, { status, headers });\n }\n\n /**\n * Create a rewrite response (middleware pattern).\n * Sets the x-middleware-rewrite header.\n */\n static rewrite(destination: string | URL, init?: MiddlewareResponseInit): NextResponse {\n const url = typeof destination === \"string\" ? destination : destination.toString();\n const headers = new Headers(init?.headers);\n headers.set(\"x-middleware-rewrite\", url);\n if (init?.request?.headers) {\n encodeMiddlewareRequestHeaders(headers, init.request.headers);\n }\n return new NextResponse(null, { ...init, headers });\n }\n\n /**\n * Continue to the next handler (middleware pattern).\n * Sets the x-middleware-next header.\n */\n static next(init?: MiddlewareResponseInit): NextResponse {\n const headers = new Headers(init?.headers);\n headers.set(\"x-middleware-next\", \"1\");\n if (init?.request?.headers) {\n encodeMiddlewareRequestHeaders(headers, init.request.headers);\n }\n return new NextResponse(null, { ...init, headers });\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextURL — lightweight URL wrapper with pathname helpers\n// ---------------------------------------------------------------------------\n\nexport interface NextURLConfig {\n basePath?: string;\n nextConfig?: {\n i18n?: {\n locales: string[];\n defaultLocale: string;\n };\n };\n}\n\nexport class NextURL {\n /** Internal URL stores the pathname WITHOUT basePath or locale prefix. */\n private _url: URL;\n private _basePath: string;\n private _locale: string | undefined;\n private _defaultLocale: string | undefined;\n private _locales: string[] | undefined;\n\n constructor(input: string | URL, base?: string | URL, config?: NextURLConfig) {\n this._url = new URL(input.toString(), base);\n this._basePath = config?.basePath ?? \"\";\n this._stripBasePath();\n const i18n = config?.nextConfig?.i18n;\n if (i18n) {\n this._locales = [...i18n.locales];\n this._defaultLocale = i18n.defaultLocale;\n this._analyzeLocale(this._locales);\n }\n }\n\n /** Strip basePath prefix from the internal pathname. */\n private _stripBasePath(): void {\n if (!this._basePath) return;\n const { pathname } = this._url;\n if (pathname === this._basePath || pathname.startsWith(this._basePath + \"/\")) {\n this._url.pathname = pathname.slice(this._basePath.length) || \"/\";\n }\n }\n\n /** Extract locale from pathname, stripping it from the internal URL. */\n private _analyzeLocale(locales: string[]): void {\n const segments = this._url.pathname.split(\"/\");\n const candidate = segments[1]?.toLowerCase();\n const match = locales.find((l) => l.toLowerCase() === candidate);\n if (match) {\n this._locale = match;\n this._url.pathname = \"/\" + segments.slice(2).join(\"/\");\n } else {\n this._locale = this._defaultLocale;\n }\n }\n\n /**\n * Reconstruct the full pathname with basePath + locale prefix.\n * Mirrors Next.js's internal formatPathname().\n */\n private _formatPathname(): string {\n // Build prefix: basePath + locale (skip defaultLocale — Next.js omits it)\n let prefix = this._basePath;\n if (this._locale && this._locale !== this._defaultLocale) {\n prefix += \"/\" + this._locale;\n }\n if (!prefix) return this._url.pathname;\n const inner = this._url.pathname;\n return inner === \"/\" ? prefix : prefix + inner;\n }\n\n get href(): string {\n const formatted = this._formatPathname();\n if (formatted === this._url.pathname) return this._url.href;\n // Replace pathname in href via string slicing — avoids URL allocation.\n // URL.href is always <origin+auth><pathname><search><hash>.\n const { href, pathname, search, hash } = this._url;\n const baseEnd = href.length - pathname.length - search.length - hash.length;\n return href.slice(0, baseEnd) + formatted + search + hash;\n }\n set href(value: string) {\n this._url.href = value;\n this._stripBasePath();\n if (this._locales) this._analyzeLocale(this._locales);\n }\n\n get origin(): string {\n return this._url.origin;\n }\n\n get protocol(): string {\n return this._url.protocol;\n }\n set protocol(value: string) {\n this._url.protocol = value;\n }\n\n get username(): string {\n return this._url.username;\n }\n set username(value: string) {\n this._url.username = value;\n }\n\n get password(): string {\n return this._url.password;\n }\n set password(value: string) {\n this._url.password = value;\n }\n\n get host(): string {\n return this._url.host;\n }\n set host(value: string) {\n this._url.host = value;\n }\n\n get hostname(): string {\n return this._url.hostname;\n }\n set hostname(value: string) {\n this._url.hostname = value;\n }\n\n get port(): string {\n return this._url.port;\n }\n set port(value: string) {\n this._url.port = value;\n }\n\n /** Returns the pathname WITHOUT basePath or locale prefix. */\n get pathname(): string {\n return this._url.pathname;\n }\n set pathname(value: string) {\n this._url.pathname = value;\n }\n\n get search(): string {\n return this._url.search;\n }\n set search(value: string) {\n this._url.search = value;\n }\n\n get searchParams(): URLSearchParams {\n return this._url.searchParams;\n }\n\n get hash(): string {\n return this._url.hash;\n }\n set hash(value: string) {\n this._url.hash = value;\n }\n\n get basePath(): string {\n return this._basePath;\n }\n set basePath(value: string) {\n this._basePath = value === \"\" ? \"\" : value.startsWith(\"/\") ? value : \"/\" + value;\n }\n\n get locale(): string {\n return this._locale ?? \"\";\n }\n set locale(value: string | undefined) {\n if (this._locales) {\n if (!value) {\n this._locale = this._defaultLocale;\n return;\n }\n if (!this._locales.includes(value)) {\n throw new TypeError(\n `The locale \"${value}\" is not in the configured locales: ${this._locales.join(\", \")}`,\n );\n }\n }\n this._locale = this._locales ? value : this._locale;\n }\n\n get defaultLocale(): string | undefined {\n return this._defaultLocale;\n }\n\n get locales(): string[] | undefined {\n return this._locales ? [...this._locales] : undefined;\n }\n\n clone(): NextURL {\n const config: NextURLConfig = {\n basePath: this._basePath,\n nextConfig: this._locales\n ? { i18n: { locales: [...this._locales], defaultLocale: this._defaultLocale! } }\n : undefined,\n };\n // Pass the full href (with locale/basePath re-added) so the constructor\n // can re-analyze and extract locale correctly.\n return new NextURL(this.href, undefined, config);\n }\n\n toString(): string {\n return this.href;\n }\n\n /**\n * The build ID of the Next.js application.\n * Set from `generateBuildId` in next.config.js, or a random UUID if not configured.\n * Can be used in middleware to detect deployment skew between client and server.\n * Matches the Next.js API: `request.nextUrl.buildId`.\n */\n get buildId(): string | undefined {\n return process.env.__VINEXT_BUILD_ID ?? undefined;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cookie helpers (minimal implementations)\n// ---------------------------------------------------------------------------\n\ninterface CookieEntry {\n name: string;\n value: string;\n}\n\nexport class RequestCookies {\n private _headers: Headers;\n private _parsed: Map<string, string>;\n\n constructor(headers: Headers) {\n this._headers = headers;\n this._parsed = parseCookieHeader(headers.get(\"cookie\") ?? \"\");\n }\n\n get(name: string): CookieEntry | undefined {\n const value = this._parsed.get(name);\n return value !== undefined ? { name, value } : undefined;\n }\n\n getAll(nameOrOptions?: string | CookieEntry): CookieEntry[] {\n const name = typeof nameOrOptions === \"string\" ? nameOrOptions : nameOrOptions?.name;\n return [...this._parsed.entries()]\n .filter(([cookieName]) => name === undefined || cookieName === name)\n .map(([cookieName, value]) => ({ name: cookieName, value }));\n }\n\n has(name: string): boolean {\n return this._parsed.has(name);\n }\n\n set(nameOrOptions: string | CookieEntry, value?: string): this {\n let cookieName: string;\n let cookieValue: string;\n if (typeof nameOrOptions === \"string\") {\n cookieName = nameOrOptions;\n cookieValue = value ?? \"\";\n } else {\n cookieName = nameOrOptions.name;\n cookieValue = nameOrOptions.value;\n }\n this._parsed.set(cookieName, cookieValue);\n this._syncHeader();\n return this;\n }\n\n delete(names: string | string[]): boolean | boolean[] {\n if (Array.isArray(names)) {\n const results = names.map((name) => this._parsed.delete(name));\n this._syncHeader();\n return results;\n }\n const result = this._parsed.delete(names);\n this._syncHeader();\n return result;\n }\n\n clear(): this {\n this._parsed.clear();\n this._syncHeader();\n return this;\n }\n\n get size(): number {\n return this._parsed.size;\n }\n\n toString(): string {\n return this._serialize();\n }\n\n private _serialize(): string {\n return [...this._parsed.entries()].map(([n, v]) => `${n}=${encodeURIComponent(v)}`).join(\"; \");\n }\n\n private _syncHeader(): void {\n if (this._parsed.size === 0) {\n this._headers.delete(\"cookie\");\n } else {\n this._headers.set(\"cookie\", this._serialize());\n }\n }\n\n [Symbol.iterator](): IterableIterator<[string, CookieEntry]> {\n const entries = this.getAll().map((c) => [c.name, c] as [string, CookieEntry]);\n return entries[Symbol.iterator]();\n }\n}\n\n/**\n * RFC 6265 §4.1.1: cookie-name is a token (RFC 2616 §2.2).\n * Allowed: any visible ASCII (0x21-0x7E) except separators: ()<>@,;:\\\"/[]?={}\n */\nconst VALID_COOKIE_NAME_RE =\n /^[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2E\\x30-\\x39\\x41-\\x5A\\x5E-\\x7A\\x7C\\x7E]+$/;\n\nfunction validateCookieName(name: string): void {\n if (!name || !VALID_COOKIE_NAME_RE.test(name)) {\n throw new Error(`Invalid cookie name: ${JSON.stringify(name)}`);\n }\n}\n\nfunction validateCookieAttributeValue(value: string, attributeName: string): void {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n if (code <= 0x1f || code === 0x7f || value[i] === \";\") {\n throw new Error(`Invalid cookie ${attributeName} value: ${JSON.stringify(value)}`);\n }\n }\n}\n\nexport class ResponseCookies {\n private _headers: Headers;\n\n constructor(headers: Headers) {\n this._headers = headers;\n }\n\n set(name: string, value: string, options?: CookieOptions): this {\n validateCookieName(name);\n const parts = [`${name}=${encodeURIComponent(value)}`];\n if (options?.path) {\n validateCookieAttributeValue(options.path, \"Path\");\n parts.push(`Path=${options.path}`);\n }\n if (options?.domain) {\n validateCookieAttributeValue(options.domain, \"Domain\");\n parts.push(`Domain=${options.domain}`);\n }\n if (options?.maxAge !== undefined) parts.push(`Max-Age=${options.maxAge}`);\n if (options?.expires) parts.push(`Expires=${options.expires.toUTCString()}`);\n if (options?.httpOnly) parts.push(\"HttpOnly\");\n if (options?.secure) parts.push(\"Secure\");\n if (options?.sameSite) parts.push(`SameSite=${options.sameSite}`);\n this._headers.append(\"Set-Cookie\", parts.join(\"; \"));\n return this;\n }\n\n get(name: string): CookieEntry | undefined {\n for (const header of this._headers.getSetCookie()) {\n const eq = header.indexOf(\"=\");\n if (eq === -1) continue;\n const cookieName = header.slice(0, eq);\n if (cookieName === name) {\n const semi = header.indexOf(\";\", eq);\n const raw = header.slice(eq + 1, semi === -1 ? undefined : semi);\n let value: string;\n try {\n value = decodeURIComponent(raw);\n } catch {\n value = raw;\n }\n return { name, value };\n }\n }\n return undefined;\n }\n\n has(name: string): boolean {\n return this.get(name) !== undefined;\n }\n\n getAll(): CookieEntry[] {\n const entries: CookieEntry[] = [];\n for (const header of this._headers.getSetCookie()) {\n const eq = header.indexOf(\"=\");\n if (eq === -1) continue;\n const cookieName = header.slice(0, eq);\n const semi = header.indexOf(\";\", eq);\n const raw = header.slice(eq + 1, semi === -1 ? undefined : semi);\n let value: string;\n try {\n value = decodeURIComponent(raw);\n } catch {\n value = raw;\n }\n entries.push({ name: cookieName, value });\n }\n return entries;\n }\n\n delete(name: string): this {\n this.set(name, \"\", { maxAge: 0, path: \"/\" });\n return this;\n }\n\n [Symbol.iterator](): IterableIterator<[string, CookieEntry]> {\n const entries: [string, CookieEntry][] = [];\n for (const header of this._headers.getSetCookie()) {\n const eq = header.indexOf(\"=\");\n if (eq === -1) continue;\n const cookieName = header.slice(0, eq);\n const semi = header.indexOf(\";\", eq);\n const raw = header.slice(eq + 1, semi === -1 ? undefined : semi);\n let value: string;\n try {\n value = decodeURIComponent(raw);\n } catch {\n value = raw;\n }\n entries.push([cookieName, { name: cookieName, value }]);\n }\n return entries[Symbol.iterator]();\n }\n}\n\ninterface CookieOptions {\n path?: string;\n domain?: string;\n maxAge?: number;\n expires?: Date;\n httpOnly?: boolean;\n secure?: boolean;\n sameSite?: \"Strict\" | \"Lax\" | \"None\";\n}\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface MiddlewareResponseInit extends ResponseInit {\n request?: {\n headers?: Headers;\n };\n}\n\nexport type NextMiddlewareResult = NextResponse | Response | null | undefined | void;\n\nexport type NextMiddleware = (\n request: NextRequest,\n event: NextFetchEvent,\n) => NextMiddlewareResult | Promise<NextMiddlewareResult>;\n\n/**\n * Minimal NextFetchEvent — extends FetchEvent where available,\n * otherwise provides the waitUntil pattern standalone.\n */\nexport class NextFetchEvent {\n sourcePage: string;\n private _waitUntilPromises: Promise<unknown>[] = [];\n\n constructor(params: { page: string }) {\n this.sourcePage = params.page;\n }\n\n waitUntil(promise: Promise<unknown>): void {\n this._waitUntilPromises.push(promise);\n }\n\n get waitUntilPromises(): Promise<unknown>[] {\n return this._waitUntilPromises;\n }\n\n /** Drain all waitUntil promises. Returns a single promise that settles when all are done. */\n drainWaitUntil(): Promise<PromiseSettledResult<unknown>[]> {\n return Promise.allSettled(this._waitUntilPromises);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Utility exports\n// ---------------------------------------------------------------------------\n\n/**\n * Parse user agent string. Minimal implementation — for full UA parsing,\n * apps should use a dedicated library like `ua-parser-js`.\n */\nexport function userAgentFromString(ua: string | undefined): UserAgent {\n const input = ua ?? \"\";\n return {\n isBot: /bot|crawler|spider|crawling/i.test(input),\n ua: input,\n browser: {},\n device: {},\n engine: {},\n os: {},\n cpu: {},\n };\n}\n\nexport function userAgent({ headers }: { headers: Headers }): UserAgent {\n return userAgentFromString(headers.get(\"user-agent\") ?? undefined);\n}\n\nexport interface UserAgent {\n isBot: boolean;\n ua: string;\n browser: { name?: string; version?: string; major?: string };\n device: { model?: string; type?: string; vendor?: string };\n engine: { name?: string; version?: string };\n os: { name?: string; version?: string };\n cpu: { architecture?: string };\n}\n\n/**\n * after() — schedule work after the response is sent.\n *\n * Uses the platform's `waitUntil` (via the per-request ExecutionContext) when\n * available so the task survives past the response on Cloudflare Workers.\n * Falls back to a fire-and-forget microtask on runtimes without an execution\n * context (e.g. Node.js dev server).\n *\n * Throws when called inside a cached scope — request-specific\n * side-effects must not leak into cached results.\n */\nexport function after<T>(task: Promise<T> | (() => T | Promise<T>)): void {\n _throwIfInsideCacheScope(\"after()\");\n\n const promise = typeof task === \"function\" ? Promise.resolve().then(task) : task;\n // NOTE: vinext runs function tasks concurrently with response streaming (next microtask),\n // whereas Next.js queues them to run strictly after the response is sent via onClose.\n // This is a known simplification — function tasks here are not guaranteed to run\n // after the response completes, only after the current synchronous execution.\n //\n // `.catch()` is attached synchronously in the same tick as `promise` is created, so\n // there is no window where a pre-rejected `task` promise could trigger an\n // `unhandledrejection` event before the handler is in place.\n const guarded = promise.catch((err) => {\n console.error(\"[vinext] after() task failed:\", err);\n });\n\n // TODO: Next.js throws when after() is called outside a request context or when\n // waitUntil is unavailable, preventing silent task loss. vinext falls back to\n // fire-and-forget here, which is correct for the Node.js dev server (where\n // getRequestExecutionContext() always returns null). On Workers, a misconfigured\n // entry that omits runWithExecutionContext would silently drop tasks — consider\n // a one-time console.warn on the fallback path, gated to production only (e.g.\n // `process.env.NODE_ENV === 'production'` or `typeof caches !== 'undefined'` for\n // a Workers runtime check) with a module-level `let _warned = false` guard so it\n // fires at most once and doesn't spam the dev-server console.\n getRequestExecutionContext()?.waitUntil(guarded);\n}\n\n/**\n * connection() — signals that the response requires a live connection\n * (not a static/cached response). Opts the page out of ISR caching\n * and sets Cache-Control: no-store on the response.\n */\nexport async function connection(): Promise<void> {\n const { markDynamicUsage, throwIfInsideCacheScope } = await import(\"./headers.js\");\n throwIfInsideCacheScope(\"connection()\");\n markDynamicUsage();\n}\n\n/**\n * URLPattern re-export — used in middleware for route matching.\n * Available natively in Node 20+, Cloudflare Workers, Deno.\n * Falls back to urlpattern-polyfill if the global is not available.\n */\nexport const URLPattern: typeof globalThis.URLPattern =\n globalThis.URLPattern ??\n (() => {\n throw new Error(\n \"URLPattern is not available in this runtime. \" +\n \"Install the `urlpattern-polyfill` package or upgrade to Node 20+.\",\n );\n });\n"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAM,qBAAqB,OAAO,IAAI,iCAAiC;AACvE,MAAM,0BAA0B,OAAO,IAAI,2BAA2B;AACtE,MAAM,KAAK;AAEX,SAAS,yBAAyB,SAAuB;AAEvD,KADiB,GAAG,qBACN,UAAU,IAAI,KAC1B,OAAM,IAAI,MACR,KAAK,QAAQ,iGAC+C,QAAQ,uDAErE;AAGH,KADoB,GAAG,0BACN,UAAU,KAAK,KAC9B,OAAM,IAAI,MACR,KAAK,QAAQ,iIAC+C,QAAQ,uDAErE;;AAQL,IAAa,cAAb,cAAiC,QAAQ;CACvC;CACA;CAEA,YACE,OACA,MAMA;EAGA,MAAM,EAAE,YAAY,aAAa,GAAG,gBAAgB,QAAQ,EAAE;AAG9D,MAAI,iBAAiB,SAAS;GAC5B,MAAM,MAAM;AACZ,SAAM,IAAI,KAAK;IACb,QAAQ,IAAI;IACZ,SAAS,IAAI;IACb,MAAM,IAAI;IAEV,QAAQ,IAAI,OAAO,SAAS,KAAA;IAC5B,GAAG;IACJ,CAAC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YAAQ;;AAEV,WAAQ,KAAK,CAAC,YAAY;IAAE,MAAM;IAAY;IAAO,CAAC,CAAC;;AAEzD,SAAO,QAAQ,OAAO,WAAW;;;;;;;AAmCrC,IAAa,iBAAb,MAA4B;CAC1B;CACA,qBAAiD,EAAE;CAEnD,YAAY,QAA0B;AACpC,OAAK,aAAa,OAAO;;CAG3B,UAAU,SAAiC;AACzC,OAAK,mBAAmB,KAAK,QAAQ;;CAGvC,IAAI,oBAAwC;AAC1C,SAAO,KAAK;;;CAId,iBAA2D;AACzD,SAAO,QAAQ,WAAW,KAAK,mBAAmB;;;;;;;AAYtD,SAAgB,oBAAoB,IAAmC;CACrE,MAAM,QAAQ,MAAM;AACpB,QAAO;EACL,OAAO,+BAA+B,KAAK,MAAM;EACjD,IAAI;EACJ,SAAS,EAAE;EACX,QAAQ,EAAE;EACV,QAAQ,EAAE;EACV,IAAI,EAAE;EACN,KAAK,EAAE;EACR;;AAGH,SAAgB,UAAU,EAAE,WAA4C;AACtE,QAAO,oBAAoB,QAAQ,IAAI,aAAa,IAAI,KAAA,EAAU;;;;;;;;;;;;;AAwBpE,SAAgB,MAAS,MAAiD;AACxE,0BAAyB,UAAU;CAWnC,MAAM,WATU,OAAO,SAAS,aAAa,QAAQ,SAAS,CAAC,KAAK,KAAK,GAAG,MASpD,OAAO,QAAQ;AACrC,UAAQ,MAAM,iCAAiC,IAAI;GACnD;AAWF,6BAA4B,EAAE,UAAU,QAAQ;;;;;;;AAQlD,eAAsB,aAA4B;CAChD,MAAM,EAAE,kBAAkB,4BAA4B,MAAM,OAAO;AACnE,yBAAwB,eAAe;AACvC,mBAAkB;;;;;;;AAQpB,MAAa,aACX,WAAW,qBACJ;AACL,OAAM,IAAI,MACR,iHAED"}
|
|
@@ -18,6 +18,8 @@ import { NavigationState } from "./navigation-state.js";
|
|
|
18
18
|
interface UnifiedRequestContext extends VinextHeadersShimState, I18nState, NavigationState, CacheState, PrivateCacheState, FetchCacheState, RouterState, HeadState {
|
|
19
19
|
/** Cloudflare Workers ExecutionContext, or null on Node.js dev. */
|
|
20
20
|
executionContext: ExecutionContextLike | null;
|
|
21
|
+
/** Per-request cache for cacheForRequest(). Keyed by factory function reference. */
|
|
22
|
+
requestCache: WeakMap<(...args: any[]) => any, unknown>;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Create a fresh `UnifiedRequestContext` with defaults for all fields.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified-request-context.js","names":[],"sources":["../../src/shims/unified-request-context.ts"],"sourcesContent":["/**\n * Unified per-request context backed by a single AsyncLocalStorage.\n *\n * Consolidates the 5–6 nested ALS scopes that previously wrapped every\n * App Router request (headers, navigation, cache-state, private-cache,\n * fetch-cache, execution-context) into one flat store.\n *\n * Each shim module checks `isInsideUnifiedScope()` and reads its sub-fields\n * from the unified store, falling back to its own standalone ALS when\n * outside (SSR environment, Pages Router, tests).\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport type {\n CacheState,\n ExecutionContextLike,\n FetchCacheState,\n HeadState,\n I18nState,\n NavigationState,\n PrivateCacheState,\n RouterState,\n VinextHeadersShimState,\n} from \"./request-state-types.js\";\n\n// ---------------------------------------------------------------------------\n// Unified context shape\n// ---------------------------------------------------------------------------\n\n/**\n * Flat union of all per-request state previously spread across\n * VinextHeadersShimState, NavigationState, CacheState, PrivateCacheState,\n * FetchCacheState, and ExecutionContextLike.\n *\n * Each field group is documented with its source shim module.\n */\nexport interface UnifiedRequestContext\n extends\n VinextHeadersShimState,\n I18nState,\n NavigationState,\n CacheState,\n PrivateCacheState,\n FetchCacheState,\n RouterState,\n HeadState {\n // ── request-context.ts ─────────────────────────────────────────────\n /** Cloudflare Workers ExecutionContext, or null on Node.js dev. */\n executionContext: ExecutionContextLike | null;\n}\n\n// ---------------------------------------------------------------------------\n// ALS setup — stored on globalThis via Symbol.for so all Vite environments\n// (RSC/SSR/client) share the same instance.\n// ---------------------------------------------------------------------------\n\nconst _ALS_KEY = Symbol.for(\"vinext.unifiedRequestContext.als\");\nconst _REQUEST_CONTEXT_ALS_KEY = Symbol.for(\"vinext.requestContext.als\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = (_g[_ALS_KEY] ??=\n new AsyncLocalStorage<UnifiedRequestContext>()) as AsyncLocalStorage<UnifiedRequestContext>;\n\nfunction _getInheritedExecutionContext(): ExecutionContextLike | null {\n const unifiedStore = _als.getStore();\n if (unifiedStore) return unifiedStore.executionContext;\n\n const executionContextAls = _g[_REQUEST_CONTEXT_ALS_KEY] as\n | AsyncLocalStorage<ExecutionContextLike | null>\n | undefined;\n return executionContextAls?.getStore() ?? null;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Create a fresh `UnifiedRequestContext` with defaults for all fields.\n * Pass partial overrides for the fields you need to pre-populate.\n */\nexport function createRequestContext(opts?: Partial<UnifiedRequestContext>): UnifiedRequestContext {\n return {\n headersContext: null,\n dynamicUsageDetected: false,\n pendingSetCookies: [],\n draftModeCookieHeader: null,\n phase: \"render\",\n i18nContext: null,\n serverContext: null,\n serverInsertedHTMLCallbacks: [],\n requestScopedCacheLife: null,\n _privateCache: null,\n currentRequestTags: [],\n executionContext: _getInheritedExecutionContext(), // inherits from standalone ALS if present\n ssrContext: null,\n ssrHeadChildren: [],\n ...opts,\n };\n}\n\n/**\n * Run `fn` within a unified request context scope.\n * All shim modules will read/write their state from `ctx` for the\n * duration of the call, including async continuations.\n */\nexport function runWithRequestContext<T>(\n ctx: UnifiedRequestContext,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n return _als.run(ctx, fn);\n}\n\n/**\n * Run `fn` in a nested unified scope derived from the current request context.\n * Used by legacy runWith* wrappers to reset or override one sub-state while\n * preserving proper async isolation for continuations created inside `fn`.\n * The child scope is a shallow clone of the parent store, so untouched fields\n * keep sharing their existing references while overridden slices can be reset.\n *\n * @internal\n */\nexport function runWithUnifiedStateMutation<T>(\n mutate: (ctx: UnifiedRequestContext) => void,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n const parentCtx = _als.getStore();\n if (!parentCtx) return fn();\n\n const childCtx = { ...parentCtx };\n // NOTE: This is a shallow clone. Array fields (pendingSetCookies,\n // serverInsertedHTMLCallbacks, currentRequestTags, ssrHeadChildren), the\n // _privateCache Map, and object fields (headersContext
|
|
1
|
+
{"version":3,"file":"unified-request-context.js","names":[],"sources":["../../src/shims/unified-request-context.ts"],"sourcesContent":["/**\n * Unified per-request context backed by a single AsyncLocalStorage.\n *\n * Consolidates the 5–6 nested ALS scopes that previously wrapped every\n * App Router request (headers, navigation, cache-state, private-cache,\n * fetch-cache, execution-context) into one flat store.\n *\n * Each shim module checks `isInsideUnifiedScope()` and reads its sub-fields\n * from the unified store, falling back to its own standalone ALS when\n * outside (SSR environment, Pages Router, tests).\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport type {\n CacheState,\n ExecutionContextLike,\n FetchCacheState,\n HeadState,\n I18nState,\n NavigationState,\n PrivateCacheState,\n RouterState,\n VinextHeadersShimState,\n} from \"./request-state-types.js\";\n\n// ---------------------------------------------------------------------------\n// Unified context shape\n// ---------------------------------------------------------------------------\n\n/**\n * Flat union of all per-request state previously spread across\n * VinextHeadersShimState, NavigationState, CacheState, PrivateCacheState,\n * FetchCacheState, and ExecutionContextLike.\n *\n * Each field group is documented with its source shim module.\n */\nexport interface UnifiedRequestContext\n extends\n VinextHeadersShimState,\n I18nState,\n NavigationState,\n CacheState,\n PrivateCacheState,\n FetchCacheState,\n RouterState,\n HeadState {\n // ── request-context.ts ─────────────────────────────────────────────\n /** Cloudflare Workers ExecutionContext, or null on Node.js dev. */\n executionContext: ExecutionContextLike | null;\n\n // ── cache-for-request.ts ──────────────────────────────────────────\n /** Per-request cache for cacheForRequest(). Keyed by factory function reference. */\n requestCache: WeakMap<(...args: any[]) => any, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// ALS setup — stored on globalThis via Symbol.for so all Vite environments\n// (RSC/SSR/client) share the same instance.\n// ---------------------------------------------------------------------------\n\nconst _ALS_KEY = Symbol.for(\"vinext.unifiedRequestContext.als\");\nconst _REQUEST_CONTEXT_ALS_KEY = Symbol.for(\"vinext.requestContext.als\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = (_g[_ALS_KEY] ??=\n new AsyncLocalStorage<UnifiedRequestContext>()) as AsyncLocalStorage<UnifiedRequestContext>;\n\nfunction _getInheritedExecutionContext(): ExecutionContextLike | null {\n const unifiedStore = _als.getStore();\n if (unifiedStore) return unifiedStore.executionContext;\n\n const executionContextAls = _g[_REQUEST_CONTEXT_ALS_KEY] as\n | AsyncLocalStorage<ExecutionContextLike | null>\n | undefined;\n return executionContextAls?.getStore() ?? null;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Create a fresh `UnifiedRequestContext` with defaults for all fields.\n * Pass partial overrides for the fields you need to pre-populate.\n */\nexport function createRequestContext(opts?: Partial<UnifiedRequestContext>): UnifiedRequestContext {\n return {\n headersContext: null,\n dynamicUsageDetected: false,\n pendingSetCookies: [],\n draftModeCookieHeader: null,\n phase: \"render\",\n i18nContext: null,\n serverContext: null,\n serverInsertedHTMLCallbacks: [],\n requestScopedCacheLife: null,\n _privateCache: null,\n currentRequestTags: [],\n executionContext: _getInheritedExecutionContext(), // inherits from standalone ALS if present\n requestCache: new WeakMap(),\n ssrContext: null,\n ssrHeadChildren: [],\n ...opts,\n };\n}\n\n/**\n * Run `fn` within a unified request context scope.\n * All shim modules will read/write their state from `ctx` for the\n * duration of the call, including async continuations.\n */\nexport function runWithRequestContext<T>(\n ctx: UnifiedRequestContext,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n return _als.run(ctx, fn);\n}\n\n/**\n * Run `fn` in a nested unified scope derived from the current request context.\n * Used by legacy runWith* wrappers to reset or override one sub-state while\n * preserving proper async isolation for continuations created inside `fn`.\n * The child scope is a shallow clone of the parent store, so untouched fields\n * keep sharing their existing references while overridden slices can be reset.\n *\n * @internal\n */\nexport function runWithUnifiedStateMutation<T>(\n mutate: (ctx: UnifiedRequestContext) => void,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n const parentCtx = _als.getStore();\n if (!parentCtx) return fn();\n\n const childCtx = { ...parentCtx };\n // NOTE: This is a shallow clone. Array fields (pendingSetCookies,\n // serverInsertedHTMLCallbacks, currentRequestTags, ssrHeadChildren), the\n // _privateCache Map, requestCache WeakMap, and object fields (headersContext,\n // i18nContext, serverContext, ssrContext, executionContext,\n // requestScopedCacheLife) still share references with the parent until\n // replaced. requestCache is intentionally shared — nested scopes within\n // the same request should see the same cached values. The mutate\n // callback must replace those reference-typed slices (for example\n // `ctx.currentRequestTags = []`) rather than mutating them in-place (for\n // example `ctx.currentRequestTags.push(...)`) or the parent scope will\n // observe those changes too. Keep this enumeration in sync with\n // UnifiedRequestContext: when adding a new reference-typed field, add it\n // here too and verify callers still follow the replace-not-mutate rule.\n mutate(childCtx);\n return _als.run(childCtx, fn);\n}\n\n/**\n * Get the current unified request context.\n * Returns the ALS store when inside a `runWithRequestContext()` scope,\n * or a fresh detached context otherwise. Unlike the legacy per-shim fallback\n * singletons, this detached value is ephemeral — mutations do not persist\n * across calls. This is intentional to prevent state leakage outside request\n * scopes.\n *\n * Only direct callers observe this detached fallback. Shim `_getState()`\n * helpers should continue to gate on `isInsideUnifiedScope()` and fall back\n * to their standalone ALS/fallback singletons outside the unified scope.\n * If called inside a standalone `runWithExecutionContext()` scope, the\n * detached context still reflects that inherited `executionContext`.\n */\nexport function getRequestContext(): UnifiedRequestContext {\n return _als.getStore() ?? createRequestContext();\n}\n\n/**\n * Check whether the current execution is inside a `runWithRequestContext()` scope.\n * Shim modules use this to decide whether to read from the unified store\n * or fall back to their own standalone ALS.\n */\nexport function isInsideUnifiedScope(): boolean {\n return _als.getStore() != null;\n}\n"],"mappings":";;;;;;;;;;;;;AA4DA,MAAM,WAAW,OAAO,IAAI,mCAAmC;AAC/D,MAAM,2BAA2B,OAAO,IAAI,4BAA4B;AACxE,MAAM,KAAK;AACX,MAAM,OAAQ,GAAG,cACf,IAAI,mBAA0C;AAEhD,SAAS,gCAA6D;CACpE,MAAM,eAAe,KAAK,UAAU;AACpC,KAAI,aAAc,QAAO,aAAa;AAKtC,QAH4B,GAAG,2BAGH,UAAU,IAAI;;;;;;AAW5C,SAAgB,qBAAqB,MAA8D;AACjG,QAAO;EACL,gBAAgB;EAChB,sBAAsB;EACtB,mBAAmB,EAAE;EACrB,uBAAuB;EACvB,OAAO;EACP,aAAa;EACb,eAAe;EACf,6BAA6B,EAAE;EAC/B,wBAAwB;EACxB,eAAe;EACf,oBAAoB,EAAE;EACtB,kBAAkB,+BAA+B;EACjD,8BAAc,IAAI,SAAS;EAC3B,YAAY;EACZ,iBAAiB,EAAE;EACnB,GAAG;EACJ;;;;;;;AAQH,SAAgB,sBACd,KACA,IACgB;AAChB,QAAO,KAAK,IAAI,KAAK,GAAG;;;;;;;;;;;AAY1B,SAAgB,4BACd,QACA,IACgB;CAChB,MAAM,YAAY,KAAK,UAAU;AACjC,KAAI,CAAC,UAAW,QAAO,IAAI;CAE3B,MAAM,WAAW,EAAE,GAAG,WAAW;AAcjC,QAAO,SAAS;AAChB,QAAO,KAAK,IAAI,UAAU,GAAG;;;;;;;;;;;;;;;;AAiB/B,SAAgB,oBAA2C;AACzD,QAAO,KAAK,UAAU,IAAI,sBAAsB;;;;;;;AAQlD,SAAgB,uBAAgC;AAC9C,QAAO,KAAK,UAAU,IAAI"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vinext",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"description": "Run Next.js apps on Vite. Drop-in replacement for the next CLI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/index.js"
|
|
23
23
|
},
|
|
24
|
+
"./cache": {
|
|
25
|
+
"types": "./dist/cache.d.ts",
|
|
26
|
+
"import": "./dist/cache.js"
|
|
27
|
+
},
|
|
24
28
|
"./shims/*": {
|
|
25
29
|
"types": "./dist/shims/*.d.ts",
|
|
26
30
|
"import": "./dist/shims/*.js"
|
|
@@ -62,8 +66,8 @@
|
|
|
62
66
|
"@types/node": "^25.2.3",
|
|
63
67
|
"@types/react": "^19.2.14",
|
|
64
68
|
"@types/react-dom": "^19.2.3",
|
|
65
|
-
"@vitejs/plugin-react": "^
|
|
66
|
-
"@vitejs/plugin-rsc": "^0.5.
|
|
69
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
70
|
+
"@vitejs/plugin-rsc": "^0.5.21",
|
|
67
71
|
"react-server-dom-webpack": "^19.2.4",
|
|
68
72
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.12",
|
|
69
73
|
"vite-plus": "0.1.12"
|
|
@@ -71,7 +75,7 @@
|
|
|
71
75
|
"peerDependencies": {
|
|
72
76
|
"@mdx-js/rollup": "^3.0.0",
|
|
73
77
|
"@vitejs/plugin-react": "^5.1.4 || ^6.0.0",
|
|
74
|
-
"@vitejs/plugin-rsc": "^0.5.
|
|
78
|
+
"@vitejs/plugin-rsc": "^0.5.21",
|
|
75
79
|
"react": ">=19.2.0",
|
|
76
80
|
"react-dom": ">=19.2.0",
|
|
77
81
|
"react-server-dom-webpack": "^19.2.4",
|