FirebaseExtended / firechat

Real-time Chat powered by Firebase
https://firechat.firebaseapp.com
MIT License
2.41k stars 1.04k forks source link

Fixed race condition where _sessionId was null #71

Closed jwngr closed 8 years ago

jwngr commented 8 years ago

After deploying the latest version of Firechat, I noticed an error in the console due to the fact that self._sessionId is null on this line. I am not sure exactly why this showed up now, but I think it is because _sessionId is set in _setupDataEvents() which is called with onAuthStateChanged() here and that method may not fire as soon in the 3.x.x SDKs as onAuth() used to fire in the 2.x.x SDKs. So, the enterRoom() call happens first (triggered by the Firechat UI code) and tries to use _sessionId before it is available. The solution is to just define _sessionId earlier. I have a hunch there are still race conditions, but this should be early enough that we won't hit it before the enterRoom() call happens.