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:
Gyumin Lee
2026-03-15 23:18:59 +02:00
committed by GitHub
parent bcb0ccb6ca
commit edf0a197a8
4 changed files with 60 additions and 21 deletions
+9 -2
View File
@@ -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(() => {