capacitor-community / capacitor-community/firebase-analytics
Web: Race condition with initializeFirebase
- Dominant language
- Java
- Stars
- 178
- Forks
- 70
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
FirebaseAnaltyics behaves badly if don't wait for initializeFirebase to return, and call trackEvent.
**To Reproduce**
```js
export async function initFirebase() {
return FirebaseAnalytics.initializeFirebase(firebaseConfig).then(() => {
FirebaseAnalytics.setCollectionEnabled({
enabled: true,
});
})
}
export const firebaseReady = initFirebase()
## if you call FirebaseAnalytics.trackEvent() here, without waiting for firebaseReady, you'll get a warning that firebase was initialized twice, and the setCollectionEnabled call will fail.
```
**Expected behavior**
There are already some readyhandlers coded in FirebaseAnalyticsWeb. i expect them to take care of this situation automatically.
Eg:
If you call trackEvent before initializeFirebase, i expect them to error.
if you call trackEvent after initializeFirebase, but before it's complete... it should wait on the promise internally and exectute.
At a minimum, it should give a more appropriate error message.
**version info**
@capacitor-community/firebase-analytics: 4.0.0,
@capacitor/core: 4.5.0,
Contributor guide
Assessment
This issue has not been assessed yet.