Closed ManuelRauber closed 4 days ago
This behavior is intended. The application will be bootstrapped during the build process to validate and extract all routes, generating an SSR manifest.
In the future, file-based routing may address this issue.
Currently, you can set the environment variable NG_BUILD_PARTIAL_SSR=1
, but be aware that this will slow down the first request and may cause validation errors to appear at runtime instead of during the build process.
This behavior is intended. The application will be bootstrapped during the build process to validate and extract all routes, generating an SSR manifest.
In the future, file-based routing may address this issue.
Currently, you can set the environment variable
NG_BUILD_PARTIAL_SSR=1
, but be aware that this will slow down the first request and may cause validation errors to appear at runtime instead of during the build process.
Hm, interesting, since the behaviour is different to the non-hybrid SSR, but I understand why it is necessary at the moment.
For my use case, I think I can safely use a mock value when inject(REQUEST)
is null, which will happen during build time since I don't have pre-generated routes.
Or is there any possibility to detect build-time explicitly?
Or is there any possibility to detect build-time explicitly?
No there isn't a way
Or is there any possibility to detect build-time explicitly?
No there isn't a way
I've checked using the mock object, but that's not working for me.
So, I need to use the usual SSR approach for now.
You can close this issue if you want, since the original behavior is intended and does not fit my use case. :-)
Command
build
Is this a regression?
The previous version in which this bug was not present was
No response
Description
For my use-case I use Angular 19 Hybrid SSR. For now, I only need the SSR part, not making use of any other
RenderMode
, but I want to keep the doors open for later.During the bootstrap of the application I'm using an app initializer to get some data via HTTP. The website cannot run without it (think of getting different configurations from an API depending on the hostname), so it makes sense to get the data as soon as possible and assume the website always runs with a preloaded configuration.
When I use Angular SSR my builds works as expected. When I sure Angular Hybrid SSR my build hangs because it tries to make a request to the API which is not available on the build server.
The configuration for Hybrid SSR is:
As you can see, there's no pre-rendering involved.
I want to use Hybrid SSR because it makes use of the same request handler during development where the normal SSR uses its own internal SSR middleware. Using the same handler seems more error-proof to me.
Minimal Reproduction
For both examples make sure to have Angular 19 installed.
Example with Angular SSR
ng new v19ssr --ssr
app.config.ts
add an app initializer:provideAppInitializer(() => console.log('Hello'))
angular.json
change the existingprerender
tofalse
.ng build
Observe, that there is no
Hello
in your console. This is as it should be.Example with Angular Hybrid SSR
ng new v19ssrSR --ssr --server-routing
app.config.ts
add an app initializer:provideAppInitializer(() => console.log('Hello'))
app.routes.server.ts
switch the render mode toServer
angular.json
change theoutputMode
toserver
ng build
Observe, that there is
Hello
in your console, so the whole app has been boostrapped even when there is no route to prerender.Exception or Error
Your Environment
Anything else relevant?
No response