From fcb90bab8b7578dcf7dd0c87dcc0cbe7cdbc0591 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 28 Nov 2016 22:50:10 -0800 Subject: [PATCH] Handle race condition with resize event --- js/components/WindowManager.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/components/WindowManager.jsx b/js/components/WindowManager.jsx index 19083d4f..d7c2a6c5 100644 --- a/js/components/WindowManager.jsx +++ b/js/components/WindowManager.jsx @@ -11,11 +11,18 @@ class WindowManager extends React.Component { super(props); this.windowNodes = []; this.state = {}; - window.addEventListener('resize', this.centerWindows.bind(this)); this.getRef = this.getRef.bind(this); this.handleMouseDown = this.handleMouseDown.bind(this); } + componentDidMount() { + window.addEventListener('resize', this.centerWindows.bind(this)); + const {innerHeight, innerWidth} = window; + if (innerHeight || innerWidth) { + this.centerWindows(); + } + } + centerWindows() { const {innerHeight, innerWidth} = window; const state = {};