mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-07-09 16:00:59 +00:00
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:
parent
e7de730c71
commit
ad645b2ef6
1 changed files with 6 additions and 1 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue