Skip to content

Conversation

msyavuz
Copy link
Member

@msyavuz msyavuz commented Sep 24, 2025

SUMMARY

This PR fixes an issue where refreshing a dashboard does not update charts in tabs that haven't been loaded yet. Previously, only charts in tabs that were already visited would refresh, leaving unvisited tabs with stale data.

The fix implements lazy refresh behavior for tabs - when a dashboard refresh is triggered, tabs that haven't been loaded yet will automatically refresh their charts when the user switches to them.

BEFORE/AFTER

Before

  • When refreshing a dashboard with multiple tabs, only the charts from tabs that were already loaded would be refreshed
  • Charts in unvisited tabs would remain stale even after a dashboard refresh

After

  • Dashboard refresh marks the refresh timestamp
  • When switching to a previously unloaded tab after a refresh, that tab's charts are automatically refreshed
  • This matches the initial loading behavior where tabs load lazily as the user navigates to them

TESTING INSTRUCTIONS

  1. Create a dashboard with 3 tabs, and add one chart on each tab
  2. Wait a couple of minutes so data gets cached on all charts
  3. Access the dashboard (loads on first tab) and navigate to the second tab
  4. Trigger a dashboard refresh using the refresh button
  5. Navigate to the third tab
  6. Verify that the third tab's charts are refreshed when you switch to it (you should see loading indicators)

ADDITIONAL INFORMATION

  • Added tracking of tab activation times to determine when tabs need refreshing
  • Added lastRefreshTime to dashboard state to track when refreshes occur
  • Tab component now checks if it needs to refresh when becoming visible
  • Created utility function getChartIdsFromComponent to get all chart IDs within a tab

Fixes the issue where dashboard refresh doesn't affect unloaded tabs.

@dosubot dosubot bot added dashboard Namespace | Anything related to the Dashboard dashboard:tab Related to the usage of tabs in the Dashboard labels Sep 24, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Design High coupling with DashboardLayout implementation ▹ view 🧠 Not in scope
Performance Inefficient memoization key for layout ▹ view 🧠 Incorrect
Performance Inefficient effect dependency on tabActivationTimes ▹ view 🧠 Not in standard
Design Component with Mixed Responsibilities ▹ view 🧠 Incorrect
Files scanned
File Path Reviewed
superset-frontend/src/dashboard/util/charts/useAllChartIds.ts
superset-frontend/src/dashboard/util/getChartIdsFromComponent.ts
superset-frontend/src/dashboard/reducers/dashboardState.js
superset-frontend/src/dashboard/components/gridComponents/Tab/Tab.jsx

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment on lines +22 to +25
export default function getChartIdsFromComponent(
componentId: string,
layout: DashboardLayout,
): number[] {

This comment was marked as resolved.

const layout = useSelector(
(state: RootState) => state.dashboardLayout.present,
);
return useMemo(() => getChartIdsFromLayout(layout), [layout]);

This comment was marked as resolved.

Comment on lines +127 to +158
useEffect(() => {
if (props.renderType === RENDER_TAB_CONTENT && props.isComponentVisible) {
const tabId = props.id;
const tabActivationTime = tabActivationTimes[tabId] || 0;

// If a refresh occurred while this tab was inactive,
// refresh the charts in this tab now that it's visible
if (
lastRefreshTime &&
tabActivationTime &&
lastRefreshTime > tabActivationTime
) {
const chartIds = getChartIdsFromComponent(tabId, dashboardLayout);
if (chartIds.length > 0) {
// Small delay to ensure charts are fully mounted
setTimeout(() => {
// Refresh charts in this tab
dispatch(onRefresh(chartIds, true, 0, dashboardInfo.id));
}, 100);
}
}
}
}, [
props.isComponentVisible,
props.renderType,
props.id,
lastRefreshTime,
tabActivationTimes,
dashboardLayout,
dashboardInfo.id,
dispatch,
]);

This comment was marked as resolved.

Comment on lines 114 to +124
const Tab = props => {
const dispatch = useDispatch();
const canEdit = useSelector(state => state.dashboardInfo.dash_edit_perm);
const dashboardLayout = useSelector(state => state.dashboardLayout.present);
const lastRefreshTime = useSelector(
state => state.dashboardState.lastRefreshTime,
);
const tabActivationTimes = useSelector(
state => state.dashboardState.tabActivationTimes || {},
);
const dashboardInfo = useSelector(state => state.dashboardInfo);

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashboard:tab Related to the usage of tabs in the Dashboard dashboard Namespace | Anything related to the Dashboard size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant