| Server IP : 159.203.156.69 / Your IP : 216.73.217.172 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/vinext/dist/shims/ |
Upload File : |
{"version":3,"file":"router-state.js","names":[],"sources":["../../src/shims/router-state.ts"],"sourcesContent":["/**\n * Server-only Pages Router state backed by AsyncLocalStorage.\n *\n * Provides request-scoped isolation for SSR context (pathname, query,\n * locale) so concurrent requests on Workers don't share state.\n *\n * This module is server-only — it imports node:async_hooks and must NOT\n * be bundled for the browser.\n */\n\nimport { _registerRouterStateAccessors } from \"./router.js\";\nimport { getOrCreateAls } from \"./internal/als-registry.js\";\nimport {\n getRequestContext,\n isInsideUnifiedScope,\n runWithUnifiedStateMutation,\n} from \"./unified-request-context.js\";\n\n// ---------------------------------------------------------------------------\n// ALS setup\n// ---------------------------------------------------------------------------\n\nexport type SSRContext = {\n pathname: string;\n query: Record<string, string | string[]>;\n asPath: string;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n};\n\nexport type RouterState = {\n ssrContext: SSRContext | null;\n};\n\nconst _FALLBACK_KEY = Symbol.for(\"vinext.router.fallback\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = getOrCreateAls<RouterState>(\"vinext.router.als\");\n\nconst _fallbackState = (_g[_FALLBACK_KEY] ??= {\n ssrContext: null,\n} satisfies RouterState) as RouterState;\n\nfunction _getState(): RouterState {\n if (isInsideUnifiedScope()) {\n return getRequestContext();\n }\n return _als.getStore() ?? _fallbackState;\n}\n\n/**\n * Run a function within a router state ALS scope.\n * Ensures per-request isolation for Pages Router SSR context\n * on concurrent runtimes.\n */\nexport function runWithRouterState<T>(fn: () => Promise<T>): Promise<T>;\nexport function runWithRouterState<T>(fn: () => T | Promise<T>): T | Promise<T>;\nexport function runWithRouterState<T>(fn: () => T | Promise<T>): T | Promise<T> {\n if (isInsideUnifiedScope()) {\n return runWithUnifiedStateMutation((uCtx) => {\n uCtx.ssrContext = null;\n }, fn);\n }\n\n const state: RouterState = {\n ssrContext: null,\n };\n return _als.run(state, fn);\n}\n\n// ---------------------------------------------------------------------------\n// Register ALS-backed accessors into router.ts\n// ---------------------------------------------------------------------------\n\n_registerRouterStateAccessors({\n getSSRContext(): SSRContext | null {\n return _getState().ssrContext;\n },\n\n setSSRContext(ctx: SSRContext | null): void {\n _getState().ssrContext = ctx;\n },\n});\n"],"mappings":";;;;;;;;;;;;;AAmCA,MAAM,gBAAgB,OAAO,IAAI,yBAAyB;AAC1D,MAAM,KAAK;AACX,MAAM,OAAO,eAA4B,oBAAoB;AAE7D,MAAM,iBAAkB,GAAG,mBAAmB,EAC5C,YAAY,MACb;AAED,SAAS,YAAyB;CAChC,IAAI,sBAAsB,EACxB,OAAO,mBAAmB;CAE5B,OAAO,KAAK,UAAU,IAAI;;AAU5B,SAAgB,mBAAsB,IAA0C;CAC9E,IAAI,sBAAsB,EACxB,OAAO,6BAA6B,SAAS;EAC3C,KAAK,aAAa;IACjB,GAAG;CAMR,OAAO,KAAK,IAAI,EAFd,YAAY,MAEO,EAAE,GAAG;;AAO5B,8BAA8B;CAC5B,gBAAmC;EACjC,OAAO,WAAW,CAAC;;CAGrB,cAAc,KAA8B;EAC1C,WAAW,CAAC,aAAa;;CAE5B,CAAC"}