NG.IX · Angular 22 practice question

A developer enables SSR on an existing Angular component that reads navigator.language and location.pathname inside its constructor. Why does this break server-side rendering?

Choose one answer
Check answer and explanation

Correct answer: Browser-specific globals such as navigator, location, window, and document are not available in the server environment.

Explanation

Browser-specific globals such as navigator, location, window, and document (along with certain HTMLElement properties) are not available on the server, so accessing them directly during SSR causes errors.

Common trap

Moving the reads from the constructor to ngOnInit is a common misconception, because ngOnInit also executes during server-side rendering where those browser globals still do not exist. Believing the compiler strips navigator and location is tempting, yet Angular does not remove them—runtime execution on the server simply lacks those browser APIs.

Source: Angular docs: Server and hybrid rendering — Authoring server-compatible components
Checked against the cited text on 2026-11-25.

Report an error in this question