omsn2 commented on code in PR #43108:
URL: https://github.com/apache/superset/pull/43108#discussion_r4033414039
##########
superset-frontend/src/dashboard/containers/DashboardPage.tsx:
##########
@@ -381,8 +523,47 @@ export const DashboardPage: FC<PageProps> = ({ idOrSlug }:
PageProps) => {
}, [addDangerToast, datasets, datasetsApiError, dispatch, isNotFoundError]);
const relevantDataMask = useSelector(selectRelevantDatamask);
+ const fullDataMask = useSelector(selectDataMask);
+ const nativeFilters = useSelector(selectNativeFilters);
const activeFilters = useSelector(selectActiveFilters);
+ useEffect(() => {
+ // Skip persistence for unauthenticated/guest users: they have no stable
+ // identity to scope the key to, and restoring filter state across
+ // guest-token sessions would leak selections between unrelated sessions.
+ // Use == null (not !userId) so a valid userId of 0 is not treated as
+ // anonymous.
+ if (
+ !id ||
+ userId == null ||
+ hydratedDashboardId !== id ||
+ !isDashboardHydrated.current
+ )
+ return;
+ // Persist only entries that correspond to configured native filters.
+ // This avoids saving chart customization or other transient dataMask
+ // entries that are not part of the user's filter selections.
+ const nativeFilterIds = Object.keys(nativeFilters);
+ // Do not overwrite a previously saved state with an empty mask.
+ // When the store clears dataMask on unmount (SPA navigation away), the
+ // hydratedDashboardId guard may still pass briefly before the next
+ // dashboard's hydration fires; skipping empty writes prevents that race
+ // from wiping the user's last valid selection.
+ if (nativeFilterIds.length === 0) return;
+ const nativeFilterMask = Object.fromEntries(
+ nativeFilterIds
+ .filter(filterId => filterId in fullDataMask)
+ .map(filterId => [filterId, fullDataMask[filterId]]),
+ );
+ // Also skip when the configuration is non-empty but dataMask has already
+ // been cleared (e.g. during SPA unmount before the next dashboard
hydrates).
+ // The ref stays true across the switch so the hydratedDashboardId guard
+ // alone is not sufficient — a nativeFilterMask of {} would still overwrite
+ // the user's saved selection.
+ if (Object.keys(nativeFilterMask).length === 0) return;
+ saveDashboardFilters(id, userId, nativeFilterMask, nativeFilters);
Review Comment:
Added isVersionPreviewActive from selectIsDashboardVersionPreviewActive
(already used in Header and DashboardBuilder) to the save effect's early-return
guard. When a version preview is active, the entire persistence write is
skipped. Added it to the useEffect deps array so it re-evaluates as preview
opens/closes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]