Skip to content

Commit 8680803

Browse files
refactor(web): keep form-save and clipboard timer cleanup in plain effects
Review pushback: unmount cleanup is ordinary lifetime cleanup, so it stays in an effect rather than a form ref callback, and the clipboard timer is cleared on unmount again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 576fda3 commit 8680803

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎apps/web/src/components/projectScriptEditor.tsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
PlayIcon,
2020
WrenchIcon,
2121
} from "lucide-react";
22-
import React, { type FormEvent, type KeyboardEvent, useRef, useState } from "react";
22+
import React, { type FormEvent, type KeyboardEvent, useEffect, useRef, useState } from "react";
2323

2424
import {
2525
keybindingValueForCommand,
@@ -282,9 +282,12 @@ function ProjectScriptEditorForm({
282282
const pendingSubmissionRef = useRef<object | null>(null);
283283
// A save that settles after this form is replaced must not close or error
284284
// the request that replaced it.
285-
const releasePendingSubmission = () => () => {
286-
pendingSubmissionRef.current = null;
287-
};
285+
useEffect(
286+
() => () => {
287+
pendingSubmissionRef.current = null;
288+
},
289+
[],
290+
);
288291

289292
const isEditing = request.scriptId != null;
290293

@@ -402,7 +405,7 @@ function ProjectScriptEditorForm({
402405
</DialogDescription>
403406
</DialogHeader>
404407
<DialogPanel>
405-
<form id={formId} ref={releasePendingSubmission} onSubmit={submit}>
408+
<form id={formId} onSubmit={submit}>
406409
<fieldset className="space-y-4" disabled={isSaving || !canEditActions}>
407410
<div className="space-y-1.5">
408411
<Label htmlFor="script-name">Name</Label>

‎apps/web/src/hooks/useCopyToClipboard.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,13 @@ export function useCopyToClipboard<TContext = void>({
232232
);
233233
});
234234

235+
React.useEffect(() => {
236+
return (): void => {
237+
if (timeoutIdRef.current) {
238+
clearTimeout(timeoutIdRef.current);
239+
}
240+
};
241+
}, []);
242+
235243
return { copyToClipboard, isCopied };
236244
}

0 commit comments

Comments
 (0)