Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix tree crash bug #603

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/modules/navigation/ItemNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';

import { Alert } from '@mui/material';
Expand All @@ -19,6 +20,11 @@ const { useItem, useDescendants, useItemsTags } = hooks;
const DrawerNavigation = (): JSX.Element | null => {
const rootId = useParams()[ROOT_ID_PATH];
const navigate = useNavigate();
const [prevRootId, setPrevRootId] = useState(rootId);

useEffect(() => {
setPrevRootId(rootId);
}, [rootId]);

const { t: translateMessage } = useMessagesTranslation();

Expand All @@ -30,6 +36,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 <LoadingTree />;
}

if (rootItem) {
return (
<MainMenu id={MAIN_MENU_ID}>
Expand Down