codeant-ai-for-open-source[bot] commented on code in PR #43085:
URL: https://github.com/apache/superset/pull/43085#discussion_r3764848875


##########
superset-frontend/src/dashboard/containers/DashboardPage.tsx:
##########
@@ -157,20 +181,26 @@ export const DashboardPage: FC<PageProps> = ({ idOrSlug 
}: PageProps) => {
   const isNotFoundError = (error as SupersetApiError | null)?.status === 404;
   const readyToRender = Boolean(dashboard && charts);
   const { dashboard_title, id = 0 } = dashboard || {};
+  const hydratedDashboardId = useSelector<RootState, number | undefined>(
+    state => state.dashboardInfo?.id,
+  );
+  const fullDataMask = useSelector(selectDataMask);
 
+  useEffect(() => {
+    if (!id || hydratedDashboardId !== id) return;
+    saveDashboardFilters(id, fullDataMask);
+  }, [id, hydratedDashboardId, fullDataMask]);

Review Comment:
   **Suggestion:** The persistence effect runs before the hydration effect and 
can overwrite the saved state with the current Redux mask, commonly `{}` during 
the initial render. When the hydration effect subsequently reads localStorage, 
it restores the already-erased value instead of the user's filters. Defer 
persistence until after dashboard hydration has completed, or prevent the 
initial write until the saved state has been loaded. [stale reference]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Reopening dashboards can lose persisted native-filter selections.
   - ⚠️ SPA dashboard reuse can overwrite saved filter state.
   - ⚠️ Filter selections must be manually restored by users.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7628e60c035e4141bff87ea44e56296d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=7628e60c035e4141bff87ea44e56296d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/dashboard/containers/DashboardPage.tsx
   **Line:** 189:192
   **Comment:**
        *Stale Reference: The persistence effect runs before the hydration 
effect and can overwrite the saved state with the current Redux mask, commonly 
`{}` during the initial render. When the hydration effect subsequently reads 
localStorage, it restores the already-erased value instead of the user's 
filters. Defer persistence until after dashboard hydration has completed, or 
prevent the initial write until the saved state has been loaded.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43085&comment_hash=966020fddb138832b829856a27c62ff2a28cc794543e5d912c1efa0341214bae&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43085&comment_hash=966020fddb138832b829856a27c62ff2a28cc794543e5d912c1efa0341214bae&reaction=dislike'>👎</a>



##########
superset-frontend/src/dashboard/containers/DashboardPage.tsx:
##########
@@ -226,6 +256,11 @@ export const DashboardPage: FC<PageProps> = ({ idOrSlug }: 
PageProps) => {
         }
       } else if (nativeFilterKeyValue) {
         dataMask = await getFilterValue(id, nativeFilterKeyValue);
+      } else {
+        const savedFilters = getSavedDashboardFilters(id);
+        if (savedFilters) {
+          dataMask = savedFilters;
+        }
       }

Review Comment:
   **Suggestion:** The saved filter lookup is inside an effect that only runs 
when `readyToRender` changes. During SPA navigation, the component can remain 
ready while `id` and the fetched dashboard data change, so this branch is 
skipped for the new dashboard and its saved filters are never hydrated. Include 
the dashboard identity in the hydration trigger and reset the hydration 
lifecycle when navigating between dashboards. [state/lifecycle]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Dashboard-to-dashboard navigation skips saved native filters.
   - ⚠️ Dashboard B can display stale filter state from dashboard A.
   - ⚠️ Users lose expected filter persistence during SPA navigation.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=bcaebff1d5a444c380fb98430950a02f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=bcaebff1d5a444c380fb98430950a02f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/dashboard/containers/DashboardPage.tsx
   **Line:** 259:264
   **Comment:**
        *State Lifecycle: The saved filter lookup is inside an effect that only 
runs when `readyToRender` changes. During SPA navigation, the component can 
remain ready while `id` and the fetched dashboard data change, so this branch 
is skipped for the new dashboard and its saved filters are never hydrated. 
Include the dashboard identity in the hydration trigger and reset the hydration 
lifecycle when navigating between dashboards.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43085&comment_hash=c1a3b01731da6a5a0f6cf677f391b628fb77860dbc73672df0fe588bab2d6a10&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43085&comment_hash=c1a3b01731da6a5a0f6cf677f391b628fb77860dbc73672df0fe588bab2d6a10&reaction=dislike'>👎</a>



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