From 10cbe2125a68ec2c31b45363a20a2327c3a4c238 Mon Sep 17 00:00:00 2001 From: jgor20 <102353650+jgor20@users.noreply.github.com> Date: Sun, 11 Jan 2026 14:51:07 +0000 Subject: [PATCH] perf(ui): debounce window resize event for sidebar responsiveness Debounce the window resize event listener with a 150ms timeout to prevent excessive executions, improving performance during window resizing. --- public/app.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/public/app.js b/public/app.js index b237b71..4cb3a9c 100644 --- a/public/app.js +++ b/public/app.js @@ -67,21 +67,27 @@ document.addEventListener('alpine:init', () => { // Handle responsive sidebar transitions let lastWidth = window.innerWidth; + let resizeTimeout = null; + window.addEventListener('resize', () => { - const currentWidth = window.innerWidth; - const lgBreakpoint = 1024; + if (resizeTimeout) clearTimeout(resizeTimeout); - // Desktop -> Mobile: Auto-close sidebar to prevent overlay blocking screen - if (lastWidth >= lgBreakpoint && currentWidth < lgBreakpoint) { - this.sidebarOpen = false; - } - - // Mobile -> Desktop: Auto-open sidebar (restore standard desktop layout) - if (lastWidth < lgBreakpoint && currentWidth >= lgBreakpoint) { - this.sidebarOpen = true; - } - - lastWidth = currentWidth; + resizeTimeout = setTimeout(() => { + const currentWidth = window.innerWidth; + const lgBreakpoint = 1024; + + // Desktop -> Mobile: Auto-close sidebar to prevent overlay blocking screen + if (lastWidth >= lgBreakpoint && currentWidth < lgBreakpoint) { + this.sidebarOpen = false; + } + + // Mobile -> Desktop: Auto-open sidebar (restore standard desktop layout) + if (lastWidth < lgBreakpoint && currentWidth >= lgBreakpoint) { + this.sidebarOpen = true; + } + + lastWidth = currentWidth; + }, 150); }); // Theme setup