Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(web): load theme script via Next.js Script tag

Richie McIlroy0d855ee25f2b
diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx
index 1b595989d..1eca794d4 100644
--- a/apps/web/app/layout.tsx
+++ b/apps/web/app/layout.tsx
@@ -5,6 +5,7 @@ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import { Effect } from "effect";
import type { Metadata } from "next";
import localFont from "next/font/local";
+import Script from "next/script";
import type { PropsWithChildren } from "react";
import { SonnerToaster } from "@/components/SonnerToastProvider";
import { runPromise } from "@/lib/server";
@@ -22,8 +23,6 @@ import {
SessionProvider,
} from "./Layout/providers";
import { StripeContextProvider } from "./Layout/StripeContext";
-//@ts-expect-error
-import { script } from "./themeScript";
const defaultFont = localFont({
src: [
@@ -107,9 +106,7 @@ export default ({ children }: PropsWithChildren) =>
<meta name="theme-color" content="#ffffff" />
</head>
<body suppressHydrationWarning>
- <script
- dangerouslySetInnerHTML={{ __html: `(${script.toString()})()` }}
- />
+ <Script src="/theme-script.js" strategy="beforeInteractive" />
<TooltipPrimitive.Provider>
<PostHogProvider bootstrapData={bootstrapData}>
<AuthContextProvider user={runPromise(resolveCurrentUser)}>
diff --git a/apps/web/app/themeScript.js b/apps/web/app/themeScript.js
deleted file mode 100644
index 3470ca3d0..000000000
--- a/apps/web/app/themeScript.js
+++ /dev/null
@@ -1,15 +0,0 @@
-export function script() {
- const cookie = (() => {
- if (!document.cookie) return undefined;
- const match = document.cookie.match(/\W?theme=(?<theme>\w+)/);
- return match?.groups?.theme;
- })();
-
- const pathname = window.location.pathname;
- const isDashboardPath =
- pathname.startsWith("/dashboard") ||
- pathname.startsWith("/login") ||
- pathname.startsWith("/onboarding");
-
- if (isDashboardPath) document.body.classList.add(cookie ?? "light");
-}