Skip to content

Commit ab70c95

Browse files
committed
fix: load turnstile script once
1 parent ed5ca17 commit ab70c95

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

apps/web/app/components/TurnstileWidget.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ export function TurnstileWidget() {
1010
const data = useRouteLoaderData("root") as RootData | undefined;
1111
const siteKey = data?.publicConfig?.turnstileSiteKey;
1212
if (!siteKey) return null;
13-
return (
14-
<>
15-
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer />
16-
<div className="cf-turnstile" data-sitekey={siteKey} data-action="turnstile-spin-v2" />
17-
</>
18-
);
13+
return <div className="cf-turnstile" data-sitekey={siteKey} data-action="turnstile-spin-v2" />;
1914
}
2015

2116
export function getTurnstileToken() {

apps/web/app/root.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function loader({ request }: { request: Request }) {
1717
}
1818

1919
export function Layout({ children }: { children: React.ReactNode }) {
20-
const data = useRouteLoaderData("root") as { publicConfig?: { apiBaseUrl?: string } } | undefined;
20+
const data = useRouteLoaderData("root") as { publicConfig?: { apiBaseUrl?: string; turnstileSiteKey?: string } } | undefined;
2121
const publicConfig = data?.publicConfig || { apiBaseUrl: "https://api.cnodejs.org" };
2222

2323
return (
@@ -32,6 +32,9 @@ export function Layout({ children }: { children: React.ReactNode }) {
3232
/>
3333
<Meta />
3434
<Links />
35+
{publicConfig.turnstileSiteKey ? (
36+
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer />
37+
) : null}
3538
</head>
3639
<body>
3740
{children}

0 commit comments

Comments
 (0)