Files
edr-platform/apps/edr-freight-web/portal/src/main.tsx
2026-08-10 12:00:29 +03:00

67 lines
2.5 KiB
TypeScript

// Must stay the first import: pins all date/time display to EAT before any
// module can create a formatter in the PC's local timezone.
import "@edr/ui-common/display-timezone";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { BrowserRouter } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { MantineProvider } from "@mantine/core";
import posthog from "posthog-js";
import { PostHogProvider, PostHogErrorBoundary } from "@posthog/react";
import "@mantine/core/styles.css";
import "@mantine/dates/styles.css";
import "@edr/ui-common/styles.css";
import "../index.css";
import "@edr/ui-common/theme.css";
import { Toaster } from "react-hot-toast";
import { mantineTheme } from "./theme/mantine";
import { initPostHog } from "./lib/posthog";
import { AppErrorFallback } from "./components/errors/AppErrorFallback";
import App from "./App";
// Purge cookies that were stored as the literal string "undefined" before the
// envelope interceptor fix. Without this, stale sessions would keep sending
// "Authorization: Bearer undefined" and get 401 JsonWebTokenError forever.
["auth-token", "refresh-token"].forEach((name) => {
const entry = document.cookie
.split("; ")
.find((c) => c.startsWith(`${name}=`));
const value = entry?.split("=").slice(1).join("=");
if (value === "undefined" || value === "null" || value === "") {
document.cookie = `${name}=; Max-Age=0; path=/`;
}
});
// Must run before render so replay and exception capture cover startup errors.
// No-ops when VITE_POSTHOG_KEY is unset.
initPostHog();
const queryClient = new QueryClient();
const rootElement = document.getElementById("root");
if (!rootElement) {
throw new Error("Root element not found");
}
createRoot(document.getElementById("root")!).render(
<StrictMode>
<PostHogProvider client={posthog}>
{/* forceColorScheme (not defaultColorScheme) — the app is light-only.
`default` still lets Mantine flip to dark via useMantineColorScheme
or a persisted color-scheme value; `force` pins it. */}
<MantineProvider theme={mantineTheme} forceColorScheme="light">
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<PostHogErrorBoundary fallback={<AppErrorFallback />}>
<App />
</PostHogErrorBoundary>
<Toaster position="top-right" />
</BrowserRouter>
</QueryClientProvider>
</MantineProvider>
</PostHogProvider>
</StrictMode>,
);