Skip to content

Angular SSR/Hydration: Unexplained Third Execution of Initializer/Hooks on Server #32125

@mmart1n

Description

@mmart1n

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

🚀 Angular SSR/Hydration: Unexplained Third Execution of Initializer/Hooks on Server

Hello,

I am working on an Angular 20 project with Server-Side Rendering (SSR) and Client Hydration enabled. I have noticed unusual behavior during the initial page load involving application initializers and component lifecycle hooks.

My Setup:

  • Angular Version: 20.x.x
  • SSR: Enabled with Client Hydration (provideClientHydration())
  • Data Fetching: A required HTTP request is initiated inside a function provided via provideAppInitializer() (or inside the AppComponent's constructor/ngOnInit).
  • State Transfer: Configured correctly (the client is successfully reusing the first server response).

The Observed Behavior:

On a fresh page load, my logging shows that the root component's constructor, ngOnInit, and the provideAppInitializer callback are executed three times in the following sequence:

Execution Event Environment HTTP Request Made? Expected Behavior?
1st Hook Run Server (Node.js) YES Expected: Initial Server Render
2nd Hook Run Browser (Client) NO (Transferred) Expected: Client Hydration
3rd Hook Run Server (Node.js) YES UNEXPECTED

The Anomaly:

The most confusing part is the third execution, which occurs on the server again after the client has started the hydration process. This third execution triggers a second, redundant HTTP request from the server, causing unnecessary load.

  • Total Hook/Initializer Runs: 3 (Server, Client, Server)
  • Total HTTP Requests: 2 (Both from the Server)

My Question:

Is this triple execution and the resulting extra server-side HTTP call a known issue, or does it indicate an incorrect configuration or a deeper problem with how I am utilizing provideAppInitializer alongside modern Angular SSR and Hydration?

Thank you for any insight or guidance!

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)


Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions