You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
@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.
Activity
[-]Observables Called Twice on Initial Page Load in SSR[/-][+]Observables Called Twice on the Server in SSR[/+][-]Observables Called Twice on the Server in SSR[/-][+]Observables Called Twice on the Server (SSR)[/+][-]Observables Called Twice on the Server (SSR)[/-][+]Observables Called Twice in Dev SSR Server[/+]alan-agius4 commentedon Dec 8, 2024
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.
lennybakkalian commentedon Dec 8, 2024
@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.
alan-agius4 commentedon Dec 9, 2024
Discussion in #29085
angular-automatic-lock-bot commentedon Jan 9, 2025
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.