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 ( -
+