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


##########
superset-frontend/src/SqlLab/actions/sqlLab.js:
##########
@@ -765,7 +766,11 @@ export function removeQuery(query) {
       : Promise.resolve();
 
     return sync
-      .then(() => dispatch({ type: REMOVE_QUERY, query }))
+      .then(() => {
+        dispatch({ type: REMOVE_QUERY, query });
+        // Invalidate RTK Query cache to update the UI
+        dispatch(api.util.invalidateTags(['EditorQueries']));

Review Comment:
   ### Missing Cache Invalidation on Error <sub>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The RTK Query cache invalidation is only triggered on success but not on 
error when removing a query.
   
   
   ###### Why this matters
   If the DELETE request fails, the UI may show stale data since the cache 
wasn't invalidated, leading to inconsistency between the UI state and the 
actual server state.
   
   ###### Suggested change ∙ *Feature Preview*
   Move the cache invalidation outside the .then() block to ensure it runs in 
both success and error cases:
   ```javascript
   return sync
     .then(() => {
       dispatch({ type: REMOVE_QUERY, query });
     })
     .catch(() => {
       dispatch(
         addDangerToast(
           t(
             'An error occurred while removing query. Please contact your 
administrator.',
           ),
         ),
       );
     })
     .finally(() => {
       dispatch(api.util.invalidateTags(['EditorQueries']));
     });
   ```
   
   
   ###### 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/9f280bb6-ccd2-4668-ac01-2a9cb3dfac62/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9f280bb6-ccd2-4668-ac01-2a9cb3dfac62?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/9f280bb6-ccd2-4668-ac01-2a9cb3dfac62?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/9f280bb6-ccd2-4668-ac01-2a9cb3dfac62?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/9f280bb6-ccd2-4668-ac01-2a9cb3dfac62)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:a9fb5b20-eae0-4141-8dd3-2574516ee1e1 -->
   
   
   [](a9fb5b20-eae0-4141-8dd3-2574516ee1e1)



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