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


##########
superset-frontend/src/explore/components/controls/AnnotationLayerControl/index.tsx:
##########
@@ -107,17 +107,25 @@ class AnnotationLayerControl extends PureComponent<Props, 
PopoverState> {
     AnnotationLayer.preload();
   }
 
-  UNSAFE_componentWillReceiveProps(nextProps: Props) {
-    const { name, annotationError, validationErrors, value } = nextProps;
-    if (Object.keys(annotationError).length && !validationErrors.length) {
-      this.props.actions.setControlValue(
-        name,
-        value,
-        Object.keys(annotationError),
-      );
-    }
-    if (!Object.keys(annotationError).length && validationErrors.length) {
-      this.props.actions.setControlValue(name, value, []);
+  componentDidUpdate(prevProps: Props) {
+    const { name, annotationError, validationErrors, value } = this.props;
+    if (
+      (Object.keys(annotationError).length && !validationErrors.length) ||
+      (!Object.keys(annotationError).length && validationErrors.length)
+    ) {
+      if (
+        annotationError !== prevProps.annotationError ||
+        validationErrors !== prevProps.validationErrors ||
+        value !== prevProps.value
+      ) {

Review Comment:
   ### Redundant Object.keys() Computation <sub>![category 
Performance](https://img.shields.io/badge/Performance-4f46e5)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   Multiple redundant Object.keys() calculations within nested conditional 
blocks
   
   
   ###### Why this matters
   Repeatedly calling Object.keys() increases computational overhead, 
especially when the result is used multiple times in the same function scope
   
   ###### Suggested change ∙ *Feature Preview*
   Store the Object.keys() result in a variable before the conditional checks:
   ```typescript
   const annotationErrorKeys = Object.keys(annotationError);
   if (
     (annotationErrorKeys.length && !validationErrors.length) ||
     (!annotationErrorKeys.length && validationErrors.length)
   ) {
     if (
       annotationError !== prevProps.annotationError ||
       validationErrors !== prevProps.validationErrors ||
       value !== prevProps.value
     ) {
       this.props.actions.setControlValue(
         name,
         value,
         annotationErrorKeys.length ? annotationErrorKeys : []
       );
     }
   }
   ```
   
   
   ###### 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/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c?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/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c?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/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:e76a45b6-46d0-4c81-afd3-f67f85455f22 -->
   
   
   [](e76a45b6-46d0-4c81-afd3-f67f85455f22)



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