perf: batch mobile keyboard viewport handlers with rAF and debounce (#660)
Reduce layout thrashing during virtual keyboard open/close on mobile by batching resize and visualViewport event handlers to once per animation frame. No visual or behavioral changes — desktop is unaffected. - MainLayout: rAF-batch visualViewport resize/scroll and window resize listeners (was firing 10-20x per frame during keyboard animation) - Header: rAF-batch ResizeObserver and resize/orientationchange callbacks - ChatContainer: rAF-batch ResizeObserver and resize fallback callbacks - useDeviceInfo: 150ms debounce on resize listener (device type does not change during keyboard transitions)
This commit is contained in:
@@ -161,12 +161,19 @@ export function useDeviceInfo(): DeviceInfo {
|
||||
React.useEffect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
let debounceTimer: ReturnType<typeof setTimeout>;
|
||||
const handleResize = () => {
|
||||
setDeviceInfo(getDeviceInfo());
|
||||
clearTimeout(debounceTimer);
|
||||
debounceTimer = setTimeout(() => {
|
||||
setDeviceInfo(getDeviceInfo());
|
||||
}, 150);
|
||||
};
|
||||
|
||||
window.addEventListener('resize', handleResize);
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
return () => {
|
||||
clearTimeout(debounceTimer);
|
||||
window.removeEventListener('resize', handleResize);
|
||||
};
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user