From ecfa15cf57fd72962f5eec33285292c0c4f90df6 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Wed, 3 Jan 2024 11:12:23 +0000 Subject: [PATCH] Only call "reattach" when explicitly opening the PDF view (#16330) GitOrigin-RevId: 53d7ef25a58255bdac46011c3d7b7e4d63e65a6c --- .../js/features/ide-react/hooks/use-pdf-pane.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/services/web/frontend/js/features/ide-react/hooks/use-pdf-pane.ts b/services/web/frontend/js/features/ide-react/hooks/use-pdf-pane.ts index dae5401cad..0a232edcbe 100644 --- a/services/web/frontend/js/features/ide-react/hooks/use-pdf-pane.ts +++ b/services/web/frontend/js/features/ide-react/hooks/use-pdf-pane.ts @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useRef } from 'react' +import { useCallback, useRef } from 'react' import { ImperativePanelHandle } from 'react-resizable-panels' import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel' import { useLayoutContext } from '@/shared/context/layout-context' @@ -12,13 +12,6 @@ export const usePdfPane = () => { useCollapsiblePanel(pdfIsOpen, pdfPanelRef) - // close a detached PDF when the detacher PDF view opens - useEffect(() => { - if (pdfIsOpen && detachRole === 'detacher') { - reattach() - } - }, [detachRole, pdfIsOpen, reattach]) - // triggered by a double-click on the resizer const togglePdfPane = useCallback(() => { if (pdfIsOpen) { @@ -32,12 +25,16 @@ export const usePdfPane = () => { const setPdfIsOpen = useCallback( (value: boolean) => { if (value) { + // opening the PDF view, so close a detached PDF + if (detachRole === 'detacher') { + reattach() + } changeLayout('sideBySide') } else { changeLayout('flat', 'editor') } }, - [changeLayout] + [changeLayout, detachRole, reattach] ) // triggered when the PDF pane becomes open