diff --git a/client/src/components/production-list-columns/production-list-columns.comment.component.jsx b/client/src/components/production-list-columns/production-list-columns.comment.component.jsx index 43d27c40a..10d084cb7 100644 --- a/client/src/components/production-list-columns/production-list-columns.comment.component.jsx +++ b/client/src/components/production-list-columns/production-list-columns.comment.component.jsx @@ -12,6 +12,7 @@ export default function ProductionListColumnComment({ record, usePortal = false const [note, setNote] = useState(record.comment || ""); const [open, setOpen] = useState(false); const textAreaRef = useRef(null); + const rafIdRef = useRef(null); const [updateAlert] = useMutation(UPDATE_JOB); @@ -37,14 +38,21 @@ export default function ProductionListColumnComment({ record, usePortal = false }; const handleOpenChange = (flag) => { + if (rafIdRef.current) { + cancelAnimationFrame(rafIdRef.current); + rafIdRef.current = null; + } setOpen(flag); if (flag) { setNote(record.comment || ""); - requestAnimationFrame(() => { - try { - textAreaRef.current?.focus?.({ preventScroll: true }); - } catch { - textAreaRef.current?.focus?.(); + rafIdRef.current = requestAnimationFrame(() => { + rafIdRef.current = null; + if (textAreaRef.current?.focus) { + try { + textAreaRef.current.focus({ preventScroll: true }); + } catch { + textAreaRef.current.focus(); + } } }); } diff --git a/client/src/components/production-list-columns/production-list-columns.productionnote.component.jsx b/client/src/components/production-list-columns/production-list-columns.productionnote.component.jsx index ea85f3dcc..21d129adc 100644 --- a/client/src/components/production-list-columns/production-list-columns.productionnote.component.jsx +++ b/client/src/components/production-list-columns/production-list-columns.productionnote.component.jsx @@ -21,6 +21,7 @@ function ProductionListColumnProductionNote({ record, setNoteUpsertContext, useP const [note, setNote] = useState(record.production_vars?.note || ""); const [open, setOpen] = useState(false); const textAreaRef = useRef(null); + const rafIdRef = useRef(null); const [updateAlert] = useMutation(UPDATE_JOB); @@ -53,14 +54,21 @@ function ProductionListColumnProductionNote({ record, setNoteUpsertContext, useP const handleOpenChange = useCallback( (flag) => { + if (rafIdRef.current) { + cancelAnimationFrame(rafIdRef.current); + rafIdRef.current = null; + } setOpen(flag); if (flag) { setNote(record.production_vars?.note || ""); - requestAnimationFrame(() => { - try { - textAreaRef.current?.focus?.({ preventScroll: true }); - } catch { - textAreaRef.current?.focus?.(); + rafIdRef.current = requestAnimationFrame(() => { + rafIdRef.current = null; + if (textAreaRef.current?.focus) { + try { + textAreaRef.current.focus({ preventScroll: true }); + } catch { + textAreaRef.current.focus(); + } } }); }