Fix rendering performances issues related to scrolling events (#174)
* memoize chat related components * Avoid re-rendering ChatInput on every message udpate * change the way the horizontal scrollbar is hidden * make the scroll event listener passive * perf(Chat): fix performances issues related to autoscroll Uses the intersection API to determine autoscroll mode instead of listening for scroll events * tuning detection of autoscroll
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
export function throttle<T extends (...args: any[]) => any>(func: T, limit: number): T {
|
||||
let lastFunc: ReturnType<typeof setTimeout>;
|
||||
let lastRan: number;
|
||||
|
||||
return ((...args) => {
|
||||
if (!lastRan) {
|
||||
func(...args);
|
||||
lastRan = Date.now();
|
||||
} else {
|
||||
clearTimeout(lastFunc);
|
||||
lastFunc = setTimeout(() => {
|
||||
if (Date.now() - lastRan >= limit) {
|
||||
func(...args);
|
||||
lastRan = Date.now();
|
||||
}
|
||||
}, limit - (Date.now() - lastRan));
|
||||
}
|
||||
}) as T;
|
||||
}
|
||||
Reference in New Issue
Block a user