perf(webui): reduce file activity layout work (#6587)
This commit is contained in:
1 parent
3404fe83e2
commit
94bfd3ff7d
6 files changed
+98
-17
No files matched your search
@@ -160,11 +160,18 @@ function StartTruncatedText({ children, className, ...props }: HTMLAttributes<HT
|
||||
const content = useRef<HTMLSpanElement>(null);
|
||||
const [clipped, setClipped] = useState(false);
|
||||
useLayoutEffect(() => {
|
||||
const update = () => setClipped(content.current!.getBoundingClientRect().width > container.current!.getBoundingClientRect().width);
|
||||
const observer = new ResizeObserver(update);
|
||||
observer.observe(container.current!);
|
||||
observer.observe(content.current!);
|
||||
update();
|
||||
let availableWidth = 0;
|
||||
let contentWidth = 0;
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
for (const entry of entries) {
|
||||
const width = entry.borderBoxSize[0].inlineSize;
|
||||
if (entry.target === container.current) availableWidth = width;
|
||||
else contentWidth = width;
|
||||
}
|
||||
setClipped(contentWidth > availableWidth);
|
||||
});
|
||||
observer.observe(container.current!, { box: "border-box" });
|
||||
observer.observe(content.current!, { box: "border-box" });
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
return <span ref={container} className={cn("inline-flex items-baseline overflow-hidden whitespace-nowrap", className)}>
|
||||
|
||||
Reference in new issue
Block a user