Skip to content

feat(@angular/ssr): introduce DI token to signal route discovery process#32491

Open
alan-agius4 wants to merge 1 commit intoangular:mainfrom
alan-agius4:route-extractor
Open

feat(@angular/ssr): introduce DI token to signal route discovery process#32491
alan-agius4 wants to merge 1 commit intoangular:mainfrom
alan-agius4:route-extractor

Conversation

@alan-agius4
Copy link
Collaborator

A new DI token, DURING_ROUTE_DISCOVERY, is introduced to provide a clear signal for when the application is operating in route discovery mode. This token is provided with the value true within the route extraction providers. Other services and components can inject this token to conditionally alter their behavior, for instance, to disable functionality that is not required or could interfere with the route discovery process.

Closes #32474

A new DI token, `DURING_ROUTE_DISCOVERY`, is introduced to provide a clear signal for when the application is operating in route discovery mode.
This token is provided with the value `true` within the route extraction providers. Other services and components can inject this token to conditionally alter their behavior, for instance, to disable functionality that is not required or could interfere with the route discovery process.

Closes angular#32474
@alan-agius4 alan-agius4 requested a review from dgp1130 February 13, 2026 15:25
@alan-agius4 alan-agius4 added target: minor This PR is targeted for the next minor release action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 13, 2026
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: @angular/ssr labels Feb 13, 2026
* disable features or behaviors that are not necessary or might interfere with the route
* discovery process.
*/
export const DURING_ROUTE_DISCOVERY = new InjectionToken<boolean>('DURING_ROUTE_DISCOVERY');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const DURING_ROUTE_DISCOVERY = new InjectionToken<boolean>('DURING_ROUTE_DISCOVERY');
export const DURING_ROUTE_DISCOVERY = new InjectionToken<boolean>('DURING_ROUTE_DISCOVERY', {
factory: () => false
});

Should this have a default value? As this will run in browser mode too I guess ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh. Good catch.

Copy link
Collaborator

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

My personal opinion is that we would want to discourage overall use of this token as I think server startup should be generally cheap, hermetic, and stable (in the sense that it does the same thing every time). If you rely on unique runtime dependencies which you don't need for route discovery and are problematic for that use case, I feel like there are potentially better ways to accomplish what most developers need.

That said, reality is always messy and I can see cases where this is useful or Angular is lacking the higher-level APIs which might be a better fit, so no objection from me on landing this.

* disable features or behaviors that are not necessary or might interfere with the route
* discovery process.
*/
export const DURING_ROUTE_DISCOVERY = new InjectionToken<boolean>('DURING_ROUTE_DISCOVERY');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider: The naming feels a little awkward to me to start with "during". I wonder if IS_DISCOVERING_ROUTES or IS_BOOTSTRAPPING_FOR_ROUTES or something like that might be more clear as a boolean value? Up to you in the end.

Copy link
Collaborator

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually one other thought: Can we have a test somewhere that discovering routes sets this token correctly while SSR/CSR does not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/ssr detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow detecting or skipping APP_INITIALIZERs during build-time route-extraction phase, with outputMode: server

3 participants