From 7640e48e7bb3ae9a93a999523eeafc2349f2674c Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 28 Oct 2016 14:44:27 -0400 Subject: [PATCH] Components: Trigger require if prop reference changes --- client/components/async-load/index.jsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/client/components/async-load/index.jsx b/client/components/async-load/index.jsx index a24c19214c4e46..0fc3084985840e 100644 --- a/client/components/async-load/index.jsx +++ b/client/components/async-load/index.jsx @@ -19,6 +19,18 @@ export default class AsyncLoad extends Component { } componentWillMount() { + this.require(); + } + + componentDidUpdate( prevProps ) { + // Our Babel transform will hoist the require function in the rendering + // component, so we can compare the reference with confidence + if ( this.props.require !== prevProps.require ) { + this.require(); + } + } + + require() { this.props.require( ( component ) => { this.setState( { component } ); } );