SSR & Hydration
Render useful HTML on the server, reuse it in the browser and keep component identity, state and interaction deterministic across the boundary.
RENDERING STRATEGY
Choose a mode per route
Angular supports server rendering per request, build-time prerendering and client rendering. NeuralNg does not force one mode; the same component contracts remain valid in each.
SSR
Personalized or frequently changing public content.
SSG
Documentation, marketing and other cacheable routes.
CSR
Private tools where initial HTML and SEO are not priorities.
Enable hydration once at application level
provideClientHydration() lets Angular reconcile and reuse server-rendered DOM. Event replay captures supported interactions that occur before hydration finishes. Angular 22 enables incremental hydration through this provider by default.
What NeuralNg guarantees
Components render meaningful closed or inactive server markup without requiring browser globals. Browser-only positioning, focus, storage and top-layer work starts after the browser takes ownership.
Deterministic identity
APP_ID-scoped generators and explicit ID inputs preserve ARIA relationships.
Browser guards
DOM measurements, observers and global listeners do not execute on the server.
Closed overlays
Popup positioning and focus work begin only after a client-side open action.
Lifecycle cleanup
Observers, listeners, top-layer state and focus ownership are released on destroy.
Server and browser must render the same tree
The initial locale, direction, collection order, selected values, open state and conditional branches must agree. Prefer explicit public IDs for important forms and composite widgets; generated IDs are deterministic only while component creation order remains identical.
Common mismatch sources
- Random IDs or current time in templates
- Viewport-dependent initial branches
- Browser storage read during rendering
- Different server and client locale
- Invalid HTML corrected by the browser
- Direct DOM insertion before hydration
Defer browser-only enhancement
Use Angular render callbacks for measurement, focus and third-party browser APIs. Use isPlatformBrowser in reusable services that must expose a safe server no-op. Do not scatter eager window and document reads through component constructors.
Overlay markup starts stable and closed
Select, MultiSelect, AutoComplete, TreeSelect, Popover, Tooltip, Dialog and Drawer postpone top-layer positioning and focus work until the browser. An appendTo="body" panel is moved only after opening, never while server HTML is being produced.
Transfer initial data instead of requesting it twice
Angular hydration includes HTTP transfer caching for eligible server requests. Keep the initial result serializable, preserve collection order and avoid emitting a temporary empty state in the browser before transferred data resolves.
Serialize
Dates, Maps and class instances need an explicit wire representation.
Authorize
Never expose server-only credentials or private provider state in HTML.
Revalidate
Treat transferred data as the initial snapshot, then refresh through application policy.
Hydrate expensive regions when they become useful
Incremental hydration combines server-rendered @defer content with hydrate triggers. Reserve it for meaningful boundaries; splitting every small control increases complexity without improving the user journey.
The server-rendered block and its placeholder must reserve compatible space. Event replay is automatically available with Angular's incremental hydration.
Diagnose the production path
A client-only development server cannot prove SSR safety. Build the production target, inspect the returned HTML with JavaScript disabled, then use Angular DevTools and the browser console to locate hydrated nodes and mismatches.
Deployment checklist
Every public route produces useful HTML before JavaScript.
Server and browser start with identical locale, direction and form state.
No initial branch depends on time, randomness, viewport or browser storage.
Explicit IDs are used for critical label, hint and overlay relationships.
Early interactions survive hydration and do not execute twice.
Overlays restore focus and leave no document listeners after navigation.
Hydration is tested in the deployed runtime, not only the CSR dev server.