Skip to content
This repository was archived by the owner on Nov 4, 2025. It is now read-only.

Commit c7fc072

Browse files
committed
fix: Align should in sync
1 parent ef85ea6 commit c7fc072

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/util.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export function isSamePoint(prev: TargetPoint, next: TargetPoint) {
1919

2020
export function restoreFocus(activeElement, container) {
2121
// Focus back if is in the container
22-
if (activeElement !== document.activeElement && contains(container, activeElement) && typeof activeElement.focus === 'function') {
22+
if (
23+
activeElement !== document.activeElement &&
24+
contains(container, activeElement) &&
25+
typeof activeElement.focus === 'function'
26+
) {
2327
activeElement.focus();
2428
}
2529
}
@@ -36,7 +40,7 @@ export function monitorResize(element: HTMLElement, callback: Function) {
3640

3741
if (prevWidth !== fixedWidth || prevHeight !== fixedHeight) {
3842
// https://webkit.org/blog/9997/resizeobserver-in-webkit/
39-
requestAnimationFrame(() => {
43+
Promise.resolve().then(() => {
4044
callback({ width: fixedWidth, height: fixedHeight });
4145
});
4246
}

tests/util.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ describe('util', () => {
9292
jest.useRealTimers();
9393
});
9494

95-
it('should defer callback to next frame', () => {
95+
it('should defer callback to next frame', async () => {
9696
const callback = jest.fn();
9797
monitorResize(element, callback);
9898
observer.triggerResize();
9999
jest.runAllTimers();
100+
await Promise.resolve();
100101
expect(callback).toHaveBeenCalled();
101102
});
102103

0 commit comments

Comments
 (0)