| 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 : |
import { getOrCreateAls } from "./internal/als-registry.js";
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
import { _registerRouterStateAccessors } from "./router.js";
//#region src/shims/router-state.ts
/**
* Server-only Pages Router state backed by AsyncLocalStorage.
*
* Provides request-scoped isolation for SSR context (pathname, query,
* locale) so concurrent requests on Workers don't share state.
*
* This module is server-only — it imports node:async_hooks and must NOT
* be bundled for the browser.
*/
const _FALLBACK_KEY = Symbol.for("vinext.router.fallback");
const _g = globalThis;
const _als = getOrCreateAls("vinext.router.als");
const _fallbackState = _g[_FALLBACK_KEY] ??= { ssrContext: null };
function _getState() {
if (isInsideUnifiedScope()) return getRequestContext();
return _als.getStore() ?? _fallbackState;
}
function runWithRouterState(fn) {
if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((uCtx) => {
uCtx.ssrContext = null;
}, fn);
return _als.run({ ssrContext: null }, fn);
}
_registerRouterStateAccessors({
getSSRContext() {
return _getState().ssrContext;
},
setSSRContext(ctx) {
_getState().ssrContext = ctx;
}
});
//#endregion
export { runWithRouterState };
//# sourceMappingURL=router-state.js.map