angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.75k stars 11.98k forks source link

"prerender": false is ignored with "outputMode": "server" #28590

Closed zip-fa closed 11 hours ago

zip-fa commented 1 day ago

Command

build

Is this a regression?

The previous version in which this bug was not present was

No response

Description

Hi. "prerender": false is ignored with "outputMode": "server": angular tries to prerender all my routes and i receive "undefined" message on routes extraction step:

Image

ng build command now only reacts to "export NG_BUILD_PARTIAL_SSR=true && ng build" - build does not fail with this setup

Minimal Reproduction

ng build

Exception or Error

No response

Your Environment

v19.0.0-next.8

Anything else relevant?

No response

alan-agius4 commented 1 day ago

It is by design that the prerender option is ignored.

The outputMode is only intended to be used with the new SSR APIs, where the rendering modes are configured at route level.

That being said, the error is definitely not helpful, can you please provide a minimal reproduction?

zip-fa commented 1 day ago

My current serverRoutes config is:

import type { ServerRoute } from '@angular/ssr';
import { RenderMode } from '@angular/ssr';

export const serverRoutes: ServerRoute[] = [
  {
    path: '**',
    renderMode: RenderMode.Server,
    headers: {
      'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate',
      'Pragma': 'no-cache',
      'Expires': '0',
      'Surrogate-Control': 'no-store'
    }
  }
];

app.config.server is:

import { mergeApplicationConfig } from '@angular/core';
import { provideServerRendering } from '@angular/platform-server';
import { provideServerRoutesConfig } from '@angular/ssr';

import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';

export const config = mergeApplicationConfig(appConfig, {
  providers: [provideServerRendering(), provideServerRoutesConfig(serverRoutes)]
});

Shouldn't prerender be completly disabled with this configuration? About "undefined" error: i will make repro in some time & add another comment

alan-agius4 commented 1 day ago

With this config, indeed none of the routes will be pre-rendered. Although the application will still be bootstrapped during the build to generate the SSR manifest.

zip-fa commented 1 day ago

Alright, it took me 2 hours to find the cause of "undefined" error.

I've modified prerender.js directly in node_modules :)) Image

To find this:

Image

zip-fa commented 1 day ago

I've added catchError with isPlatformServer check to my global http interceptor and now everything works perfect: