Merge pull request #15653 from overleaf/td-ide-page-wait-before-open-doc

React IDE page: open a document after project:joined handling has finished

GitOrigin-RevId: ce48b5fabf7124c37b811b4be132cb28f1eb9857
This commit is contained in:
Tim Down
2023-11-09 09:02:58 +00:00
committed by Copybot
parent 54088acb1b
commit b0ddbbb5f8
3 changed files with 13 additions and 11 deletions
@@ -71,6 +71,7 @@ export function EditorAndSidebar({
openInitialDoc,
} = useEditorManagerContext()
const { view } = useLayoutContext()
const { projectJoined } = useIdeReactContext()
const [, setOpenFile] = useScopeValue<BinaryFile | null>('openFile')
const historyIsOpen = view === 'history'
@@ -143,14 +144,14 @@ export function EditorAndSidebar({
)
}, [openDocId])
// Open a document once the file tree is ready
// Open a document once the file tree and project are ready
const initialOpenDoneRef = useRef(false)
useEffect(() => {
if (fileTreeReady && !initialOpenDoneRef.current) {
if (fileTreeReady && projectJoined && !initialOpenDoneRef.current) {
initialOpenDoneRef.current = true
openInitialDoc(rootDocId)
}
}, [fileTreeReady, openInitialDoc, rootDocId])
}, [fileTreeReady, openInitialDoc, projectJoined, rootDocId])
// Keep the editor file tree around so that it is available and up to date
// when restoring a file