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: usePatchUpdateFlow to conditionally refetch queries based on the browser URL #3915

Merged
merged 8 commits into from
Sep 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { track } from "@/customization/utils/analytics";
import useAutoSaveFlow from "@/hooks/flows/use-autosave-flow";
import useUploadFlow from "@/hooks/flows/use-upload-flow";
import { getNodeRenderType, isSupportedNodeTypes } from "@/utils/utils";

import _, { cloneDeep } from "lodash";
import {
KeyboardEvent,
Expand Down
11 changes: 9 additions & 2 deletions src/frontend/src/pages/MainPage/pages/mainPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useDeleteFolders } from "@/controllers/API/queries/folders";
import { useCustomNavigate } from "@/customization/hooks/use-custom-navigate";
import { track } from "@/customization/utils/analytics";
import useAlertStore from "@/stores/alertStore";
import { useIsFetching } from "@tanstack/react-query";
import { useState } from "react";
import { useIsFetching, useQueryClient } from "@tanstack/react-query";
import { useEffect, useState } from "react";
import { Outlet, useLocation } from "react-router-dom";
import DropdownButton from "../../../../components/dropdownButtonComponent";
import PageLayout from "../../../../components/pageLayout";
Expand All @@ -28,6 +28,13 @@ export default function HomePage(): JSX.Element {
const setSuccessData = useAlertStore((state) => state.setSuccessData);
const setErrorData = useAlertStore((state) => state.setErrorData);
const folderToEdit = useFolderStore((state) => state.folderToEdit);
const queryClient = useQueryClient();

// cleanup the query cache when the component unmounts
// prevent unnecessary queries on flow update
useEffect(() => {
return () => queryClient.removeQueries({ queryKey: ["useGetFolder"] });
}, []);

const dropdownOptions = useDropdownOptions({
navigate,
Expand Down
Loading