This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch fix/stale-dashboard-favorite-status-32533
in repository https://gitbox.apache.org/repos/asf/superset.git

commit f999177e3b33ea9bf47becaaf3e1a4b4446f92bf
Author: Evan Rusackas <[email protected]>
AuthorDate: Sat Feb 21 14:18:30 2026 -0800

    fix(dashboard): prevent stale favorite status errors after navigation
    
    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 <[email protected]>
---
 .../src/dashboard/actions/dashboardState.ts        | 53 +++++++++++++++-------
 1 file changed, 36 insertions(+), 17 deletions(-)

diff --git a/superset-frontend/src/dashboard/actions/dashboardState.ts 
b/superset-frontend/src/dashboard/actions/dashboardState.ts
index 4901f0a064f..d86e0eb94d1 100644
--- a/superset-frontend/src/dashboard/actions/dashboardState.ts
+++ b/superset-frontend/src/dashboard/actions/dashboardState.ts
@@ -160,27 +160,38 @@ export function toggleFaveStar(isStarred: boolean): 
ToggleFaveStarAction {
 }
 
 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.',
+              ),
             ),
-          ),
-        ),
-      );
+          );
+        }
+      });
   };
 }
 
 export function saveFaveStar(id: number, isStarred: boolean) {
-  return function saveFaveStarThunk(dispatch: AppDispatch) {
+  return function saveFaveStarThunk(dispatch: AppDispatch, getState: GetState) 
{
     const endpoint = `/api/v1/dashboard/${id}/favorites/`;
     const apiCall = isStarred
       ? SupersetClient.delete({
@@ -190,13 +201,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.')),
+          );
+        }
+      });
   };
 }
 

Reply via email to