korbit-ai[bot] commented on code in PR #34781:
URL: https://github.com/apache/superset/pull/34781#discussion_r2289562085


##########
superset-frontend/src/SqlLab/reducers/getInitialState.ts:
##########
@@ -221,18 +224,21 @@ export default function getInitialState({
           });
         }
         if (sqlLab.tabHistory) {
-          tabHistory.push(...sqlLab.tabHistory);
+          tabHistory.push(
+            ...sqlLab.tabHistory.filter(
+              tabId => !sqlLab.destroyedQueryEditors?.[tabId],
+            ),
+          );
         }
-        lastUpdatedActiveTab = tabHistory.slice(tabHistory.length - 1)[0] || 
'';
-
         if (sqlLab.destroyedQueryEditors) {
           Object.entries(sqlLab.destroyedQueryEditors).forEach(([id, ts]) => {
+            destroyedQueryEditors[id] = ts;
             if (queryEditors[id]) {
-              destroyedQueryEditors[id] = ts;
               delete queryEditors[id];
             }
           });
         }
+        lastUpdatedActiveTab = tabHistory.slice(tabHistory.length - 1)[0] || 
'';

Review Comment:
   ### Unsafe Active Tab Assignment <sub>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The lastUpdatedActiveTab is assigned without checking if the last tab in 
history is valid (not destroyed and exists in queryEditors).
   
   
   ###### Why this matters
   This could lead to an invalid active tab being set, causing the UI to 
attempt to display a non-existent or destroyed tab.
   
   ###### Suggested change ∙ *Feature Preview*
   Add validation to ensure the last tab is valid:
   ```typescript
   const lastTab = tabHistory.slice(tabHistory.length - 1)[0];
   lastUpdatedActiveTab = lastTab && queryEditors[lastTab] ? lastTab : '';
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/03d898c6-ab80-498d-be47-59ad478b62c3/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/03d898c6-ab80-498d-be47-59ad478b62c3?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/03d898c6-ab80-498d-be47-59ad478b62c3?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/03d898c6-ab80-498d-be47-59ad478b62c3?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/03d898c6-ab80-498d-be47-59ad478b62c3)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:7df86b07-5168-49dd-ad6d-8f4fcb132ae5 -->
   
   
   [](7df86b07-5168-49dd-ad6d-8f4fcb132ae5)



-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to