Repository navigation
feat(@angular/ssr): add server routing configuration API - #28346
Conversation
0582d70 to
90bb423
Compare
90bb423 to
60be7e5
Compare
60be7e5 to
01df293
Compare
6fe6e24 to
40c6fe7
Compare
40c6fe7 to
7815301
Compare
44c284d to
c1da755
Compare
dgp1130
left a comment
There was a problem hiding this comment.
Great stuff here @alan-agius4! Glad to see this all coming together. 😁
| ); | ||
| } | ||
|
|
||
| const parameters = await runInInjectionContext(parentInjector, () => getPrerenderPaths()); |
There was a problem hiding this comment.
Question: How does runInInjectionContext handle async callbacks? getPrerenderPaths() might return a Promise. What happens for:
function getPrerenderPaths() {
await someAsyncWork();
const service = inject(SomeService); // Can we inject after an `await`?
}There was a problem hiding this comment.
No, the inject needs to happen before any async work.
function getPrerenderPaths() {
const service = inject(SomeService); // Can we inject after an `await`?
await someAsyncWork();
}
There was a problem hiding this comment.
Is there any precedent for Angular APIs which are naturally async but run in an injection context? This feels like an easy tripping hazard.
I guess the workaround would be to keep a reference to the injector (or inject before the await like you suggested)?
async function getPrerenderPaths() {
const injector = inject(Injector);
const result = await someAsyncWork();
if (result === something) {
injector.inject(SomethingElse);
}
}/cc @AndrewKushnir is this something we should be concerned about?
There was a problem hiding this comment.
Both guards and interceptors run in an injection context.
d82eda1 to
bb0ca53
Compare
bb0ca53 to
3a932de
Compare
3a932de to
22b4016
Compare
22b4016 to
041f1df
Compare
|
Thanks for working through this @alan-agius4! My only remaining concern is the choice of default value for |
AndrewKushnir
left a comment
There was a problem hiding this comment.
LGTM, just a few minor comments, mostly related to error message text improvements.
cb69759 to
f14ef08
Compare
77744f4 to
df3715f
Compare
This commit introduces a new server routing configuration API, as discussed in RFC angular/angular#56785. The new API provides several enhancements: ```ts const serverRoutes: ServerRoute[] = [ { path: '/error', renderMode: RenderMode.Server, status: 404, headers: { 'Cache-Control': 'no-cache' } } ]; ``` ```ts const serverRoutes: ServerRoute[] = [ { path: '/product/:id', renderMode: RenderMode.Prerender, async getPrerenderPaths() { const dataService = inject(ProductService); const ids = await dataService.getIds(); // Assuming this returns ['1', '2', '3'] return ids.map(id => ({ id })); // Generates paths like: [{ id: '1' }, { id: '2' }, { id: '3' }] } } ]; ``` ```ts const serverRoutes: ServerRoute[] = [ { path: '/product/:id', renderMode: RenderMode.Prerender, fallback: PrerenderFallback.Server, // Can be Server, Client, or None async getPrerenderPaths() { } } ]; ``` ```ts const serverRoutes: ServerRoute[] = [ { path: '/product/:id', renderMode: RenderMode.Server, }, { path: '/error', renderMode: RenderMode.Client, }, { path: '/**', renderMode: RenderMode.Prerender, }, ]; ``` These additions aim to provide greater flexibility and control over server-side rendering configurations and prerendering behaviors.
df3715f to
b54d412
Compare
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This commit introduces a new server routing configuration API, as discussed in RFC angular/angular#56785. The new API provides several enhancements:
These additions aim to provide greater flexibility and control over server-side rendering configurations and prerendering behaviors.