feat(@angular/ssr): introduce DI token to signal route discovery process#32491
feat(@angular/ssr): introduce DI token to signal route discovery process#32491alan-agius4 wants to merge 1 commit intoangular:mainfrom
Conversation
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
| * 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'); |
There was a problem hiding this comment.
| 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 ?
There was a problem hiding this comment.
Ohhh. Good catch.
dgp1130
left a comment
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
dgp1130
left a comment
There was a problem hiding this comment.
Actually one other thought: Can we have a test somewhere that discovering routes sets this token correctly while SSR/CSR does not?
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 valuetruewithin 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