Repository navigation
[dtq-dev-93] Enable Angular hydration so pages are not drawn again after load - #1765
Open
milanmajchrak wants to merge 9 commits into
Open
milanmajchrak wants to merge 9 commits into
milanmajchrak wants to merge 9 commits into
Conversation
Provide hydration on the server too, so the browser reuses the server DOM. ThemedComponent lets Angular remove its wrapper and skips hydration when content is projected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The facet lists and the new items box keep their loaded height while empty, so the footer and the content below do not jump when they fill. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Themed wrappers whose projected content has control flow get a static ngSkipHydration, and the admin grid elements that project raw DOM nodes skip it too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The host binding removed it when no content was projected. The server then wrote hydration data for a wrapper that the browser skips. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reserved height now follows a loading flag that is cleared when the request completes, not the presence of content. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The browser reset every menu on REHYDRATE. The admin sidebar was then hidden until the menu providers had checked the rights again, and slid back in. For a logged-in admin this shifted the whole page. The server state already holds the built menus. The browser menu providers replace each section by id, click handlers included. So the reset is not needed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
After login the app reloads through /reload/<time>?redirect=<url>. Excluded pages were rendered there, and the nested buttons in the health and bulk access accordions broke hydration of the whole page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A reload is served by CSR when its own path or its target is excluded. A relative redirect target is matched from the root, like the router does. The top menu sections are compared after the visibility filter, so a section the browser shows after the server hid it is drawn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sub sections still trigger the top sections again, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References
Replaces the 7.6 anti-flicker overlay from #1287 (5c9c6bc), which was not ported to v9. Angular hydration does the same job without a mask.
Upstream DSpace has the same gap:
provideClientHydration()only inbrowser-app.config.ts. Upstream issues "Full-screen flash as server-side rendered HTML is re-rendered in the browser" and "Further optimize initial page load by leveraging preboot" describe it. No upstream fix yet. Upstream main also has theMenuEffectsreset on REHYDRATE.Description
The browser now reuses the server-rendered page (Angular hydration) instead of drawing it again. The measured pages no longer jump after load, for anonymous users and for a logged-in admin.
Instructions for Reviewers
List of changes in this PR:
provideClientHydration(withNoHttpTransferCache())moved frombrowser-app.config.tsto the sharedcommonAppConfig. Now the server writes the hydration data. Before, the browser found none and silently drew the page from scratch. The HTTP transfer cache is off, because REST data already reaches the browser in the NgRx transfer state.ThemedComponent: the<div #content>wrapper for projected content is now inside@if (!compRef). Before, the code removed it withnativeElement.remove(). Angular did not know that, so the browser looked for the div and hydration failed withNG0500on<ds-root>.ThemedComponent: a wrapper with projected content getsngSkipHydrationon its host. Angular cannot hydrate DOM nodes passed tocreateComponentasprojectableNodes(the server throwsNG0503). Only that wrapper is drawn again in the browser. A staticngSkipHydrationset in a template is kept, also when nothing is projected.@ifor@for, the parent template also puts a staticngSkipHydrationon the wrapper (vanilla file section, CLARIN files field, relation lookup search tab). Angular reads the static attribute to decide whether a block inside the wrapper is hydrated. With the host binding alone, such a block broke when the same template had been rendered once without hydration on that page:NG0500and 4 file rows instead of 2. The CLARIN item pages do not use these file components, so today this is a safeguard.projectableNodesgethost: { ngSkipHydration: 'true' }./admin/is excluded from SSR by default. Without this, a deployment that renders it on the server would hitNG0503.MenuEffectsis removed. It reset every menu on REHYDRATE, so for a logged-in admin the sidebar disappeared and slid back in after load. The browser adds all menu sections again after REHYDRATE (initPersistentMenusand the route menus run afterloadAppState), click handlers included, so the reset is not needed.MenuService.getMenuTopSections()now compares sections by id and visibility, so a section the browser shows after the server hid it (for example after a failed authorization request during SSR) is drawn.server.tsserves/reload/<time>?redirect=<url>(used after login, logout and a language change) with CSR when/reloador the redirect target is excluded from SSR. A relative target is matched from the root, like the router does. Before, excluded pages such as/access-control/bulk-accessand/healthwere rendered on the server after login. Their accordions put a<button>inside the accordion button, the browser moves those nodes, and hydration of the whole page failed (NG0501).withEnabledBlockingInitialNavigation()stays. Angular prints the dev-mode warningNG05001for it, and its docs say not to combine it with hydration. Hydration works on every page tested.CLS, anonymous, prod build (Playwright Chromium, 1400x900, cold cache, median of 3-5 loads, REST from the v9 test instance):
Home at 375x812: 0.42 with hydration only, 0.02 with the reserved space. The loaded home page looks the same as before at 14 widths from 375 to 1920 px.
Logged in as admin (local stack, same method, median of 5): home 0.94 → 0.0025, item 1.02 → 0.0004. Without the
MenuEffectschange it was 0.16 / 0.07. The admin sidebar actions and the item edit menu work, also on the first click after load.How to test:
npm run build:prod, thennpm run serve:ssr.view-source:showsngh="..."attributes and an<!--nghm-->comment.ng build --configuration developmentplusng run dspace-angular:server:development, withssr.enabled: true) logsAngular hydrated N component(s)and noNG0500-NG0507errors. If the server asks for a hasheden.<hash>.json, copyen.jsonto that name.npm run test -- --include=src/app/shared/theme-support/themed.component.spec.tsnpm run test -- --include=src/app/home-page/home-page.component.spec.tsnpm run test -- --include=src/app/core/core.effects.spec.tsnpm run test -- --include=src/app/shared/ssr-path.util.spec.tsnpm run test -- --include=src/app/shared/menu/menu.service.spec.tsCodex review (gpt-6.2-sol, high), 3 rounds: 3 findings fixed (projected
@ifin a themed wrapper, admin grids with rawprojectableNodes, home space kept after an empty or failed request). Not changed in this PR:<div>inside a<p>, so a server-rendered grid search would fail to hydrate./searchis not rendered on the server by default (excludePathPatterns,enableSearchComponent: false).dspace.ui.urlcannot be read. Both mean REST is already failing.A 4th Codex run on the
MenuEffectsand/reloadcommits found 3 more issues, all fixed (menu visibility after REHYDRATE, relative redirect target, an explicit/reloadexclusion); its other 2 are the REST failure cases above. The nested buttons in the health and bulk access accordions are not changed: both pages are excluded from SSR by default.Checklist
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.🤖 Generated with Claude Code