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
{{ message }}
Repository navigation
Add render timeout to renderModule and renderApplication functions #51549
area: serverIssues related to server-side renderingfeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under consideration
What modules are relevant for this feature request?
aspnetcore-engine
builders
common
express-engine
hapi-engine
Description
Should have a way to set timeout. So if angular universal render more than certain time, it should throw a timeout error.
It is highly possible certain links in the backend are broken at some point, without timeout it will be hanging there.
Have you considered any alternative solutions or workarounds?
Reacted by Krzysztof Platis, cgrantnz, Piotr Błaszczak, Henry, Troy Steuwer, Orestis Ioakeimidis, Alan Agius, Matthieu Riegler, Sam Lin and Dominik König
This feature will be very useful. For now I just did this simple trick to handle timeouts.
// All regular routes use the Universal engineserver.get('*',(req: express.Request,res: express.Response)=>{consttimeoutAfter=1000;// timeout after 1sconstindexFile=join(distFolder,'index.html');letisActive=setTimeout(()=>{console.error(`TIMEOUT after ${timeoutAfter}ms on `,req.url);isActive=null;consthtml=readFileSync(indexFile).toString()+'<!-- data-cy=error-timeout -->';res.status(200).send(html);},timeoutAfter)res.render(indexHtml,{
req,
res,},(err: Error,html: string)=>{if(err)console.error(err);if(isActive){clearTimeout(isActive);// clear timeout if response comes first}else{return;// if timeout, response is already sent}if(!html){// if there is error, just render index.html, it's better then 500 errorhtml=readFileSync(indexFile).toString()+'<!-- data-cy=error -->';}res.status(200).send(html);},);});
@alan-agius4 I think we should consider adding this config option to the renderApplication and renderModule functions (within @angular/platform-server) and potentially also expose them via APIs from @angular/ssr.
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
Hi @alan-agius4@AndrewKushnir
IMHO we should take care not only of rendering timeouts but also any custom error propagation from Angular app to Express in SSR (or worker in case of SSG).
Currently, when any async error happens in a custom Angular app (e.g. unhandled TypeError 'cannot use property x of undefined' or we receive a HTTP error response from the upstream backend API), we have no way OOTB in Angular to reject the rendering. Therefore even if an fatal async error happens during the rendering, OOTB we respond with 200 HTTP status from SSR to the client (or save the html file in SSG) - which is bad for SEO, because malformed HTML might be indexed by google
Instead, we should be able to reject from Angular renderModule or renderApplication and thanks to this return HTTP 500 status from SSR to the client (or don't save the html file in SSG).
Summing up, it's not only timeouts that are important for SEO, but error handling in general too.
FYI in our Angular library "Spartacus" we're building now an Angular SSR Error Handling feature - a custom wrapper over CommonEngine to be able to populate errors from Angular app to the SSR. Internally we created a custom injection token PROPAGATE_SERVER_ERROR_RESPONSE = new InjectionToken<Function> that we call in our custom ErrorHandler class in case of any unhandled exception in the app (+ in case of any HTTP error response from the backend; intercepted in HttpInterceptor).
Note: I've described this issue already in Angular repo issues here: #50829
area: serverIssues related to server-side renderingfeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under consideration
Activity
myflowpl commentedon Dec 21, 2021
This feature will be very useful. For now I just did this simple trick to handle timeouts.
alan-agius4 commentedon Aug 29, 2023
@AndrewKushnir do you think this should be part of
@angular/platform-serveror@angular/ssr?angular-robot commentedon Aug 29, 2023
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.
Find more details about Angular's feature request process in our documentation.
AndrewKushnir commentedon Aug 29, 2023
@alan-agius4 I think we should consider adding this config option to the
renderApplicationandrenderModulefunctions (within@angular/platform-server) and potentially also expose them via APIs from@angular/ssr.[-]add render timeout [/-][+]Add render timeout to `renderModule` and `renderApplication` functions[/+]angular-robot commentedon Sep 17, 2023
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
Platonn commentedon May 10, 2024
Hi @alan-agius4 @AndrewKushnir
IMHO we should take care not only of rendering timeouts but also any custom error propagation from Angular app to Express in SSR (or worker in case of SSG).
Currently, when any async error happens in a custom Angular app (e.g. unhandled TypeError 'cannot use property x of undefined' or we receive a HTTP error response from the upstream backend API), we have no way OOTB in Angular to reject the rendering. Therefore even if an fatal async error happens during the rendering, OOTB we respond with 200 HTTP status from SSR to the client (or save the html file in SSG) - which is bad for SEO, because malformed HTML might be indexed by google
Instead, we should be able to reject from Angular
renderModuleorrenderApplicationand thanks to this return HTTP 500 status from SSR to the client (or don't save the html file in SSG).Summing up, it's not only timeouts that are important for SEO, but error handling in general too.
FYI in our Angular library "Spartacus" we're building now an Angular SSR Error Handling feature - a custom wrapper over CommonEngine to be able to populate errors from Angular app to the SSR. Internally we created a custom injection token
PROPAGATE_SERVER_ERROR_RESPONSE = new InjectionToken<Function>that we call in our custom ErrorHandler class in case of any unhandled exception in the app (+ in case of any HTTP error response from the backend; intercepted in HttpInterceptor).Note: I've described this issue already in Angular repo issues here: #50829