afterNextRender registers a callback that runs once on the client after server-side rendering and the subsequent render. It prevents browser-only APIs such as window, document, and location from executing during SSR. Angular introduced it alongside afterRender in v16; use afterRender when the callback must run after every render. section 9.2.3
Client-only scroll listener
A scroll-to-top component registers its window scroll listener inside afterNextRender. The listener toggles button visibility after scrolling beyond 100 pixels, while the component uses ChangeDetectorRef to update the view. Because registration occurs once, the listener can operate independently afterward.
