Skip to content

Commit

Permalink
fix: Apply batched updates to resize observer callback (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-boris authored Dec 6, 2024
1 parent c8a5c73 commit d5f68a1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/internal/container-queries/use-resize-observer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { unstable_batchedUpdates } from 'react-dom';
import { ResizeObserver, ResizeObserverEntry } from '@juggle/resize-observer';
import { useEffect, useLayoutEffect } from 'react';
import { ContainerQueryEntry, ElementReference } from './interfaces';
Expand Down Expand Up @@ -56,7 +57,9 @@ export function useResizeObserver(elementRef: ElementReference, onObserve: (entr
const observer = new ResizeObserver(entries => {
// Prevent observe notifications on already unmounted component.
if (connected) {
stableOnObserve(convertResizeObserverEntry(entries[0]));
unstable_batchedUpdates(() => {
stableOnObserve(convertResizeObserverEntry(entries[0]));
});
}
});
observer.observe(element);
Expand Down

0 comments on commit d5f68a1

Please sign in to comment.