Skip to content

Commit 6d081ce

Browse files
committed
fix(ui): fix Copy & Close button not dismissing API key modal
The render-time setState pattern caused an infinite loop: clicking the button set generatedKey to null, but createFetcher.data.key persisted and immediately re-set it during re-render. Replaced with useEffect that only fires when fetcher data changes.
1 parent 4474ef7 commit 6d081ce

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

apps/web/app/routes/settings.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getSession } from "~/lib/auth/session-helpers";
66
import { getDb } from "~/lib/db";
77
import { apiKeys } from "~/lib/db/schema";
88
import { eq, isNull, and } from "drizzle-orm";
9-
import { useState } from "react";
9+
import { useEffect, useState } from "react";
1010

1111
export async function loader({ request, context }: LoaderFunctionArgs) {
1212
const env = context.cloudflare.env as Env;
@@ -83,10 +83,12 @@ export default function Settings() {
8383
setShowNewKeyModal(false);
8484
};
8585

86-
// Show generated key once
87-
if (createFetcher.data?.key && !generatedKey) {
88-
setGeneratedKey(createFetcher.data.key);
89-
}
86+
// Show generated key when fetcher returns a new one
87+
useEffect(() => {
88+
if (createFetcher.data?.key) {
89+
setGeneratedKey(createFetcher.data.key);
90+
}
91+
}, [createFetcher.data]);
9092

9193
const handleDeleteKey = (keyId: string) => {
9294
if (!confirm("Are you sure you want to revoke this API key?")) return;

0 commit comments

Comments
 (0)