From 9b0672c2a094f9df083f762e5de811748208e0eb Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 12:06:16 -0700 Subject: [PATCH] perf: clean diff section model cleanup from effect (#3704) --- .../src/components/editor/DiffSectionItem.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/components/editor/DiffSectionItem.tsx b/src/renderer/src/components/editor/DiffSectionItem.tsx index fe9d47aed..836806eca 100644 --- a/src/renderer/src/components/editor/DiffSectionItem.tsx +++ b/src/renderer/src/components/editor/DiffSectionItem.tsx @@ -148,6 +148,17 @@ export function DiffSectionItem({ } }, 0) }, [modelPathBase]) + const disposeDiffModelsRef = useRef(disposeDiffModels) + disposeDiffModelsRef.current = disposeDiffModels + + const setSectionRootNode = useCallback((node: HTMLDivElement | null): void => { + if (node) { + return + } + // Why: virtualized diff rows remount as their keyed section/collapse state + // changes; the row root is the owner of the detached Monaco models. + disposeDiffModelsRef.current() + }, []) useEffect(() => { if (section.collapsed) { @@ -155,8 +166,6 @@ export function DiffSectionItem({ } }, [disposeDiffModels, section.collapsed]) - useEffect(() => () => disposeDiffModels(), [disposeDiffModels]) - // Why: only forward the pending scroll id when it matches a comment in this // section so unrelated sections don't keep re-rendering their decorator // every time the sidebar requests a scroll elsewhere. @@ -418,7 +427,7 @@ export function DiffSectionItem({ }, [index, loadSection]) return ( -
+