11import {
22 AsyncPipe ,
3+ isPlatformServer ,
34 NgIf ,
45} from '@angular/common' ;
56import {
@@ -9,6 +10,7 @@ import {
910 OnChanges ,
1011 OnDestroy ,
1112 OnInit ,
13+ PLATFORM_ID ,
1214} from '@angular/core' ;
1315import {
1416 ActivatedRoute ,
@@ -33,6 +35,7 @@ import {
3335 APP_CONFIG ,
3436 AppConfig ,
3537} from '../../../config/app-config.interface' ;
38+ import { environment } from '../../../environments/environment' ;
3639import { DSONameService } from '../../core/breadcrumbs/dso-name.service' ;
3740import { BrowseService } from '../../core/browse/browse.service' ;
3841import { BrowseEntrySearchOptions } from '../../core/browse/browse-entry-search-options.model' ;
@@ -114,6 +117,11 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
114117 */
115118 @Input ( ) displayTitle = true ;
116119
120+ /**
121+ * Defines whether to fetch search results during SSR execution
122+ */
123+ @Input ( ) renderOnServerSide : boolean ;
124+
117125 scope$ : BehaviorSubject < string > = new BehaviorSubject ( undefined ) ;
118126
119127 /**
@@ -194,6 +202,10 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
194202 * Observable determining if the loading animation needs to be shown
195203 */
196204 loading$ = observableOf ( true ) ;
205+ /**
206+ * Whether this component should be rendered or not in SSR
207+ */
208+ ssrRenderingDisabled = false ;
197209
198210 public constructor ( protected route : ActivatedRoute ,
199211 protected browseService : BrowseService ,
@@ -202,18 +214,23 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
202214 protected router : Router ,
203215 @Inject ( APP_CONFIG ) public appConfig : AppConfig ,
204216 public dsoNameService : DSONameService ,
217+ @Inject ( PLATFORM_ID ) public platformId : any ,
205218 ) {
206219 this . fetchThumbnails = this . appConfig . browseBy . showThumbnails ;
207220 this . paginationConfig = Object . assign ( new PaginationComponentOptions ( ) , {
208221 id : BBM_PAGINATION_ID ,
209222 currentPage : 1 ,
210223 pageSize : this . appConfig . browseBy . pageSize ,
211224 } ) ;
225+ this . ssrRenderingDisabled = ! this . renderOnServerSide && ! environment . ssr . enableBrowseComponent && isPlatformServer ( this . platformId ) ;
212226 }
213227
214228
215229 ngOnInit ( ) : void {
216-
230+ if ( this . ssrRenderingDisabled ) {
231+ this . loading$ = observableOf ( false ) ;
232+ return ;
233+ }
217234 const sortConfig = new SortOptions ( 'default' , SortDirection . ASC ) ;
218235 this . updatePage ( getBrowseSearchOptions ( this . defaultBrowseId , this . paginationConfig , sortConfig ) ) ;
219236 this . currentPagination$ = this . paginationService . getCurrentPagination ( this . paginationConfig . id , this . paginationConfig ) ;
@@ -336,7 +353,6 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
336353 this . paginationService . clearPagination ( this . paginationConfig . id ) ;
337354 }
338355
339-
340356}
341357
342358/**
0 commit comments