| 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 { GLOBAL_ACCESSORS_KEY, _registerStateAccessors } from "./navigation.js";
//#region src/shims/navigation-state.ts
/**
* Server-only navigation state backed by AsyncLocalStorage.
*
* This module provides request-scoped isolation for navigation context
* and useServerInsertedHTML callbacks. Without ALS, concurrent requests
* on Cloudflare Workers would share module-level state and leak data
* (pathnames, params, CSS-in-JS styles) between requests.
*
* This module is server-only — it imports node:async_hooks and must NOT
* be bundled for the browser. The dual-environment navigation.ts shim
* uses a registration pattern so it works in both environments.
*/
const _FALLBACK_KEY = Symbol.for("vinext.navigation.fallback");
const _g = globalThis;
const _als = getOrCreateAls("vinext.navigation.als");
const _fallbackState = _g[_FALLBACK_KEY] ??= {
serverContext: null,
serverInsertedHTMLCallbacks: []
};
function _getState() {
if (isInsideUnifiedScope()) return getRequestContext();
return _als.getStore() ?? _fallbackState;
}
function runWithNavigationContext(fn) {
if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((uCtx) => {
uCtx.serverContext = null;
uCtx.serverInsertedHTMLCallbacks = [];
}, fn);
return _als.run({
serverContext: null,
serverInsertedHTMLCallbacks: []
}, fn);
}
function runWithServerInsertedHTMLState(fn) {
if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((uCtx) => {
uCtx.serverInsertedHTMLCallbacks = [];
}, fn);
const state = {
serverContext: (_als.getStore() ?? _fallbackState).serverContext,
serverInsertedHTMLCallbacks: []
};
return _als.run(state, fn);
}
const _accessors = {
getServerContext() {
return _getState().serverContext;
},
setServerContext(ctx) {
_getState().serverContext = ctx;
},
getInsertedHTMLCallbacks() {
return _getState().serverInsertedHTMLCallbacks;
},
clearInsertedHTMLCallbacks() {
_getState().serverInsertedHTMLCallbacks = [];
}
};
_registerStateAccessors(_accessors);
globalThis[GLOBAL_ACCESSORS_KEY] = _accessors;
//#endregion
export { runWithNavigationContext, runWithServerInsertedHTMLState };
//# sourceMappingURL=navigation-state.js.map