Merge pull request #33690 from overleaf/mj-prune-deleted-tabs

[web] Prune non-existent tabs when file tree changes

GitOrigin-RevId: 97e68a88a201acc2d1e582911ca64e1f72f9bfe1
This commit is contained in:
Mathias Jakobsen
2026-05-15 08:08:19 +00:00
committed by Copybot
parent 3980b9e580
commit 6538c00742
2 changed files with 45 additions and 0 deletions
@@ -241,6 +241,24 @@ export const TabsProvider: FC<React.PropsWithChildren> = ({ children }) => {
})
}, [openEntity, previewTabs, setOpenTabs, tabsEnabled])
useEffect(() => {
if (!tabsEnabled) {
return
}
// Make sure file tree is ready for lookup before pruning tabs, to avoid
// accidentally closing tabs that are still valid but not yet available
if (!fileTreeData?._id) {
return
}
setOpenTabs(current => {
const pruned = current.filter(tab => findInTree(fileTreeData, tab.id))
if (pruned.length === current.length) {
return current
}
return pruned
})
}, [fileTreeData, setOpenTabs, tabsEnabled])
const value = useMemo(
() => ({
tabs,