Skip to content

Comments

fix(dashboard): prevent stale favorite status errors after navigation#38156

Open
rusackas wants to merge 2 commits intomasterfrom
fix/stale-dashboard-favorite-status-32533
Open

fix(dashboard): prevent stale favorite status errors after navigation#38156
rusackas wants to merge 2 commits intomasterfrom
fix/stale-dashboard-favorite-status-32533

Conversation

@rusackas
Copy link
Member

SUMMARY

Fixes a race condition where navigating between dashboards could show error toasts for dashboards the user is no longer viewing.

The Problem:
When a user:

  1. Creates a dashboard (e.g., ID 258)
  2. Deletes that dashboard
  3. Navigates to another dashboard (e.g., ID 55)

The favorite_status API call for the deleted dashboard (258) would complete and show an error toast: "There was an issue fetching the favorite status of this dashboard." This is confusing because the user is now viewing a different dashboard.

Root Cause:
The fetchFaveStar and saveFaveStar Redux thunks would dispatch actions (including error toasts) regardless of whether the requested dashboard ID still matched the currently viewed dashboard. This allowed stale API responses to affect the UI after navigation.

The Fix:
Before dispatching any actions in the thunk callbacks, check if dashboardInfo.id from the current Redux state matches the id that was originally requested. If they don't match, the response is stale and should be silently ignored.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:
When navigating from a deleted dashboard to another dashboard, error toasts would appear for the deleted dashboard.

After:
Stale responses are silently ignored, preventing confusing error messages.

TESTING INSTRUCTIONS

  1. Create a new dashboard and save it
  2. Note the dashboard ID from the URL
  3. Delete the dashboard
  4. Navigate to any other dashboard
  5. Verify no error toast appears about "fetching the favorite status"

Alternative test (without deletion):

  1. Open Network tab in DevTools
  2. Add throttling to simulate slow network
  3. Navigate from one dashboard to another quickly
  4. Verify no duplicate/stale favorite status updates occur

ADDITIONAL INFORMATION

🤖 Generated with Claude Code

@dosubot
Copy link

dosubot bot commented Feb 21, 2026

Related Documentation

Checked 0 published document(s) in 2 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Feb 21, 2026

Code Review Agent Run #bbdc61

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: f999177..f999177
    • superset-frontend/src/dashboard/actions/dashboardState.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot bot added the dashboard Namespace | Anything related to the Dashboard label Feb 21, 2026
@codeant-ai-for-open-source
Copy link
Contributor

Sequence Diagram

The PR updates favorite-status thunks to ignore API responses unless the requested dashboard ID still matches the currently viewed dashboard, preventing stale state updates or error toasts after navigation.

sequenceDiagram
    participant Dashboard UI
    participant Thunk
    participant Superset API
    participant Redux Store

    Dashboard UI->>Thunk: fetchFaveStar(id) / saveFaveStar(id, isStarred)
    Thunk->>Superset API: call favorite_status or favorites endpoint
    Superset API-->>Thunk: response (success or error)

    alt response for current dashboard (ids match)
        Thunk->>Redux Store: dispatch state update or addDangerToast
        Redux Store-->>Dashboard UI: updated favorite state or error toast
    else stale response (ids differ)
        Thunk-->>Thunk: silently ignore response (no dispatch)
        Note right of Thunk: prevents toasts/state changes for old dashboard
    end
Loading

Generated by CodeAnt AI

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Feb 21, 2026

Code Review Agent Run #d52fee

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: f999177..3fa9597
    • superset-frontend/src/dashboard/actions/dashboardState.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a race condition where navigating between dashboards could show error toasts for dashboards the user is no longer viewing. The fix prevents stale API responses from affecting the UI by checking if the requested dashboard ID matches the currently viewed dashboard ID before dispatching actions or showing error messages.

Changes:

  • Modified fetchFaveStar thunk to check if the dashboard ID is still current before dispatching actions or error toasts
  • Modified saveFaveStar thunk with the same stale response protection
  • Both functions now accept getState parameter to access current dashboard state

Comment on lines 162 to 196
export function fetchFaveStar(id: number) {
return function fetchFaveStarThunk(dispatch: AppDispatch) {
return function fetchFaveStarThunk(
dispatch: AppDispatch,
getState: GetState,
) {
return SupersetClient.get({
endpoint: `/api/v1/dashboard/favorite_status/?q=${rison.encode([id])}`,
})
.then(({ json }: { json: JsonObject }) => {
dispatch(toggleFaveStar(!!(json?.result as JsonObject[])?.[0]?.value));
// Only update state if this is still the current dashboard
// This prevents stale responses from affecting the UI after navigation
const currentId = getState().dashboardInfo?.id;
if (currentId === id) {
dispatch(
toggleFaveStar(!!(json?.result as JsonObject[])?.[0]?.value),
);
}
})
.catch(() =>
dispatch(
addDangerToast(
t(
'There was an issue fetching the favorite status of this dashboard.',
.catch(() => {
// Only show error if this is still the current dashboard
// This prevents error toasts from appearing for dashboards the user
// has already navigated away from (e.g., deleted dashboards)
const currentId = getState().dashboardInfo?.id;
if (currentId === id) {
dispatch(
addDangerToast(
t(
'There was an issue fetching the favorite status of this dashboard.',
),
),
),
),
);
);
}
});
};
}
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The race condition fix in fetchFaveStar should be covered by tests to ensure the stale response handling works correctly. The test should verify that when the dashboard ID changes between the API call and the response, no state updates or error toasts are dispatched. This is a critical behavior change that prevents user-facing bugs.

Consider adding test cases that:

  1. Verify actions are dispatched when dashboard ID matches
  2. Verify actions are NOT dispatched when dashboard ID changes (the race condition scenario)
  3. Cover both success and error response paths

The file superset-frontend/src/dashboard/actions/dashboardState.test.ts already has comprehensive tests for other thunks like saveDashboardRequest and would be the appropriate location for these tests.

Copilot uses AI. Check for mistakes.
Comment on lines 198 to 225
@@ -190,13 +206,21 @@ export function saveFaveStar(id: number, isStarred: boolean) {

return apiCall
.then(() => {
dispatch(toggleFaveStar(!isStarred));
// Only update state if this is still the current dashboard
const currentId = getState().dashboardInfo?.id;
if (currentId === id) {
dispatch(toggleFaveStar(!isStarred));
}
})
.catch(() =>
dispatch(
addDangerToast(t('There was an issue favoriting this dashboard.')),
),
);
.catch(() => {
// Only show error if this is still the current dashboard
const currentId = getState().dashboardInfo?.id;
if (currentId === id) {
dispatch(
addDangerToast(t('There was an issue favoriting this dashboard.')),
);
}
});
};
}
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The race condition fix in saveFaveStar should be covered by tests to ensure the stale response handling works correctly. The test should verify that when the dashboard ID changes between the API call and the response, no state updates or error toasts are dispatched. This is a critical behavior change that prevents user-facing bugs.

Consider adding test cases that:

  1. Verify actions are dispatched when dashboard ID matches
  2. Verify actions are NOT dispatched when dashboard ID changes (the race condition scenario)
  3. Cover both success and error response paths

The file superset-frontend/src/dashboard/actions/dashboardState.test.ts already has comprehensive tests for other thunks like saveDashboardRequest and would be the appropriate location for these tests.

Copilot uses AI. Check for mistakes.
rusackas and others added 2 commits February 22, 2026 12:33
When navigating between dashboards, the previous dashboard's favorite_status
API call could complete after the new dashboard loaded. If the previous
dashboard had been deleted, this would show an error toast for a dashboard
the user is no longer viewing.

This fix checks if the requested dashboard ID still matches the current
dashboard before dispatching actions (updating state or showing errors).
This prevents stale responses from affecting the UI after navigation.

Fixes #32533

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rusackas rusackas force-pushed the fix/stale-dashboard-favorite-status-32533 branch from 3fa9597 to 62e06ec Compare February 22, 2026 20:36
@codeant-ai-for-open-source
Copy link
Contributor

Sequence Diagram

Shows how favorite-status thunks now verify the current dashboard ID from Redux state before updating UI or showing error toasts, preventing stale API responses from affecting a newly viewed dashboard.

sequenceDiagram
    participant DashboardView
    participant ReduxThunk
    participant SupersetAPI
    participant ReduxState

    DashboardView->>ReduxThunk: fetchFaveStar(id) / saveFaveStar(id, ...)
    ReduxThunk->>SupersetAPI: call favorite_status or favorites endpoint
    SupersetAPI-->>ReduxThunk: response (success or error)
    ReduxThunk->>ReduxState: read dashboardInfo.id (currentId)
    alt currentId === requested id
        ReduxThunk-->>DashboardView: dispatch toggleFaveStar or addDangerToast
    else stale response (IDs differ)
        ReduxThunk-->>ReduxState: silently ignore response (no dispatch)
    end
Loading

Generated by CodeAnt AI

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Feb 22, 2026

Code Review Agent Run #e6c081

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: f3ed5cb..62e06ec
    • superset-frontend/src/dashboard/actions/dashboardState.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboard Namespace | Anything related to the Dashboard size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When loading a dashboard, an error associated with a previously deleted dashboard pops up.

1 participant