From d735160a118dae60e3d4392b099a66daa7b25b05 Mon Sep 17 00:00:00 2001 From: onlyflix Date: Fri, 19 Oct 2018 16:09:28 +0200 Subject: [PATCH] fix(docs-infra): don't call setSearch when not clicking in the searchBox and no searchResults (#26590) Fix to call locationService.setSearch less often to avoid unnecessary downloading of favicons Fixes #26544 PR Close #26590 --- aio/src/app/app.component.spec.ts | 7 ++++++- aio/src/app/app.component.ts | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index 79549c767f..328501569e 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -742,7 +742,7 @@ describe('AppComponent', () => { expect(component.showSearchResults).toBe(true); }); - it('should not intercept clicks om the searchBox', () => { + it('should not intercept clicks on the searchBox', () => { component.showSearchResults = true; fixture.detectChanges(); @@ -752,6 +752,11 @@ describe('AppComponent', () => { expect(component.showSearchResults).toBe(true); }); + + it('should not call `locationService.setSearch` when searchResults are not shown', () => { + docViewer.click(); + expect(locationService.setSearch).not.toHaveBeenCalled(); + }); }); describe('keyup handling', () => { diff --git a/aio/src/app/app.component.ts b/aio/src/app/app.component.ts index 820796fb69..65c4855200 100644 --- a/aio/src/app/app.component.ts +++ b/aio/src/app/app.component.ts @@ -389,7 +389,10 @@ export class AppComponent implements OnInit { hideSearchResults() { this.showSearchResults = false; - this.locationService.setSearch('', { ...this.locationService.search(), search: undefined }); + const oldSearch = this.locationService.search(); + if (oldSearch.search !== undefined) { + this.locationService.setSearch('', { ...oldSearch, search: undefined }); + } } focusSearchBox() {