Skip to content

Commit d1972f1

Browse files
[DURACOM-303] fix SSR check on template and on components missing the environment config. Add descriptive comment for skeleton component. Fix JS error on SSR.
1 parent a50c346 commit d1972f1

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

src/app/browse-by/browse-by-date/browse-by-date.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
APP_CONFIG,
3232
AppConfig,
3333
} from '../../../config/app-config.interface';
34+
import { environment } from '../../../environments/environment';
3435
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
3536
import { BrowseService } from '../../core/browse/browse.service';
3637
import {
@@ -108,7 +109,7 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
108109
}
109110

110111
ngOnInit(): void {
111-
if (!this.renderOnServerSide && isPlatformServer(this.platformId)) {
112+
if (!this.renderOnServerSide && !environment.ssr.enableBrowseComponent && isPlatformServer(this.platformId)) {
112113
this.loading$ = observableOf(false);
113114
return;
114115
}

src/app/browse-by/browse-by-metadata/browse-by-metadata.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<section class="comcol-page-browse-section">
1+
<section class="comcol-page-browse-section" *ngIf="(!ssrRenderingDisabled)">
22
<div class="browse-by-metadata w-100">
33
<ds-browse-by *ngIf="(loading$ | async) !== true" class="col-xs-12 w-100"
44
title="{{'browse.title' | translate:{

src/app/browse-by/browse-by-metadata/browse-by-metadata.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ describe('BrowseByMetadataComponent', () => {
268268

269269
describe('when rendered in SSR', () => {
270270
beforeEach(() => {
271-
comp.platformId = 'server';
272-
spyOn((comp as any).browseService, 'getBrowseEntriesFor');
271+
comp.ssrRenderingDisabled = true;
272+
spyOn((comp as any).browseService, 'getBrowseEntriesFor').and.returnValue(createSuccessfulRemoteDataObject$(null));
273273
});
274274

275275
it('should not call getBrowseEntriesFor on init', (done) => {
@@ -284,7 +284,7 @@ describe('BrowseByMetadataComponent', () => {
284284

285285
describe('when rendered in CSR', () => {
286286
beforeEach(() => {
287-
comp.platformId = 'browser';
287+
comp.ssrRenderingDisabled = false;
288288
spyOn((comp as any).browseService, 'getBrowseEntriesFor').and.returnValue(createSuccessfulRemoteDataObject$(new BrowseEntry()));
289289
});
290290

src/app/browse-by/browse-by-metadata/browse-by-metadata.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
202202
* Observable determining if the loading animation needs to be shown
203203
*/
204204
loading$ = observableOf(true);
205+
/**
206+
* Whether this component should be rendered or not in SSR
207+
*/
208+
ssrRenderingDisabled = false;
205209

206210
public constructor(protected route: ActivatedRoute,
207211
protected browseService: BrowseService,
@@ -218,11 +222,12 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
218222
currentPage: 1,
219223
pageSize: this.appConfig.browseBy.pageSize,
220224
});
225+
this.ssrRenderingDisabled = !this.renderOnServerSide && !environment.ssr.enableBrowseComponent && isPlatformServer(this.platformId);
221226
}
222227

223228

224229
ngOnInit(): void {
225-
if (!this.renderOnServerSide && !environment.ssr.enableBrowseComponent && isPlatformServer(this.platformId)) {
230+
if (this.ssrRenderingDisabled) {
226231
this.loading$ = observableOf(false);
227232
return;
228233
}
@@ -348,7 +353,6 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
348353
this.paginationService.clearPagination(this.paginationConfig.id);
349354
}
350355

351-
352356
}
353357

354358
/**

src/app/browse-by/browse-by-title/browse-by-title.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
take,
1919
} from 'rxjs/operators';
2020

21+
import { environment } from '../../../environments/environment';
2122
import {
2223
SortDirection,
2324
SortOptions,
@@ -63,7 +64,7 @@ import {
6364
export class BrowseByTitleComponent extends BrowseByMetadataComponent implements OnInit {
6465

6566
ngOnInit(): void {
66-
if (!this.renderOnServerSide && isPlatformServer(this.platformId)) {
67+
if (!this.renderOnServerSide && !environment.ssr.enableBrowseComponent && isPlatformServer(this.platformId)) {
6768
this.loading$ = observableOf(false);
6869
return;
6970
}

src/app/shared/search/search-results/search-results-skeleton/search-results-skeleton.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import { hasValue } from '../../../empty.util';
2525
templateUrl: './search-results-skeleton.component.html',
2626
styleUrl: './search-results-skeleton.component.scss',
2727
})
28+
/**
29+
* Component to show placeholders for search results while loading, to give a loading feedback to the user without layout shifting.
30+
*/
2831
export class SearchResultsSkeletonComponent implements OnInit {
2932
@Input()
3033
showThumbnails: boolean;

0 commit comments

Comments
 (0)