From 7b896456fdd8a8ebf58b48cefcc24ddf8de8c42c Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Wed, 13 Dec 2017 16:50:20 -0500 Subject: [PATCH 1/2] Update AutoSizer to support using a remote window as portal render target * Create detectElementResize CSS in the window containing the rendered AutoSizer. * Create the resize trigger element using the document containing the rendered AutoSizer. --- source/vendor/detectElementResize.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/vendor/detectElementResize.js b/source/vendor/detectElementResize.js index bd0881f99..262266eff 100644 --- a/source/vendor/detectElementResize.js +++ b/source/vendor/detectElementResize.js @@ -132,8 +132,8 @@ export default function createDetectElementResize(nonce) { keyframeprefix + 'animation: 1ms ' + animationName + '; '; } - var createStyles = function() { - if (!document.getElementById('detectElementResize')) { + var createStyles = function(doc) { + if (!doc.getElementById('detectElementResize')) { //opacity:0 works around a chrome bug https://code.google.com/p/chromium/issues/detail?id=286360 var css = (animationKeyframes ? animationKeyframes : '') + @@ -141,8 +141,8 @@ export default function createDetectElementResize(nonce) { (animationStyle ? animationStyle : '') + 'visibility: hidden; opacity: 0; } ' + '.resize-triggers, .resize-triggers > div, .contract-trigger:before { content: " "; display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; z-index: -1; } .resize-triggers > div { background: #eee; overflow: auto; } .contract-trigger:before { width: 200%; height: 200%; }', - head = document.head || document.getElementsByTagName('head')[0], - style = document.createElement('style'); + head = doc.head || doc.getElementsByTagName('head')[0], + style = doc.createElement('style'); style.id = 'detectElementResize'; style.type = 'text/css'; @@ -154,7 +154,7 @@ export default function createDetectElementResize(nonce) { if (style.styleSheet) { style.styleSheet.cssText = css; } else { - style.appendChild(document.createTextNode(css)); + style.appendChild(doc.createTextNode(css)); } head.appendChild(style); @@ -166,14 +166,15 @@ export default function createDetectElementResize(nonce) { element.attachEvent('onresize', fn); } else { if (!element.__resizeTriggers__) { + var doc = element.ownerDocument; var elementStyle = _window.getComputedStyle(element); if (elementStyle && elementStyle.position == 'static') { element.style.position = 'relative'; } - createStyles(); + createStyles(doc); element.__resizeLast__ = {}; element.__resizeListeners__ = []; - (element.__resizeTriggers__ = document.createElement('div')).className = + (element.__resizeTriggers__ = doc.createElement('div')).className = 'resize-triggers'; element.__resizeTriggers__.innerHTML = '
' + From 4ed13ec714006a2c16963960f3f20f9ff36b0916 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Fri, 22 Dec 2017 17:33:44 -0500 Subject: [PATCH 2/2] Update HTMLElement instance check to work across contexts --- source/AutoSizer/AutoSizer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/AutoSizer/AutoSizer.js b/source/AutoSizer/AutoSizer.js index 6f47b4c26..adfd7a565 100644 --- a/source/AutoSizer/AutoSizer.js +++ b/source/AutoSizer/AutoSizer.js @@ -55,7 +55,12 @@ export default class AutoSizer extends React.PureComponent { componentDidMount() { const {nonce} = this.props; - if (this._autoSizer && this._autoSizer.parentNode instanceof HTMLElement) { + if ( + this._autoSizer && + this._autoSizer.parentNode && + this._autoSizer.parentNode instanceof + this._autoSizer.parentNode.ownerDocument.defaultView.HTMLElement + ) { // Delay access of parentNode until mount. // This handles edge-cases where the component has already been unmounted before its ref has been set, // As well as libraries like react-lite which have a slightly different lifecycle.