diff --git a/server.ts b/server.ts
index 1b3e051f270..26d43290296 100644
--- a/server.ts
+++ b/server.ts
@@ -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
@@ -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 {
diff --git a/src/app/admin/admin-search-page/admin-search-results/admin-search-result-grid-element/item-search-result/item-admin-search-result-grid-element.component.ts b/src/app/admin/admin-search-page/admin-search-results/admin-search-result-grid-element/item-search-result/item-admin-search-result-grid-element.component.ts
index f41fdbe35c3..a08372ba6e1 100644
--- a/src/app/admin/admin-search-page/admin-search-results/admin-search-result-grid-element/item-search-result/item-admin-search-result-grid-element.component.ts
+++ b/src/app/admin/admin-search-page/admin-search-results/admin-search-result-grid-element/item-search-result/item-admin-search-result-grid-element.component.ts
@@ -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,
diff --git a/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-grid-element/workflow-item/workflow-item-search-result-admin-workflow-grid-element.component.ts b/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-grid-element/workflow-item/workflow-item-search-result-admin-workflow-grid-element.component.ts
index 8fa02efaafe..104c0c0e379 100644
--- a/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-grid-element/workflow-item/workflow-item-search-result-admin-workflow-grid-element.component.ts
+++ b/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-grid-element/workflow-item/workflow-item-search-result-admin-workflow-grid-element.component.ts
@@ -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,
diff --git a/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-grid-element/workspace-item/workspace-item-search-result-admin-workflow-grid-element.component.ts b/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-grid-element/workspace-item/workspace-item-search-result-admin-workflow-grid-element.component.ts
index 8d49b3a8c2d..14460ce0b99 100644
--- a/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-grid-element/workspace-item/workspace-item-search-result-admin-workflow-grid-element.component.ts
+++ b/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-grid-element/workspace-item/workspace-item-search-result-admin-workflow-grid-element.component.ts
@@ -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,
diff --git a/src/app/app.config.ts b/src/app/app.config.ts
index 33a5f830c10..ebe0dae3d1b 100644
--- a/src/app/app.config.ts
+++ b/src/app/app.config.ts
@@ -5,6 +5,10 @@ import {
DOCUMENT,
importProvidersFrom,
} from '@angular/core';
+import {
+ provideClientHydration,
+ withNoHttpTransferCache,
+} from '@angular/platform-browser';
import {
NoPreloading,
provideRouter,
@@ -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,
diff --git a/src/app/core/core.effects.spec.ts b/src/app/core/core.effects.spec.ts
new file mode 100644
index 00000000000..054506fe32b
--- /dev/null
+++ b/src/app/core/core.effects.spec.ts
@@ -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');
+ });
+});
diff --git a/src/app/core/core.effects.ts b/src/app/core/core.effects.ts
index 5af2fe580a1..03db24343f7 100644
--- a/src/app/core/core.effects.ts
+++ b/src/app/core/core.effects.ts
@@ -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';
@@ -19,5 +18,4 @@ export const coreEffects = [
ObjectUpdatesEffects,
RouteEffects,
RouterEffects,
- MenuEffects,
];
diff --git a/src/app/home-page/home-page.component.html b/src/app/home-page/home-page.component.html
index 005844a5936..7251d7a804b 100644
--- a/src/app/home-page/home-page.component.html
+++ b/src/app/home-page/home-page.component.html
@@ -76,7 +76,7 @@
{{'home-page.carousel.deposit.cite'
-
+
{{'home-page.hyperlink.author.message' | translate}}
@for (authorLink of (authors$| async); track authorLink.url) {
@@ -89,7 +89,7 @@
{{'home-page.carousel.deposit.cite'
-
+
{{'home-page.hyperlink.subject.message' | translate}}
@for (subjectLink of (subjects$| async); track subjectLink.url) {
@@ -102,7 +102,7 @@
{{'home-page.carousel.deposit.cite'
-
+
{{'home-page.hyperlink.language.message' | translate}}
@for (languageLink of (languages$| async); track languageLink.url) {
@@ -121,7 +121,7 @@
{{'home-page.carousel.deposit.cite'
-
+
{{'home-page.whats-new.message' | translate}}
diff --git a/src/app/home-page/home-page.component.scss b/src/app/home-page/home-page.component.scss
index d7457fe5914..19261c32fde 100644
--- a/src/app/home-page/home-page.component.scss
+++ b/src/app/home-page/home-page.component.scss
@@ -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%;
diff --git a/src/app/home-page/home-page.component.spec.ts b/src/app/home-page/home-page.component.spec.ts
new file mode 100644
index 00000000000..9f0ffbcbffd
--- /dev/null
+++ b/src/app/home-page/home-page.component.spec.ts
@@ -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
;
+
+ 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);
+ });
+ });
+});
diff --git a/src/app/home-page/home-page.component.ts b/src/app/home-page/home-page.component.ts
index 0347f8aa7bc..e145c00e7ed 100644
--- a/src/app/home-page/home-page.component.ts
+++ b/src/app/home-page/home-page.component.ts
@@ -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';
@@ -95,6 +99,11 @@ export class HomePageComponent implements OnInit {
newItems$: BehaviorSubject- = new BehaviorSubject
- ([]);
topItems$: BehaviorSubject
- = new BehaviorSubject
- ([]);
+ /**
+ * Boxes still waiting for their request. They keep their loaded height until it completes.
+ */
+ loading = new Set(['author', 'subjectFirstValue', 'language', 'new-items']);
+
siteId: string;
baseUrl = '';
@@ -167,13 +176,14 @@ export class HomePageComponent implements OnInit {
sort: sortConfiguration,
dsoTypes: [DSpaceObjectType.ITEM],
}))
- .pipe(getFirstSucceededRemoteDataPayload())
- .subscribe((searchObjects: SearchObjects
- ) => {
+ .pipe(getFirstCompletedRemoteData())
+ .subscribe((rd: RemoteData>) => {
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');
});
}
@@ -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)) {
diff --git a/src/app/item-page/simple/field-components/clarin-files-item-field/clarin-files-item-field.component.html b/src/app/item-page/simple/field-components/clarin-files-item-field/clarin-files-item-field.component.html
index f8b496b8704..4d1ab16ae78 100644
--- a/src/app/item-page/simple/field-components/clarin-files-item-field/clarin-files-item-field.component.html
+++ b/src/app/item-page/simple/field-components/clarin-files-item-field/clarin-files-item-field.component.html
@@ -6,7 +6,7 @@
@for (file of bitstreams; track file; let last = $last) {
-
+
{{file?.name}}
({{(file?.sizeBytes) | dsFileSize }})
@if (!last) {
diff --git a/src/app/item-page/simple/field-components/file-section/file-section.component.html b/src/app/item-page/simple/field-components/file-section/file-section.component.html
index 79440ac6551..e146adbf419 100644
--- a/src/app/item-page/simple/field-components/file-section/file-section.component.html
+++ b/src/app/item-page/simple/field-components/file-section/file-section.component.html
@@ -3,7 +3,7 @@
@for (file of bitstreams; track file; let last = $last) {
-
+
@if (primaryBitstreamId === file.id) {
{{ 'item.page.bitstreams.primary' | translate }}
diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.html
index 8b15eb25d6e..66b16feaee0 100644
--- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.html
+++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.html
@@ -1,5 +1,5 @@
@if (this.relationship.searchConfiguration && context) {
- {
- let menuEffects: MenuEffects;
- let actions: Observable;
- beforeEach(waitForAsync(() => {
- TestBed.configureTestingModule({
- providers: [
- MenuEffects,
- provideMockActions(() => actions),
- ],
- });
- }));
-
- beforeEach(() => {
- menuEffects = TestBed.inject(MenuEffects);
- });
-
- describe('reinitDSOMenus', () => {
- describe('When a REHYDRATE action is triggered', () => {
- let action;
- beforeEach(() => {
- action = new StoreAction(StoreActionTypes.REHYDRATE, null);
- });
- it('should return a ReinitMenuAction', () => {
- actions = hot('--a-', { a: action });
- const expected = cold('--b-', { b: new ReinitMenuAction });
-
- expect(menuEffects.reinitDSOMenus).toBeObservable(expected);
- });
- });
- });
-
-
-});
diff --git a/src/app/shared/menu/menu.effects.ts b/src/app/shared/menu/menu.effects.ts
deleted file mode 100644
index e3216ef0e86..00000000000
--- a/src/app/shared/menu/menu.effects.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { Injectable } from '@angular/core';
-import {
- Actions,
- createEffect,
- ofType,
-} from '@ngrx/effects';
-import { map } from 'rxjs/operators';
-
-import { StoreActionTypes } from '../../store.actions';
-import { ReinitMenuAction } from './menu.actions';
-
-@Injectable()
-export class MenuEffects {
-
- /**
- * When the store is rehydrated in the browser, re-initialise the menus to ensure
- * the menus with functions are loaded correctly.
- */
- reinitDSOMenus = createEffect(() => this.actions$
- .pipe(ofType(StoreActionTypes.REHYDRATE),
- map(() => new ReinitMenuAction()),
- ));
-
- constructor(private actions$: Actions) {
- }
-
-}
diff --git a/src/app/shared/menu/menu.service.spec.ts b/src/app/shared/menu/menu.service.spec.ts
index 5308a04d3cb..54f6cd047af 100644
--- a/src/app/shared/menu/menu.service.spec.ts
+++ b/src/app/shared/menu/menu.service.spec.ts
@@ -235,6 +235,20 @@ describe('MenuService', () => {
expect(result).toBeObservable(expected);
});
+
+ it('should emit again when a top section becomes visible', () => {
+ const emitted: MenuSection[][] = [];
+ service.getMenuTopSections(MenuID.ADMIN).subscribe((sections) => emitted.push(sections));
+
+ store.setState({
+ menus: {
+ 'admin-sidebar': { ...fakeMenu, sections: { ...topSections, section_3: { ...hiddenSection3, visible: true } } },
+ },
+ });
+
+ expect(emitted.map((sections) => sections.map((section) => section.id)))
+ .toEqual([['section', 'section_2'], ['section', 'section_2', 'section_3']]);
+ });
});
describe('getSubSectionsByParentID', () => {
diff --git a/src/app/shared/menu/menu.service.ts b/src/app/shared/menu/menu.service.ts
index 074070d0aa6..b7066d888de 100644
--- a/src/app/shared/menu/menu.service.ts
+++ b/src/app/shared/menu/menu.service.ts
@@ -23,7 +23,7 @@ import {
AppState,
keySelector,
} from '../../app.reducer';
-import { compareArraysUsingIds } from '../../item-page/simple/item-types/shared/item-relationships-utils';
+import { compareArraysUsing } from '../../item-page/simple/item-types/shared/item-relationships-utils';
import {
hasNoValue,
hasValue,
@@ -109,7 +109,7 @@ export class MenuService {
select(menuByIDSelector(menuID)),
select(menuSectionStateSelector),
map((sections: MenuSections) => Object.values(sections)),
- distinctUntilChanged(compareArraysUsingIds()),
+ distinctUntilChanged(compareArraysUsing((section: MenuSection) => `${section.id}:${section.visible}`)),
map((sections: MenuSection[]) => {
return sections
.filter((section: MenuSection) => hasNoValue(section.parentID))
diff --git a/src/app/shared/ssr-path.util.spec.ts b/src/app/shared/ssr-path.util.spec.ts
new file mode 100644
index 00000000000..783224a6359
--- /dev/null
+++ b/src/app/shared/ssr-path.util.spec.ts
@@ -0,0 +1,30 @@
+import { Request } from 'express';
+
+import { getSsrPath } from './ssr-path.util';
+
+describe('getSsrPath', () => {
+ function request(path: string, query: Record = {}): Request {
+ return { path, query } as unknown as Request;
+ }
+
+ it('should return the request path', () => {
+ expect(getSsrPath(request('/items/abc'), '/')).toEqual('/items/abc');
+ });
+
+ it('should return the redirect target of a reload after login', () => {
+ expect(getSsrPath(request('/reload/1', { redirect: '/access-control/bulk-access?page=2' }), '/'))
+ .toEqual('/access-control/bulk-access');
+ });
+
+ it('should drop the UI namespace from the redirect target', () => {
+ expect(getSsrPath(request('/reload/1', { redirect: '/repository/health' }), '/repository')).toEqual('/health');
+ });
+
+ it('should resolve a relative redirect target from the root, like the router', () => {
+ expect(getSsrPath(request('/reload/1', { redirect: 'health' }), '/')).toEqual('/health');
+ });
+
+ it('should return the request path of a reload without a redirect', () => {
+ expect(getSsrPath(request('/reload/1'), '/')).toEqual('/reload/1');
+ });
+});
diff --git a/src/app/shared/ssr-path.util.ts b/src/app/shared/ssr-path.util.ts
new file mode 100644
index 00000000000..4d8fa280e80
--- /dev/null
+++ b/src/app/shared/ssr-path.util.ts
@@ -0,0 +1,19 @@
+import { Request } from 'express';
+
+/**
+ * Path that server.ts checks against ssr.excludePathPatterns.
+ * A hard reload (after login, for example) goes through /reload/