diff --git a/src/core/public/application/application_service.test.ts b/src/core/public/application/application_service.test.ts index de9e4d4496f3b2..f348936d267954 100644 --- a/src/core/public/application/application_service.test.ts +++ b/src/core/public/application/application_service.test.ts @@ -804,6 +804,21 @@ describe('#start()', () => { `); }); + it("when openInNewTab is true it doesn't update currentApp$ after mounting", async () => { + service.setup(setupDeps); + + const { currentAppId$, navigateToApp } = await service.start(startDeps); + const stop$ = new Subject(); + const promise = currentAppId$.pipe(bufferCount(4), takeUntil(stop$)).toPromise(); + + await navigateToApp('delta', { openInNewTab: true }); + stop$.next(); + + const appIds = await promise; + + expect(appIds).toBeUndefined(); + }); + it('updates httpLoadingCount$ while mounting', async () => { // Use a memory history so that mounting the component will work const { createMemoryHistory } = jest.requireActual('history'); diff --git a/src/core/public/application/application_service.tsx b/src/core/public/application/application_service.tsx index 2e804bf2f5413c..3ba0d78cf15fd9 100644 --- a/src/core/public/application/application_service.tsx +++ b/src/core/public/application/application_service.tsx @@ -250,16 +250,15 @@ export class ApplicationService { if (path === undefined) { path = applications$.value.get(appId)?.defaultPath; } - if (!navigatingToSameApp) { - this.appInternalStates.delete(this.currentAppId$.value!); - } if (openInNewTab) { this.openInNewTab!(getAppUrl(availableMounters, appId, path)); } else { + if (!navigatingToSameApp) { + this.appInternalStates.delete(this.currentAppId$.value!); + } this.navigate!(getAppUrl(availableMounters, appId, path), state, replace); + this.currentAppId$.next(appId); } - - this.currentAppId$.next(appId); } };