omsn2 commented on code in PR #43108:
URL: https://github.com/apache/superset/pull/43108#discussion_r4024212316


##########
superset-frontend/src/dashboard/containers/DashboardPage.tsx:
##########
@@ -226,6 +289,60 @@ export const DashboardPage: FC<PageProps> = ({ idOrSlug }: 
PageProps) => {
         }
       } else if (nativeFilterKeyValue) {
         dataMask = await getFilterValue(id, nativeFilterKeyValue);
+      } else {
+        const savedFilters = getSavedDashboardFilters(id, userId);
+        // Guard against corrupted or unexpected localStorage data shapes
+        // (e.g. a JSON array or primitive) before assigning to dataMask.
+        if (
+          savedFilters &&
+          typeof savedFilters === 'object' &&
+          !Array.isArray(savedFilters)
+        ) {
+          const isVersioned =
+            'dataMask' in savedFilters && 'filterDefinitions' in savedFilters;
+          const maskToRestore = isVersioned
+            ? savedFilters.dataMask
+            : savedFilters;
+          const savedDefinitions = isVersioned
+            ? savedFilters.filterDefinitions
+            : {};
+
+          const currentFilters = (dashboard?.metadata
+            ?.native_filter_configuration ?? []) as NativeFilterConfigEntry[];
+
+          // Only restore entries whose filter ID still exists in the current
+          // native filter configuration. If we have a snapshotted definition
+          // (from the newer versioned schema), we also verify that the 
filter's
+          // target columns/datasets and type have not changed. This prevents
+          // stale extraFormData from a retargeted filter from being hydrated.
+          const validatedFilters = Object.fromEntries(
+            Object.entries(maskToRestore).filter(([filterId]) => {
+              const currentConfig = currentFilters.find(f => f.id === 
filterId);

Review Comment:
   Pre-filter the array with (f): f is NativeFilterConfigEntry => f != null && 
!!f.id before the find() call.



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

Reply via email to