Skip to content

Commit 4584dfe

Browse files
heavygeecursoragent
andcommitted
fix(web): guard ResizeObserver before constructing it
HAPI Bot Major (PR tiann#741): Vitest jsdom does not polyfill ResizeObserver, so the toolbar measure effect throws ReferenceError when the existing mermaid-diagram React tests open the lightbox. Same code path is also brittle in any browser/webview without the API. Fall back to plain window 'resize' listener when ResizeObserver is absent. Toolbar height won't auto-update on element resize without it, but the lightbox still renders and the resize listener catches the common viewport-rotation case. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent effabb8 commit 4584dfe

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

web/src/components/ZoomableLightbox.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,14 @@ export function ZoomableLightbox(props: ZoomableLightboxProps) {
359359
}
360360

361361
apply()
362+
window.addEventListener('resize', apply)
363+
364+
if (typeof ResizeObserver === 'undefined') {
365+
return () => window.removeEventListener('resize', apply)
366+
}
367+
362368
const resize = new ResizeObserver(apply)
363369
resize.observe(toolbar)
364-
window.addEventListener('resize', apply)
365370
return () => {
366371
resize.disconnect()
367372
window.removeEventListener('resize', apply)

0 commit comments

Comments
 (0)