From 9f0b20344d03afc085b782a5d271a7e3288302d0 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 23 Apr 2021 09:55:50 -0600 Subject: [PATCH 1/2] Fix db.useEmulator --- packages/database/src/core/PersistentConnection.ts | 13 ++++++------- packages/database/src/exp/Database.ts | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/database/src/core/PersistentConnection.ts b/packages/database/src/core/PersistentConnection.ts index e3cfa4c5322..0c0762a8d22 100644 --- a/packages/database/src/core/PersistentConnection.ts +++ b/packages/database/src/core/PersistentConnection.ts @@ -773,7 +773,6 @@ export class PersistentConnection extends ServerActions { const onReady = this.onReady_.bind(this); const onDisconnect = this.onRealtimeDisconnect_.bind(this); const connId = this.id + ':' + PersistentConnection.nextConnectionId_++; - const self = this; const lastSessionId = this.lastSessionId; let canceled = false; let connection: Connection | null = null; @@ -807,17 +806,17 @@ export class PersistentConnection extends ServerActions { .then(result => { if (!canceled) { log('getToken() completed. Creating connection.'); - self.authToken_ = result && result.accessToken; + this.authToken_ = result && result.accessToken; connection = new Connection( connId, - self.repoInfo_, - self.applicationId_, + this.repoInfo_, + this.applicationId_, onDataMessage, onReady, onDisconnect, /* onKill= */ reason => { - warn(reason + ' (' + self.repoInfo_.toString() + ')'); - self.interrupt(SERVER_KILL_INTERRUPT_REASON); + warn(reason + ' (' + this.repoInfo_.toString() + ')'); + this.interrupt(SERVER_KILL_INTERRUPT_REASON); }, lastSessionId ); @@ -826,7 +825,7 @@ export class PersistentConnection extends ServerActions { } }) .then(null, error => { - self.log_('Failed to get token: ' + error); + this.log_('Failed to get token: ' + error); if (!canceled) { if (this.repoInfo_.nodeAdmin) { // This may be a critical error for the Admin Node.js SDK, so log a warning. diff --git a/packages/database/src/exp/Database.ts b/packages/database/src/exp/Database.ts index 5f0ac58c144..f70d797be3e 100644 --- a/packages/database/src/exp/Database.ts +++ b/packages/database/src/exp/Database.ts @@ -217,7 +217,7 @@ export class FirebaseDatabase implements _FirebaseService { /** @hideconstructor */ constructor( - private _repoInternal: Repo, + public _repoInternal: Repo, /** The FirebaseApp associated with this Realtime Database instance. */ readonly app: FirebaseApp ) {} @@ -300,7 +300,7 @@ export function useDatabaseEmulator( ); } // Modify the repo to apply emulator settings - repoManagerApplyEmulatorSettings(db._repo, host, port); + repoManagerApplyEmulatorSettings(db._repoInternal, host, port); } /** From a8293985684c4d082791a15118d770d3f55824c5 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 23 Apr 2021 09:58:17 -0600 Subject: [PATCH 2/2] Create sweet-monkeys-warn.md --- .changeset/sweet-monkeys-warn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sweet-monkeys-warn.md diff --git a/.changeset/sweet-monkeys-warn.md b/.changeset/sweet-monkeys-warn.md new file mode 100644 index 00000000000..6b1ac7a7f98 --- /dev/null +++ b/.changeset/sweet-monkeys-warn.md @@ -0,0 +1,5 @@ +--- +"@firebase/database": patch +--- + +Fixes a regression introduced with 8.4.1 that broke `useEmulator()`.