Hello,
I’m making my Angular code SSR-safe and I’m torn between two approaches for browser APIs (localStorage, matchMedia, ResizeObserver, etc.):
- Provide an injection token for the API (derived from
DOCUMENT, or a platform check) with a safe mock/fallback on the server, and inject it everywhere. - Use
afterNextRender, which only runs in the browser, so the plain browser API inside it is safe and no mock is needed.
How do you handle this in real projects?
Thanks!