Skip to content

Commit d422436

Browse files
Fix db.useEmulator (#4828)
* Fix db.useEmulator * Create sweet-monkeys-warn.md
1 parent d47fb41 commit d422436

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

.changeset/sweet-monkeys-warn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/database": patch
3+
---
4+
5+
Fixes a regression introduced with 8.4.1 that broke `useEmulator()`.

packages/database/src/core/PersistentConnection.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,6 @@ export class PersistentConnection extends ServerActions {
773773
const onReady = this.onReady_.bind(this);
774774
const onDisconnect = this.onRealtimeDisconnect_.bind(this);
775775
const connId = this.id + ':' + PersistentConnection.nextConnectionId_++;
776-
const self = this;
777776
const lastSessionId = this.lastSessionId;
778777
let canceled = false;
779778
let connection: Connection | null = null;
@@ -807,17 +806,17 @@ export class PersistentConnection extends ServerActions {
807806
.then(result => {
808807
if (!canceled) {
809808
log('getToken() completed. Creating connection.');
810-
self.authToken_ = result && result.accessToken;
809+
this.authToken_ = result && result.accessToken;
811810
connection = new Connection(
812811
connId,
813-
self.repoInfo_,
814-
self.applicationId_,
812+
this.repoInfo_,
813+
this.applicationId_,
815814
onDataMessage,
816815
onReady,
817816
onDisconnect,
818817
/* onKill= */ reason => {
819-
warn(reason + ' (' + self.repoInfo_.toString() + ')');
820-
self.interrupt(SERVER_KILL_INTERRUPT_REASON);
818+
warn(reason + ' (' + this.repoInfo_.toString() + ')');
819+
this.interrupt(SERVER_KILL_INTERRUPT_REASON);
821820
},
822821
lastSessionId
823822
);
@@ -826,7 +825,7 @@ export class PersistentConnection extends ServerActions {
826825
}
827826
})
828827
.then(null, error => {
829-
self.log_('Failed to get token: ' + error);
828+
this.log_('Failed to get token: ' + error);
830829
if (!canceled) {
831830
if (this.repoInfo_.nodeAdmin) {
832831
// This may be a critical error for the Admin Node.js SDK, so log a warning.

packages/database/src/exp/Database.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class FirebaseDatabase implements _FirebaseService {
217217

218218
/** @hideconstructor */
219219
constructor(
220-
private _repoInternal: Repo,
220+
public _repoInternal: Repo,
221221
/** The FirebaseApp associated with this Realtime Database instance. */
222222
readonly app: FirebaseApp
223223
) {}
@@ -300,7 +300,7 @@ export function useDatabaseEmulator(
300300
);
301301
}
302302
// Modify the repo to apply emulator settings
303-
repoManagerApplyEmulatorSettings(db._repo, host, port);
303+
repoManagerApplyEmulatorSettings(db._repoInternal, host, port);
304304
}
305305

306306
/**

0 commit comments

Comments
 (0)