From b471e24cd26fd13c198b1afc1e7ca79283caafba Mon Sep 17 00:00:00 2001 From: Nico <32375741+nulmete@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:09:28 -0300 Subject: [PATCH] Fix: Label shows outdated manually selected host after navigating back to the Edit page (#44216) **Related issue:** Resolves #43135 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] QA'd all new/changed functionality manually ## Summary by CodeRabbit * **Bug Fixes** * Fixed stale "Selected hosts" display on the edit label page by ensuring host data refreshes after successful label edits, so the UI reflects the updated host set immediately. * Fixed stale host selections when navigating between manual labels by scoping and resetting the form to the correct current host set, preventing selections from carrying over between labels. --- changes/43135-fix-stale-label-hosts | 2 ++ frontend/pages/labels/EditLabelPage/EditLabelPage.tsx | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changes/43135-fix-stale-label-hosts diff --git a/changes/43135-fix-stale-label-hosts b/changes/43135-fix-stale-label-hosts new file mode 100644 index 0000000000..7e683a6e30 --- /dev/null +++ b/changes/43135-fix-stale-label-hosts @@ -0,0 +1,2 @@ +* Fixed stale "Selected hosts" on the edit label page after a previous edit by invalidating the related query caches on success. +* Fixed stale "Selected hosts" on the edit label page when navigating between manual labels by scoping the hosts cache per label and keying the form on the actual host set. diff --git a/frontend/pages/labels/EditLabelPage/EditLabelPage.tsx b/frontend/pages/labels/EditLabelPage/EditLabelPage.tsx index b4a7d82168..fba27ba105 100644 --- a/frontend/pages/labels/EditLabelPage/EditLabelPage.tsx +++ b/frontend/pages/labels/EditLabelPage/EditLabelPage.tsx @@ -79,7 +79,7 @@ const EditLabelPage = ({ routeParams, router }: IEditLabelPageProps) => { isLoading: isLoadingHosts, isError: isErrorHosts, } = useQuery( - ["hosts"], + ["hosts", labelId], () => { return labelsAPI.getHostsInLabel(labelId); }, @@ -101,6 +101,8 @@ const EditLabelPage = ({ routeParams, router }: IEditLabelPageProps) => { await labelsAPI.update(labelId, formData); renderFlash("success", "Label updated successfully."); queryClient.invalidateQueries(["label", labelId, currentUser]); + queryClient.invalidateQueries(["hosts", labelId]); + queryClient.invalidateQueries(["labels"]); } catch (error) { const status = (error as { status: number }).status; let errorMessage = "Couldn't edit label. Please try again."; @@ -150,7 +152,10 @@ const EditLabelPage = ({ routeParams, router }: IEditLabelPageProps) => { /> ) : ( h.id) + .sort((a, b) => a - b) + .join(",")}`} defaultName={label.name} defaultDescription={label.description} defaultTargetedHosts={targetedHosts}