refactor(ui): remove circular dependency in cookieUtils.ts

Derive the UI cookie path from window.location.pathname instead of
importing serverRootPath from networking.tsx. This breaks the
cookieUtils → networking → cookieUtils cycle that could cause
serverRootPath to be undefined under certain bundler configurations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hendrik Jaks 2026-03-20 00:07:06 +02:00
parent bd878e742e
commit 40eaab5693

View file

@ -1,16 +1,18 @@
/**
* Utility functions for managing cookies
*/
import { serverRootPath } from "@/components/networking";
/**
* Returns the cookie path for the UI.
* Respects server_root_path so the cookie works when LiteLLM is
* deployed behind a subpath (e.g. /myapp/ui instead of /ui).
* Derives the path from window.location.pathname so it works when
* LiteLLM is deployed behind a subpath (e.g. /myapp/ui instead of /ui).
* No imports from networking.tsx to avoid circular dependencies.
*/
function getUiCookiePath(): string {
const root = serverRootPath === "/" ? "" : serverRootPath;
return `${root}/ui`;
if (typeof window === "undefined") return "/ui";
const idx = window.location.pathname.indexOf("/ui");
if (idx >= 0) return window.location.pathname.substring(0, idx + 3);
return "/ui";
}
/**