Extension loads before workspace is connected when session is restored

In version 4.0:
When the page is reloaded and the session is restored, the extensions try to load before the user has entered the workspace password, causing an unhandled exception

(from redmine: issue id 2445, created on 2016-11-23 by root)