Skip to content

Observables Called Twice in Dev SSR Server #29084

Closed as not planned
Closed as not planned

Description

@lennybakkalian

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

platform-server

Is this a regression?

No

Description

In Angular SSR, observables are triggered (at least) twice on the server during the first page load. To demonstrate this issue, I created a fresh Angular project on StackBlitz. This only happen when running a dev server -> in prod, this behaviour doesnt happen.

Additionally, the provideAppInitializer function is also called twice. Afterward, everything works as expected without duplicate calls.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/~/github.com/lennybakkalian/angular-bug?file=src/app/app.component.ts

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

Angular CLI: 19.0.4
Node: 20.17.0
Package Manager: npm 10.8.2
OS: darwin arm64

Angular: 19.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.4
@angular-devkit/build-angular   19.0.4
@angular-devkit/core            19.0.4
@angular-devkit/schematics      19.0.4
@angular/cli                    19.0.4
@angular/ssr                    19.0.4
@schematics/angular             19.0.4
rxjs                            7.8.1
typescript                      5.6.3
zone.js                         0.15.0

Activity

  1. changed the title [-]Observables Called Twice on Initial Page Load in SSR[/-] [+]Observables Called Twice on the Server in SSR[/+] on Dec 8, 2024
  2. changed the title [-]Observables Called Twice on the Server in SSR[/-] [+]Observables Called Twice on the Server (SSR)[/+] on Dec 8, 2024
  3. transferred this issue fromangular/angularon Dec 8, 2024
  4. changed the title [-]Observables Called Twice on the Server (SSR)[/-] [+]Observables Called Twice in Dev SSR Server[/+] on Dec 8, 2024
  5. alan-agius4 commented on Dec 8, 2024

    @alan-agius4
    Collaborator

    This is expected. During the first request in development, the application bootstraps to extract the routes and build a routing table. After this initial process, the application is re-bootstrapped to render the request as usual. In production, this step doesn't occur because the routes are extracted during the build process.

  6. lennybakkalian commented on Dec 8, 2024

    @lennybakkalian
    Author

    @alan-agius4 Thank you for your answer. Are you sure that the observables need to be subscribed to? i don't see why it is necessary to subscribe to an observable to create the routing table. i personally think this should still be included as a bug ticket, as this is an inconsistency between backend and frontend and causes unexpected behavior in the dev server.

    Example:
    A user is created during page load by subscribing to an observable.
    Currently, this observable is called twice (because of this route table generation) on the first page load as soon as you start the app in the dev server.
    In my opinion, this is a very negative developer experience if there are suddenly 2 users in the database.

  7. alan-agius4 commented on Dec 9, 2024

    @alan-agius4
    Collaborator

    Discussion in #29085

  8. angular-automatic-lock-bot commented on Jan 9, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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