-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
upcoming: [DI-20360] - Updated preferences logic to remove flickering issue #10853
upcoming: [DI-20360] - Updated preferences logic to remove flickering issue #10853
Conversation
5a5e8fd
to
6e9f899
Compare
Hi @jaalah-akamai / @bnussman-akamai / @abailly-akamai, I've updated the logics to reduce re-renderings. Please start reviewing the PR |
Coverage Report: ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My two main pieces of feedback are:
useRef
inUserPreference.ts
should not be necessary. If it is necessary to make CloudPulse work, is indicative of a larger issues.- I see
preferences
andupdatePreferences
getting passed down via props to a ton of components. Rather than passing it down via props, you can just use the hooks in the component itself. Doing this will allow us to minimize the number of props and could help with the number of components re-rendering
Yes refs are needed because we are passing preference when the component initially renders and then we only allow component to render externally when major props change. If we remove refs then we have to call user preference in every component instead of props in this way we can completely remove internal state variables but my only concern is re-renderings will increase compare to what it is now. And if number of filters increased then it may cause impact application performance |
As discussed async - The plan is to move forward with removing the |
@cpathipa I've modulaized the code as per the suggestions please re-review |
@abailly-akamai / @hkhalil-akamai I've updated all the changes and test cases as well. Please review it once & approve if all good |
@@ -123,5 +117,6 @@ export const CloudPulseDashboardSelect = React.memo( | |||
value={selectedDashboard ?? null} // Undefined is not allowed for uncontrolled component | |||
/> | |||
); | |||
} | |||
}, | |||
() => true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be here? useMemo
should only be used if necessary. Is it necessary here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this compare function is not required, I've removed it from few components. Though useMemo will required as we don't want component to re-render if some other preference value changes
}; | ||
return { | ||
isLoading, | ||
preferences: { ...(preferences?.aclpPreference ?? {}) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is going on here? Can this be
preferences: { ...(preferences?.aclpPreference ?? {}) }, | |
preferences: preferences?.aclpPreference ?? {}, |
export const arrayDeepEqual = ( | ||
oldValue: number[] | string[], | ||
newValue: number[] | string[] | ||
): boolean => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Utils like this need to be unit tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this method, it is not required
(oldProps: DashboardProp, newProps: DashboardProp) => { | ||
if (oldProps.dashboard?.id !== newProps.dashboard?.id) { | ||
return false; | ||
} | ||
|
||
if ( | ||
oldProps.timeDuration?.unit !== newProps.timeDuration?.unit || | ||
oldProps.timeDuration?.value !== newProps.timeDuration?.value | ||
) { | ||
return false; | ||
} | ||
|
||
const oldKeys = Object.keys(oldProps.filterValue); | ||
const newKeys = Object.keys(newProps.filterValue); | ||
|
||
if (oldKeys.length !== newKeys.length) { | ||
return false; | ||
} | ||
|
||
for (const key of oldKeys) { | ||
const oldValue = oldProps.filterValue[key]; | ||
const newValue = newProps.filterValue[key]; | ||
|
||
if ( | ||
Array.isArray(oldValue) && | ||
Array.isArray(newValue) && | ||
!arrayDeepEqual(oldValue, newValue) | ||
) { | ||
return false; | ||
} | ||
|
||
if (oldValue !== newValue) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not saying this is wrong, but in my time writing React, I've never had to be this granular with memoization. I feel like things shouldn't have to be like this.
I also wonder how the React 19 compiler could affect stuff like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked this compare function will not be required, only surrounded with memo works
@bnussman-akamai thanks for suggestions. Alot of not required code I've removed and pushed. |
@jaalah-akamai / @abailly-akamai / @hkhalil-akamai can we have another approval & merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for responding to feedback.
@cpathipa @hkhalil-akamai thanks for the approvals |
Cloud Manager E2E Run #6596
Run Properties:
|
Project |
Cloud Manager E2E
|
Branch Review |
develop
|
Run status |
Passed #6596
|
Run duration | 25m 12s |
Commit |
033099ccf7: upcoming: [DI-20360] - Updated preferences logic to remove flickering issue (#10...
|
Committer | Nikhil Agrawal |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
4
|
Pending |
2
|
Skipped |
0
|
Passing |
409
|
View all changes introduced in this branch ↗︎ |
Description 📝
Changed the current implementation of UserPreference to avoid flickering issue in widget component
Changes 🔄
List any change relevant to the reviewer.
Target release date 🗓️
5th September 2024
Preview 📷
Include a screenshot or screen recording of the change
💡 Use
<video src="" />
tag when including recordings in table.How to test 🧪
As an Author I have considered 🤔
Check all that apply