🐛(frontend) avoid full doc-tree reload on drag-and-drop move

Moving a doc via drag-and-drop already applies the move locally through
`treeData.handleMove`, but `useMoveDoc`'s `onSuccess` also
invalidated the `KEY_DOC_TREE` query, which `useDocTree`
reacts to by nulling `treeContext.root` and forcing the whole tree to
refetch and remount. Add a `skipTreeInvalidation`
option so the drag-and-drop handler can skip that invalidation
and rely on its own local update, while other callers (e.g. the
move modal) keep reloading the tree as before.
This commit is contained in:
Anthony LC
2026-09-14 15:55:24 +02:00
parent 9e0733f8df
commit bee6833c06
2 changed files with 5 additions and 1 deletions
@@ -15,6 +15,7 @@ export type MoveDocParam = {
sourceDocumentId: string;
targetDocumentId: string;
position: TreeViewMoveModeEnum;
skipTreeInvalidation?: boolean;
};
export const moveDoc = async ({
@@ -48,7 +49,9 @@ export function useMoveDoc(options?: UseMoveDocOptions) {
onSuccess(data, variables, onMutateResult, context) {
void queryClient.invalidateQueries({ queryKey: [KEY_LIST_DOC] });
void queryClient.invalidateQueries({ queryKey: [KEY_DOC] });
void queryClient.invalidateQueries({ queryKey: [KEY_DOC_TREE] });
if (!variables.skipTreeInvalidation) {
void queryClient.invalidateQueries({ queryKey: [KEY_DOC_TREE] });
}
if (options?.onSuccess) {
void options.onSuccess(data, variables, onMutateResult, context);
@@ -58,6 +58,7 @@ export const DocTreeSubpages = memo(function DocTreeSubpages({
sourceDocumentId: result.sourceId,
targetDocumentId: result.targetModeId,
position: result.mode,
skipTreeInvalidation: true,
});
treeContext?.treeData.handleMove(result);