Skip to content

Fix calls awaiting forever on firebase scripts failing to load on web#204

Open
TomVHPresto wants to merge 3 commits intocapacitor-community:masterfrom
TomVHPresto:fix/web-load-scripts-promise-error
Open

Fix calls awaiting forever on firebase scripts failing to load on web#204
TomVHPresto wants to merge 3 commits intocapacitor-community:masterfrom
TomVHPresto:fix/web-load-scripts-promise-error

Conversation

@TomVHPresto
Copy link

On web, currently if the firebase scripts fail to load, throws an error from inside the Promise callback, which causes an unhandled promise rejection. This means that the ready promise is never resolved or rejected, and function calls like initializeFirebase will await forever.

This change means that the ready promise will be rejected and the errors will be propagated upwards correctly.

@TomVHPresto TomVHPresto changed the title Fix calls awaiting forever on firebase scripts failing to load Fix calls awaiting forever on firebase scripts failing to load on web Dec 5, 2025
@TomVHPresto
Copy link
Author

Any update?

Copy link
Member

@robingenz robingenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just two questions

await this.loadScript(
firebaseAnalyticsScript.key,
firebaseAnalyticsScript.src
resolve(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar reasoning here, using await will throw an exception on error which causes an unhandled promise rejection - instead resolving it using this promise propagates any error by rejecting the promise.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was wrong about this actually and only the other change is necessary. Let me do some testing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it won't work without the change in my testing. Using async / await inside a new promise constructor is an anti-pattern because if it throws inside an async callback, the error isn't propagated correctly.

}
} catch (error) {
throw error;
this.readyReject(error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change?

Copy link
Author

@TomVHPresto TomVHPresto Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error being thrown here means that the ready promise is never rejected, so if you do await FirebaseAnalytics.initialize() you can't catch the error using a try / catch, and the call awaits forever. This was causing an issue for me because I work on a web app that can be used offline, so I need to be able to handle his gracefully.

Copy link
Member

@robingenz robingenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run npm run changeset and generate a changeset file.

@TomVHPresto
Copy link
Author

Please run npm run changeset and generate a changeset file.

This script doesn't seem to exist

@TomVHPresto
Copy link
Author

Any update?

@robingenz
Copy link
Member

@TomVHPresto Sorry, I mixed up the repo with https://github.com/capawesome-team/capacitor-firebase. Someone else from the community should take a look at this PR. I'm not that active in this repo.

@TomVHPresto
Copy link
Author

Well thanks anyway 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants