From 876283ddee28a1acc4dcc0a9272bb68c3b2c8fc1 Mon Sep 17 00:00:00 2001 From: kim Date: Thu, 4 Apr 2024 13:50:42 +0200 Subject: [PATCH] fix: fix shortcut navigation crash --- src/modules/navigation/ItemNavigation.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/modules/navigation/ItemNavigation.tsx b/src/modules/navigation/ItemNavigation.tsx index 7c9d44928..12696abe5 100644 --- a/src/modules/navigation/ItemNavigation.tsx +++ b/src/modules/navigation/ItemNavigation.tsx @@ -1,3 +1,4 @@ +import { useEffect, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { Alert } from '@mui/material'; @@ -20,6 +21,11 @@ const { useItem, useDescendants, useItemsTags } = hooks; const DrawerNavigation = (): JSX.Element | null => { const { rootId, itemId } = useParams(); const navigate = useNavigate(); + const [prevRootId, setPrevRootId] = useState(rootId); + + useEffect(() => { + setPrevRootId(rootId); + }, [rootId]); const { t: translateMessage } = useMessagesTranslation(); @@ -32,6 +38,14 @@ const DrawerNavigation = (): JSX.Element | null => { navigate(buildContentPagePath({ rootId, itemId: newItemId })); }; + // on root change, we need to destroy the tree + // since it keeps the same data on reload despite prop changes + // we cannot rely on isLoading because the data is taken from the cache + // bc of our query client optimization + if (prevRootId !== rootId) { + return ; + } + if (rootItem) { if (rootItem.id === rootId) { return ( @@ -50,7 +64,6 @@ const DrawerNavigation = (): JSX.Element | null => { ); } - console.log('switching'); return ; }