Skip to content

Commit

Permalink
fix(framework): avoid ResizeObserver loop limit exceeded error (#6934)
Browse files Browse the repository at this point in the history
Fixes #6924
  • Loading branch information
georgimkv authored Apr 20, 2023
1 parent deb6685 commit 3b7f6d2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/base/src/delegate/ResizeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ const observedElements = new Map<HTMLElement, Array<ResizeObserverCallback>>();
const getResizeObserver = () => {
if (!resizeObserver) {
resizeObserver = new window.ResizeObserver(entries => {
entries.forEach(entry => {
const callbacks = observedElements.get(entry.target as HTMLElement);
// Callbacks could be async and we need to handle returned promises to comply with the eslint "no-misused-promises" rule.
// Although Promise.all awaits all, we don't additonal task after calling the callbacks and should not make any difference.
callbacks && Promise.all(callbacks.map((callback: ResizeObserverCallback) => callback()));
window.requestAnimationFrame(() => {
entries.forEach(entry => {
const callbacks = observedElements.get(entry.target as HTMLElement);
// Callbacks could be async and we need to handle returned promises to comply with the eslint "no-misused-promises" rule.
// Although Promise.all awaits all, we don't await the additional task after calling the callbacks and should not make any difference.
callbacks && Promise.all(callbacks.map((callback: ResizeObserverCallback) => callback()));
});
});
});
}
Expand Down

0 comments on commit 3b7f6d2

Please sign in to comment.