Skip to content

Fix stale data on host details page after subsequent navigations#40603

Merged
nulmete merged 1 commit intomainfrom
nulmete/tweak-refetch-props-host-details-page
Feb 26, 2026
Merged

Fix stale data on host details page after subsequent navigations#40603
nulmete merged 1 commit intomainfrom
nulmete/tweak-refetch-props-host-details-page

Conversation

@nulmete
Copy link
Copy Markdown
Member

@nulmete nulmete commented Feb 26, 2026

Related issue: Resolves #40408

Part of the root cause for this issue is this commit: 5136d40

In summary, I moved the QueryClient instantiation out of AppWrapper because it needs to be a stable reference. I realized this was necessary when manipulating react-query's cache as part of that work.
(I was debugging react-query's cache using getQueryData and it was always returning undefined for every entry -- that was fixed by doing what I described just above).

When QueryClient was re-created on each AppWrapper mount, refetchOnMount: false had no effect.. there was never cached data to serve, so useQuery always fetched on every navigation to the host details page.

After moving it out of AppWrapper, refetchOnMount: false works as expected and the cached (stale) data is served instead of refetching.

The fix removes the refetchOnMount: false, refetchOnReconnect: false, and refetchOnWindowFocus: false overrides, restoring react-query's defaults so data is refreshed on navigation, tab focus, and reconnect.

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

Testing

  • QA'd all new/changed functionality manually
Screen.Recording.2026-02-26.at.1.19.56.PM.mov

For unreleased bug fixes in a release candidate, one of:

  • Confirmed that the fix is not expected to adversely impact load test results
  • Alerted the release DRI if additional load testing is needed

() => hostAPI.getMdm(hostIdFromURL),
{
enabled: !!hostIdFromURL,
refetchOnMount: false,
Copy link
Copy Markdown
Member Author

@nulmete nulmete Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing refetchOnMount: false is the fix.

However, I decided to remove all refetchXXX: false props

IMO, it's good UX to have data sync after users had the tab opened for a long time and they come back (e.g. if they switched to another task).

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.28%. Comparing base (277c7c3) to head (9ef3db9).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #40603   +/-   ##
=======================================
  Coverage   66.28%   66.28%           
=======================================
  Files        2466     2466           
  Lines      197534   197534           
  Branches     8638     8638           
=======================================
  Hits       130945   130945           
  Misses      54739    54739           
  Partials    11850    11850           
Flag Coverage Δ
frontend 54.07% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nulmete nulmete marked this pull request as ready for review February 26, 2026 16:16
@nulmete nulmete requested a review from a team as a code owner February 26, 2026 16:16
@nulmete nulmete merged commit 3ab49e4 into main Feb 26, 2026
17 checks passed
@nulmete nulmete deleted the nulmete/tweak-refetch-props-host-details-page branch February 26, 2026 17:12
nulmete added a commit that referenced this pull request Feb 26, 2026
)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #40408

Part of the root cause for this issue is this commit:
5136d40

In summary, I moved the QueryClient instantiation out of AppWrapper
because it needs to be a stable reference. I realized this was necessary
when manipulating react-query's cache as part of that work.
(I was debugging react-query's cache using **getQueryData** and it was
always returning **undefined** for every entry -- that was fixed by
doing what I described just above).

When QueryClient was re-created on each AppWrapper mount,
refetchOnMount: false had no effect.. there was never cached data to
serve, so useQuery always fetched on every navigation to the host
details page.

After moving it out of AppWrapper, refetchOnMount: false works as
expected and the cached (stale) data is served instead of refetching.

The fix removes the refetchOnMount: false, refetchOnReconnect: false,
and refetchOnWindowFocus: false overrides, restoring react-query's
defaults so data is refreshed on navigation, tab focus, and reconnect.

# Checklist for submitter

- [ ] 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



https://github.com/user-attachments/assets/fa3f90ef-46f4-4a30-acc6-2176a22e8299



For unreleased bug fixes in a release candidate, one of:

- [x] Confirmed that the fix is not expected to adversely impact load
test results
- [ ] Alerted the release DRI if additional load testing is needed
nulmete added a commit that referenced this pull request Feb 26, 2026
Cherry-picking fixes for #40608 and #40603 (already merged to main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Newly created policy does not appear until refresh

2 participants