Fix timeout leak in copy-to-clipboard handler

Rapid clicks on the copy button accumulated setTimeout callbacks that
continued firing after component unmount. Clear the previous timer
before setting a new one, and clean up on unmount.
This commit is contained in:
rcourtman 2026-06-27 15:22:48 +01:00
parent e7de730c71
commit ad645b2ef6

View file

@ -94,10 +94,15 @@ export const AgentIntegrationsPanel: Component = () => {
() => surfaceContractEntries().length > 0 || hasManifestInventory(),
);
let copySnippetTimer: ReturnType<typeof setTimeout> | undefined;
const handleCopySnippet = (snippet: string) => {
setCopied(snippet);
window.setTimeout(() => setCopied(null), 2000);
if (copySnippetTimer) clearTimeout(copySnippetTimer);
copySnippetTimer = setTimeout(() => setCopied(null), 2000);
};
onCleanup(() => {
if (copySnippetTimer) clearTimeout(copySnippetTimer);
});
const readRouteHash = () => (typeof window === 'undefined' ? '' : window.location.hash);