From 7e8329379c9081a02dc177e8fdfbd1f2f91c334f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 30 Apr 2018 21:02:30 -0400 Subject: [PATCH] allow destruction of components with bind:offsetWidth etc --- src/shared/dom.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared/dom.js b/src/shared/dom.js index 54778d1aaf..2490fe0be8 100644 --- a/src/shared/dom.js +++ b/src/shared/dom.js @@ -203,8 +203,11 @@ export function addResizeListener(element, fn) { object.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;'); object.type = 'text/html'; + let win; + object.onload = () => { - object.contentDocument.defaultView.addEventListener('resize', fn); + win = object.contentDocument.defaultView; + win.addEventListener('resize', fn); }; if (/Trident/.test(navigator.userAgent)) { @@ -217,7 +220,7 @@ export function addResizeListener(element, fn) { return { cancel: () => { - object.contentDocument.defaultView.removeEventListener('resize', fn); + win.removeEventListener('resize', fn); element.removeChild(object); } };