Skip to content

Commit 7449639

Browse files
committed
fix(overlays): guard preventScroll focus against engines that mishandle options
present() runs on a critical path, so wrap the focus({ preventScroll }) call in a try/catch that falls back to a plain focus(). This keeps the no-scroll behavior on modern browsers while ensuring a focus call can never reject present() on an engine that mishandles the options object.
1 parent 5ddc39c commit 7449639

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

core/src/utils/overlays.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,17 @@ export const present = async <OverlayPresentOptions>(
604604
*/
605605
const overlayWrapper = getElementRoot(overlay.el).querySelector<HTMLElement>('[role="dialog"][tabindex]');
606606
const focusTarget = overlayWrapper ?? overlay.el;
607-
focusTarget.focus({ preventScroll: true });
607+
/**
608+
* `preventScroll` keeps this a pure focus move so the viewport does not
609+
* jump when the wrapper is partially off-screen (e.g. a sheet modal).
610+
* Guard the options call so an older engine that mishandles it can never
611+
* reject present(); we fall back to a plain focus() in that case.
612+
*/
613+
try {
614+
focusTarget.focus({ preventScroll: true });
615+
} catch {
616+
focusTarget.focus();
617+
}
608618
}
609619

610620
/**

0 commit comments

Comments
 (0)