mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
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:
committed by
Copybot
parent
3980b9e580
commit
6538c00742
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user