firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.74k stars 868 forks source link

Keep the context on cancel callback handler. #8204

Open AlastairTaft opened 3 weeks ago

AlastairTaft commented 3 weeks ago

I have an issue where there is an unhandled promise rejection throwing, but I have an error handler on this scenario, it looks something like this

const Display = function(deviceId){
  Component.call(this)
  this.bindedOnUnhandledRejection_ = this.onUnhandledRejection_.bind(this)
}

Display.prototype.addEventListeners = function(){
  window.addEventListener("unhandledrejection", this.bindedOnUnhandledRejection_)
}

Display.prototype.onUnhandledRejection_ = function(event){
  this.logger_.log({
    message: event.reason instanceof Error ? 
      event.reason.message :
      String(event.reason), 
    type: 'ERROR',
  }, {
    'reason': maybeConvertErrorToSerializableObject(event.reason),
  })
  this.paintErrors_()
}

My issue is that onUnhandledRejection is getting called from Firebase, and Firebase is removing the context from my function. So the error comes in and `this.logger` is undefined.

I'm proposing that Firebase should not be messing with my function context.

changeset-bot[bot] commented 3 weeks ago

⚠️ No Changeset found

Latest commit: 3f800e5fca363e34728d51df664dbe1a593ed0d0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR