Skip to content

Commit c5ecff5

Browse files
[Click to call] Resize observer fix (#3192)
* fix infinite loop * Change files * Duplicate change files for beta release * fix lint
1 parent 918ec26 commit c5ecff5

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fixes resizeObserver infinite loop error in older versions of react",
4+
"packageName": "@azure/communication-react",
5+
"email": "94866715+dmceachernmsft@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fixes resizeObserver infinite loop error in older versions of react",
4+
"packageName": "@azure/communication-react",
5+
"email": "94866715+dmceachernmsft@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/src/components/VideoTile.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ export const VideoTile = (props: VideoTileProps): JSX.Element => {
245245
const [isHovered, setIsHovered] = useState<boolean>(false);
246246
/* @conditional-compile-remove(pinned-participants) */
247247
const [isFocused, setIsFocused] = useState<boolean>(false);
248-
const [personaSize, setPersonaSize] = useState<number>();
248+
// need to set a default otherwise the resizeObserver will get stuck in an infinite loop.
249+
const [personaSize, setPersonaSize] = useState<number>(1);
249250
const videoTileRef = useRef<HTMLDivElement>(null);
250251

251252
const locale = useLocale();
@@ -256,8 +257,11 @@ export const VideoTile = (props: VideoTileProps): JSX.Element => {
256257
const observer = useRef(
257258
new ResizeObserver((entries): void => {
258259
const { width, height } = entries[0].contentRect;
259-
const personaSize = Math.min(width, height) / 3;
260-
setPersonaSize(Math.max(Math.min(personaSize, personaMaxSize), personaMinSize));
260+
const personaCalcSize = Math.min(width, height) / 3;
261+
// we only want to set the persona size if it has changed
262+
if (personaCalcSize !== personaSize) {
263+
setPersonaSize(Math.max(Math.min(personaCalcSize, personaMaxSize), personaMinSize));
264+
}
261265
})
262266
);
263267

0 commit comments

Comments
 (0)