From d31bdf2cf8f74a398efede27cc850e05a6655f30 Mon Sep 17 00:00:00 2001 From: Charlie Croom Date: Tue, 9 Oct 2018 16:51:29 -0700 Subject: [PATCH] [fix] ResizeObserve only on elements using 'onLayout' prop Only observe nodes when the 'onLayout' prop is specified on the element. Fixes performance regression for browsers that rely on MutationObserver-based shim for ResizeObserver. Fix #1128 Close #1129 --- .../react-native-web/src/modules/applyLayout/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-native-web/src/modules/applyLayout/index.js b/packages/react-native-web/src/modules/applyLayout/index.js index 4fd58ae3e..d6e8a1a48 100644 --- a/packages/react-native-web/src/modules/applyLayout/index.js +++ b/packages/react-native-web/src/modules/applyLayout/index.js @@ -97,7 +97,9 @@ const applyLayout = Component => { function componentDidMount() { this._layoutState = emptyObject; this._isMounted = true; - observe(this); + if (this.props.onLayout) { + observe(this); + } } ); @@ -116,7 +118,9 @@ const applyLayout = Component => { componentWillUnmount, function componentWillUnmount() { this._isMounted = false; - unobserve(this); + if (this.props.onLayout) { + unobserve(this); + } } );