️(frontend) responsive throttling instead of debouncing

We changed the responsive store to use throttling
instead of debouncing for the window resize event.
This change ensures that the store updates more
consistently during rapid window resizing,
providing a smoother user experience.
This commit is contained in:
Anthony LC
2026-08-28 11:09:13 +02:00
parent 672f84d8bc
commit 1c52633f96
@@ -42,6 +42,8 @@ export const useResponsiveStore = create<UseResponsiveStore>((set) => ({
screenWidth: initialState.screenWidth,
setScreenSize: (size: ScreenSize) => set(() => ({ screenSize: size })),
initializeResizeListener: () => {
let pendingResize = false;
const resizeHandler = () => {
const width = window.innerWidth;
if (width < BREAKPOINTS.SMALL_MOBILE) {
@@ -89,10 +91,16 @@ export const useResponsiveStore = create<UseResponsiveStore>((set) => ({
let resizeTimeout: ReturnType<typeof setTimeout> | undefined;
const debouncedResizeHandler = () => {
if (pendingResize) {
return;
}
pendingResize = true;
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
resizeHandler();
}, 300);
pendingResize = false;
}, 200);
};
window.addEventListener('resize', debouncedResizeHandler);