Skip to content

Commit

Permalink
fix: avoid constantly handling resize
Browse files Browse the repository at this point in the history
  • Loading branch information
justusmattern27 committed Sep 13, 2024
1 parent 09caa1b commit cd09c37
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/player-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,23 @@ export function Player({
(entries: ResizeObserverEntry[]) => {
const [entry] = entries;
if (entry && wrapperRef.current) {
const boundingRect = wrapperRef.current.getBoundingClientRect();
onPlayerResize?.(boundingRect);
const newRect = entry.contentRect;
if (
!lastRect.current ||
newRect.width !== lastRect.current.width ||
newRect.height !== lastRect.current.height
) {
console.log('jo resize');
lastRect.current = newRect;
onPlayerResize?.(newRect);
}
}
},
[onPlayerResize],
);

const lastRect = useRef<DOMRectReadOnly | null>(null);

useEffect(() => {
if (!wrapperRef.current) return;

Expand Down

0 comments on commit cd09c37

Please sign in to comment.