-
Notifications
You must be signed in to change notification settings - Fork 260
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
fix(ui5-illustrated-message): prevent infinite resize #5882
fix(ui5-illustrated-message): prevent infinite resize #5882
Conversation
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.
It looks good, there are some inline comments, that you can find.
In addition to the comments, could you add some basic information in the commit msg body - what is this about and how the bug is now resolved.
- added explanation comment on a variable - helper function exported in a separate util file
We could also fix this by using throttle. const throttle = (fn, delay) => {
let lastCall = 0;
return function (...args) {
// use performance.now() instead of Date.now() for better precision
const now = performance.now();
if (now - lastCall < delay) {
return;
}
lastCall = now;
return fn(...args);
};
}; IllustratedMessage.js handleResize = throttle(() => {
if (this.size !== IllustrationMessageSize.Auto) {
return;
}
if (this.offsetWidth <= IllustratedMessage.BREAKPOINTS.BASE) {
this.media = IllustratedMessage.MEDIA.BASE;
} else if (this.offsetWidth <= IllustratedMessage.BREAKPOINTS.SPOT) {
this.media = IllustratedMessage.MEDIA.SPOT;
} else if (this.offsetWidth <= IllustratedMessage.BREAKPOINTS.DIALOG) {
this.media = IllustratedMessage.MEDIA.DIALOG;
} else {
this.media = IllustratedMessage.MEDIA.SCENE;
}
}, 300) |
Although this solution is a lot better performance wise, it introduces two new unwanted behaviors.
Let me know what you think about my findings and if you think that the throttle solution should take place. Or if you have any other ideas. |
-we now use offsetWidth instead of boundingClientRect
- fixed es lint error
In the end me and @dobrinyonkov decided to use offsetWidth instead of boundingClientRect. Although this solution introduces slightly more flickering when resizing in the problematic zone, it's a lot better performance wise. |
Looks good to me! I only suggest to remove the shallowEqual util to follow the YAGNI principle. |
- removed shallowEqual method and its file following YAGNI
By caching the offsetWidth of the IllustratedMessage for each media, in the case of infinite resize, we check if the newly set media isn't with the same offsetWidth as the last time. If it is (case of infinite resize), we don't change the media.
Fixes: #5852
Thank you for your contribution! 👏
To get it merged faster, kindly review the checklist below:
Pull Request Checklist