Fix infinite loop in onclose -> cleanUp -> close -> onclose -> cleanUp -> ...
(cherry picked from commit 2a8b62db7e3c9890846edd6af549f84878fc114e)
Build dist files