Skip to content
Open
4 changes: 3 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
} from './src/express.tokens';
import { SsrExcludePatterns } from "./src/config/ssr-config.interface";
import { getSsrCacheKey } from './src/app/shared/ssr-cache-key.util';
import { getSsrPath } from './src/app/shared/ssr-path.util';

/*
* Set path for the browser application's dist folder
Expand Down Expand Up @@ -228,7 +229,8 @@ export function app() {
* The callback function to serve server side angular
*/
function ngApp(req, res, next) {
if (environment.ssr.enabled && req.method === 'GET' && (req.path === '/' || !isExcludedFromSsr(req.path, environment.ssr.excludePathPatterns))) {
const ssrAllowed = (path: string) => path === '/' || !isExcludedFromSsr(path, environment.ssr.excludePathPatterns);
if (environment.ssr.enabled && req.method === 'GET' && ssrAllowed(req.path) && ssrAllowed(getSsrPath(req, environment.ui.nameSpace))) {
// Render the page to user via SSR (server side rendering)
serverSideRender(req, res, next);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { ItemAdminSearchResultActionsComponent } from '../../item-admin-search-r
selector: 'ds-item-admin-search-result-grid-element',
styleUrls: ['./item-admin-search-result-grid-element.component.scss'],
templateUrl: './item-admin-search-result-grid-element.component.html',
// Angular cannot hydrate DOM nodes passed as projectableNodes
host: { ngSkipHydration: 'true' },
imports: [
DynamicComponentLoaderDirective,
ItemAdminSearchResultActionsComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import { WorkflowItemAdminWorkflowActionsComponent } from '../../actions/workflo
selector: 'ds-workflow-item-search-result-admin-workflow-grid-element',
styleUrls: ['./workflow-item-search-result-admin-workflow-grid-element.component.scss'],
templateUrl: './workflow-item-search-result-admin-workflow-grid-element.component.html',
// Angular cannot hydrate DOM nodes passed as projectableNodes
host: { ngSkipHydration: 'true' },
imports: [
DynamicComponentLoaderDirective,
TranslateModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import { WorkspaceItemAdminWorkflowActionsComponent } from '../../actions/worksp
selector: 'ds-workflow-item-search-result-admin-workflow-grid-element',
styleUrls: ['./workspace-item-search-result-admin-workflow-grid-element.component.scss'],
templateUrl: './workspace-item-search-result-admin-workflow-grid-element.component.html',
// Angular cannot hydrate DOM nodes passed as projectableNodes
host: { ngSkipHydration: 'true' },
imports: [
AsyncPipe,
DynamicComponentLoaderDirective,
Expand Down
7 changes: 7 additions & 0 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
DOCUMENT,
importProvidersFrom,
} from '@angular/core';
import {
provideClientHydration,
withNoHttpTransferCache,
} from '@angular/platform-browser';
import {
NoPreloading,
provideRouter,
Expand Down Expand Up @@ -115,6 +119,9 @@ export const commonAppConfig: ApplicationConfig = {
withPreloading(NoPreloading),
withComponentInputBinding(),
),
// Needed on the server too, or the browser gets no hydration data and draws the page again.
// REST responses already reach the browser through the NgRx transfer state.
provideClientHydration(withNoHttpTransferCache()),
{
provide: APP_BASE_HREF,
useFactory: getBaseHref,
Expand Down
9 changes: 9 additions & 0 deletions src/app/core/core.effects.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { coreEffects } from './core.effects';

describe('coreEffects', () => {
it('should not reset the menus when the browser rehydrates the server state', () => {
// The server state already holds the built menus and the browser menu providers replace each section by id.
// A reset on REHYDRATE only hides the admin sidebar until the providers are done, which shifts the page.
expect(coreEffects.map((effect) => effect.name)).not.toContain('MenuEffects');
});
});
2 changes: 0 additions & 2 deletions src/app/core/core.effects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MenuEffects } from '../shared/menu/menu.effects';
import { AuthEffects } from './auth/auth.effects';
import { ObjectCacheEffects } from './cache/object-cache.effects';
import { ServerSyncBufferEffects } from './cache/server-sync-buffer.effects';
Expand All @@ -19,5 +18,4 @@ export const coreEffects = [
ObjectUpdatesEffects,
RouteEffects,
RouterEffects,
MenuEffects,
];
8 changes: 4 additions & 4 deletions src/app/home-page/home-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h3 class="h5 h5-font carousel-deposit-cite">{{'home-page.carousel.deposit.cite'
<div class="row justify-content-center pt-5">
<div class="col-md-9 responsive-padding">
<div class="row offset-md-1">
<div class="col-md-4 border-bottom">
<div class="col-md-4 border-bottom fast-search-links" [class.loading]="loading.has('author')">
<strong>{{'home-page.hyperlink.author.message' | translate}}</strong>
@for (authorLink of (authors$| async); track authorLink.url) {
<div>
Expand All @@ -89,7 +89,7 @@ <h3 class="h5 h5-font carousel-deposit-cite">{{'home-page.carousel.deposit.cite'
</a>
</div>
</div>
<div class="col-md-4 border-bottom">
<div class="col-md-4 border-bottom fast-search-links" [class.loading]="loading.has('subjectFirstValue')">
<strong>{{'home-page.hyperlink.subject.message' | translate}}</strong>
@for (subjectLink of (subjects$| async); track subjectLink.url) {
<div>
Expand All @@ -102,7 +102,7 @@ <h3 class="h5 h5-font carousel-deposit-cite">{{'home-page.carousel.deposit.cite'
</a>
</div>
</div>
<div class="col-md-4 border-bottom">
<div class="col-md-4 border-bottom fast-search-links" [class.loading]="loading.has('language')">
<strong>{{'home-page.hyperlink.language.message' | translate}}</strong>
@for (languageLink of (languages$| async); track languageLink.url) {
<div>
Expand All @@ -121,7 +121,7 @@ <h3 class="h5 h5-font carousel-deposit-cite">{{'home-page.carousel.deposit.cite'
</div>

<div class="container pt-3">
<div class="card clarin-home-page-items-color">
<div class="card clarin-home-page-items-color new-items" [class.loading]="loading.has('new-items')">
<div class="card-body">
<div class="justify-content-between d-flex">
<div class="recent-submissions-head flex-fill">{{'home-page.whats-new.message' | translate}}</div>
Expand Down
17 changes: 17 additions & 0 deletions src/app/home-page/home-page.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@
font-size: 120%;
}

// The browser fills these boxes after load; keep their loaded size until then, so the page does not jump.
.fast-search-links.loading {
min-height: 169px;

@media (min-width: 768px) and (max-width: 991.98px) {
min-height: 241px;
}

@media (min-width: 992px) and (max-width: 1199.98px) {
min-height: 193px;
}
}

.new-items.loading {
min-height: 875px;
}

@media (max-width: 991.98px) {
.carousel-ldata-info {
left: 42%;
Expand Down
103 changes: 103 additions & 0 deletions src/app/home-page/home-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import {
NO_ERRORS_SCHEMA,
PLATFORM_ID,
Provider,
} from '@angular/core';
import {
ComponentFixture,
TestBed,
} from '@angular/core/testing';
import {
ActivatedRoute,
provideRouter,
} from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { of } from 'rxjs';

import { ConfigurationDataService } from '../core/data/configuration-data.service';
import { ItemDataService } from '../core/data/item-data.service';
import { SiteDataService } from '../core/data/site-data.service';
import { HALEndpointService } from '../core/shared/hal-endpoint.service';
import { SearchService } from '../core/shared/search/search.service';
import { UsageReportDataService } from '../core/statistics/usage-report-data.service';
import { ClarinItemBoxViewComponent } from '../shared/clarin-item-box-view/clarin-item-box-view.component';
import {
createFailedRemoteDataObject$,
createSuccessfulRemoteDataObject$,
} from '../shared/remote-data.utils';
import { RSSComponent } from '../shared/rss-feed/rss.component';
import { ThemedSearchFormComponent } from '../shared/search-form/themed-search-form.component';
import { HomePageComponent } from './home-page.component';

describe('HomePageComponent', () => {
let component: HomePageComponent;
let fixture: ComponentFixture<HomePageComponent>;

async function setup(platformId: string, providers: Provider[]) {
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), HomePageComponent],
providers: [
provideRouter([]),
{ provide: ActivatedRoute, useValue: { data: of({ site: { uuid: 'site-uuid' } }) } },
{ provide: SiteDataService, useValue: {} },
{ provide: ItemDataService, useValue: {} },
{ provide: PLATFORM_ID, useValue: platformId },
...providers,
],
})
.overrideComponent(HomePageComponent, {
remove: { imports: [ClarinItemBoxViewComponent, RSSComponent, ThemedSearchFormComponent] },
add: { schemas: [NO_ERRORS_SCHEMA] },
})
.compileComponents();

fixture = TestBed.createComponent(HomePageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}

function minHeight(selector: string): number {
return parseFloat(getComputedStyle(fixture.nativeElement.querySelector(selector)).minHeight) || 0;
}

describe('on the server', () => {
beforeEach(async () => {
await setup('server', [
{ provide: SearchService, useValue: { getSearchLink: () => '/search' } },
{ provide: HALEndpointService, useValue: {} },
{ provide: ConfigurationDataService, useValue: {} },
{ provide: UsageReportDataService, useValue: {} },
]);
});

it('should keep space for the boxes the browser fills after load', () => {
expect(minHeight('.fast-search-links')).toBeGreaterThan(0);
expect(minHeight('.new-items')).toBeGreaterThan(0);
});
});

describe('in the browser', () => {
beforeEach(async () => {
await setup('browser', [
{
provide: SearchService, useValue: {
getSearchLink: () => '/search',
search: () => createFailedRemoteDataObject$(),
getFacetValuesFor: () => createFailedRemoteDataObject$(),
},
},
{ provide: HALEndpointService, useValue: { getRootHref: () => 'http://rest' } },
{ provide: ConfigurationDataService, useValue: { findByPropertyName: () => createSuccessfulRemoteDataObject$({ values: ['http://ui'] }) } },
{ provide: UsageReportDataService, useValue: { searchStatistics: () => of([]) } },
]);
});

it('should drop that space when the requests fail', async () => {
await fixture.whenStable();
fixture.detectChanges();
expect(component.loading.size).toBe(0);
expect(minHeight('.fast-search-links')).toBe(0);
expect(minHeight('.new-items')).toBe(0);
});
});
});
25 changes: 18 additions & 7 deletions src/app/home-page/home-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ import {
} from '../core/cache/models/sort-options.model';
import { ConfigurationDataService } from '../core/data/configuration-data.service';
import { ItemDataService } from '../core/data/item-data.service';
import { RemoteData } from '../core/data/remote-data';
import { SiteDataService } from '../core/data/site-data.service';
import { ConfigurationProperty } from '../core/shared/configuration-property.model';
import { DSpaceObjectType } from '../core/shared/dspace-object-type.model';
import { HALEndpointService } from '../core/shared/hal-endpoint.service';
import { Item } from '../core/shared/item.model';
import { getFirstSucceededRemoteDataPayload } from '../core/shared/operators';
import {
getFirstCompletedRemoteData,
getFirstSucceededRemoteDataPayload,
} from '../core/shared/operators';
import { SearchService } from '../core/shared/search/search.service';
import { Site } from '../core/shared/site.model';
import { UsageReport } from '../core/statistics/models/usage-report.model';
Expand Down Expand Up @@ -95,6 +99,11 @@ export class HomePageComponent implements OnInit {
newItems$: BehaviorSubject<Item[]> = new BehaviorSubject<Item[]>([]);
topItems$: BehaviorSubject<Item[]> = new BehaviorSubject<Item[]>([]);

/**
* Boxes still waiting for their request. They keep their loaded height until it completes.
*/
loading = new Set<string>(['author', 'subjectFirstValue', 'language', 'new-items']);

siteId: string;

baseUrl = '';
Expand Down Expand Up @@ -167,13 +176,14 @@ export class HomePageComponent implements OnInit {
sort: sortConfiguration,
dsoTypes: [DSpaceObjectType.ITEM],
}))
.pipe(getFirstSucceededRemoteDataPayload())
.subscribe((searchObjects: SearchObjects<Item>) => {
.pipe(getFirstCompletedRemoteData())
.subscribe((rd: RemoteData<SearchObjects<Item>>) => {
const searchedItems: Item[] = [];
searchObjects?.page?.forEach(searchObject => {
rd.payload?.page?.forEach(searchObject => {
searchedItems.push(searchObject?.indexableObject);
});
this.newItems$.next(searchedItems);
this.loading.delete('new-items');
});
}

Expand Down Expand Up @@ -272,9 +282,10 @@ export class HomePageComponent implements OnInit {
});
const searchOptions: PaginatedSearchOptions = new PaginatedSearchOptions({ configuration: 'homepage' });
this.searchService.getFacetValuesFor(searchFilter, 1, searchOptions)
.pipe(getFirstSucceededRemoteDataPayload())
.subscribe(authorStats => {
authorStats.page.forEach((facetValue: FacetValue) => {
.pipe(getFirstCompletedRemoteData())
.subscribe(rd => {
this.loading.delete(facetName);
rd.payload?.page?.forEach((facetValue: FacetValue) => {
let updatedSearchUrl = facetValue?._links?.search?.href?.replace(this.halService.getRootHref() +
'/discover', this.baseUrl);
if (isUndefined(updatedSearchUrl)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="col-md-10">
<div class="file-section" *ngVar="(bitstreams$ | async) as bitstreams">
@for (file of bitstreams; track file; let last = $last) {
<ds-file-download-link [bitstream]="file" [item]="item">
<ds-file-download-link ngSkipHydration [bitstream]="file" [item]="item">
<span>{{file?.name}}</span>
<span>({{(file?.sizeBytes) | dsFileSize }})</span>
@if (!last) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ds-metadata-field-wrapper [label]="label | translate">
<div class="file-section">
@for (file of bitstreams; track file; let last = $last) {
<ds-file-download-link [bitstream]="file" [item]="item">
<ds-file-download-link ngSkipHydration [bitstream]="file" [item]="item">
<span>
@if (primaryBitstreamId === file.id) {
<span class="badge bg-primary">{{ 'item.page.bitstreams.primary' | translate }}</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@if (this.relationship.searchConfiguration && context) {
<ds-search
<ds-search ngSkipHydration
[configuration]="this.relationship.searchConfiguration"
[context]="context"
[fixedFilterQuery]="this.relationship.filter"
Expand Down
51 changes: 0 additions & 51 deletions src/app/shared/menu/menu.effects.spec.ts

This file was deleted.

Loading
Loading