diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 5380443fbc0a..1e12c31e683a 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -260,6 +260,12 @@ export function is_crossorigin() { } export function add_resize_listener(node: HTMLElement, fn: () => void) { + if ('ResizeObserver' in window) { + // @ts-ignore https://github.com/Microsoft/TypeScript/issues/28502 + const obs = new ResizeObserver(fn) as any; + obs.observe(node); + return obs.disconnect.bind(obs); + } const computed_style = getComputedStyle(node); const z_index = (parseInt(computed_style.zIndex) || 0) - 1;