diff --git a/.changeset/sharp-pans-share.md b/.changeset/sharp-pans-share.md new file mode 100644 index 00000000000..03bcc49fa95 --- /dev/null +++ b/.changeset/sharp-pans-share.md @@ -0,0 +1,5 @@ +--- +"@firebase/component": patch +--- + +Pass the instance to onInit callback diff --git a/packages/component/src/provider.test.ts b/packages/component/src/provider.test.ts index 4344aa75a56..a6e7a076557 100644 --- a/packages/component/src/provider.test.ts +++ b/packages/component/src/provider.test.ts @@ -197,6 +197,20 @@ describe('Provider', () => { expect(callback).to.have.been.calledOnce; }); + it('passes service instance', () => { + const serviceInstance = { test: true }; + provider.setComponent(getFakeComponent('test', () => serviceInstance)); + const callback = fake(); + + // initialize the service instance + provider.getImmediate(); + + provider.onInit(callback); + + expect(callback).to.have.been.calledOnce; + expect(callback).to.have.been.calledWith(serviceInstance); + }); + it('passes instance identifier', () => { provider.setComponent( getFakeComponent( diff --git a/packages/component/src/provider.ts b/packages/component/src/provider.ts index 1eaad815e4e..290cead4eaf 100644 --- a/packages/component/src/provider.ts +++ b/packages/component/src/provider.ts @@ -272,7 +272,7 @@ export class Provider { existingCallbacks.add(callback); this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks); - const existingInstance = this.instances.has(normalizedIdentifier); + const existingInstance = this.instances.get(normalizedIdentifier); if (existingInstance) { callback(existingInstance, normalizedIdentifier); }