mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Address resize loop (#5004)
This commit is contained in:
@@ -42,9 +42,9 @@ interface IDimension {
|
|||||||
height: number;
|
height: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useContainerDimensions = <
|
export const useContainerDimensions = <T extends HTMLElement = HTMLDivElement>(
|
||||||
T extends HTMLElement = HTMLDivElement
|
sensitivityThreshold = 20
|
||||||
>(): [MutableRefObject<T | null>, IDimension] => {
|
): [MutableRefObject<T | null>, IDimension] => {
|
||||||
const target = useRef<T | null>(null);
|
const target = useRef<T | null>(null);
|
||||||
const [dimension, setDimension] = useState<IDimension>({
|
const [dimension, setDimension] = useState<IDimension>({
|
||||||
width: 0,
|
width: 0,
|
||||||
@@ -53,7 +53,14 @@ export const useContainerDimensions = <
|
|||||||
|
|
||||||
useResizeObserver(target, (entry) => {
|
useResizeObserver(target, (entry) => {
|
||||||
const { inlineSize: width, blockSize: height } = entry.contentBoxSize[0];
|
const { inlineSize: width, blockSize: height } = entry.contentBoxSize[0];
|
||||||
setDimension({ width, height });
|
let difference = Math.abs(dimension.width - width);
|
||||||
|
// Only adjust when width changed by a significant margin. This addresses the cornercase that sees
|
||||||
|
// the dimensions toggle back and forward when the window is adjusted perfectly such that overflow
|
||||||
|
// is trigger then immediable disabled because of a resize event then continues this loop endlessly.
|
||||||
|
// the scrollbar size varies between platforms. Windows is apparently around 17 pixels.
|
||||||
|
if (difference > sensitivityThreshold) {
|
||||||
|
setDimension({ width, height });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return [target, dimension];
|
return [target, dimension];
|
||||||
|
|||||||
Reference in New Issue
Block a user