Fix NPE when calling setState() before attaching to window.