From ca75c02beab0570d6b3146386e9945f6ff1ccc21 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Mon, 27 Nov 2023 11:26:35 +0000 Subject: [PATCH] [ide-react] Ensure that selectEntity is only called when openDocId changes (#15915) GitOrigin-RevId: 22e4e6c83618fcfca5adcbde56e07abda045f251 --- .../ide-react/components/editor-and-sidebar.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/web/frontend/js/features/ide-react/components/editor-and-sidebar.tsx b/services/web/frontend/js/features/ide-react/components/editor-and-sidebar.tsx index 16b51c49d0..f2bea2abbe 100644 --- a/services/web/frontend/js/features/ide-react/components/editor-and-sidebar.tsx +++ b/services/web/frontend/js/features/ide-react/components/editor-and-sidebar.tsx @@ -132,14 +132,19 @@ export function EditorAndSidebar({ [eventEmitter, openDocId, openDocWithId, rootDocId] ) + const openDocIdRef = useRef(null) + // Synchronize the file tree when openDoc or openDocId is called on the editor // manager context from elsewhere. If the file tree does change, it will // trigger the onSelect handler in this component, which will update the local // state. useEffect(() => { - debugConsole.log(`openDocId changed to ${openDocId}`) - if (openDocId !== null) { - selectEntity(openDocId) + if (openDocId !== openDocIdRef.current) { + debugConsole.log(`openDocId changed to ${openDocId}`) + openDocIdRef.current = openDocId + if (openDocId !== null) { + selectEntity(openDocId) + } } }, [openDocId, selectEntity])