Giter VIP home page Giter VIP logo

Comments (8)

alan-agius4 avatar alan-agius4 commented on May 12, 2024

Hi @chriswoodie, the provided code in the stackoverflow issue does work in an ng new application. Thus, the issue might be something else.

Kindly provide a minimal reproduction. Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

from angular.

chriswoodie avatar chriswoodie commented on May 12, 2024

@alan-agius4 Here you go: https://github.com/chriswoodie/status-repro

Steps to reproduce:

  1. Clone repo
  2. npm install
  3. ng build sdk
  4. ng build
  5. npm run serve:ssr:repro-app

Go to http://localhost:4000/404 and check network status for the 404 page, you will see a 200 status instead of 404.

Turns out it's because of prerendering. If you set this to false for the project in angular.json the status code will be 404, which is correct.

Not sure if this is a bug or intended behaviour?

from angular.

alan-agius4 avatar alan-agius4 commented on May 12, 2024

This is the indented behaviour when using prerendering, since there is no request/response information. If a page depends on such information prerendering needs to be opted out for that page.

from angular.

chriswoodie avatar chriswoodie commented on May 12, 2024

@alan-agius4 Got it, I think this should be mentioned in the documentation because I had no idea about this. Would've saved me days of debugging and others will probably benefit from this too.

from angular.

chriswoodie avatar chriswoodie commented on May 12, 2024

@alan-agius4 Also, how do you opt out a page from prerendering? Can't find this in the docs either. I can only find the option to manually specify which routes to include, not exclude.

from angular.

alan-agius4 avatar alan-agius4 commented on May 12, 2024

At the moment the only way to do it is to disable auto route discovery. https://angular.io/guide/prerendering#build-options-for-prerender

from angular.

hittten avatar hittten commented on May 12, 2024

Indeed, several things about SSR need to be documented, for example since the move from @nguniversal/express-engine to @angular/ssr the express tokens were lost:

https://github.com/angular/universal/blob/e798d256de5e4377b704e63d993dc56ea35df97d/modules/express-engine/tokens/injection-tokens.ts

I have published a repo with the minimum to recreate the SSR problem with angular 17: https://github.com/hittten/angularSSR17

Clone & Setup:

git clone https://github.com/hittten/angularSSR17
npm install
npm start

logs

if you navigate to http://localhost:4200/404 you will see

ERROR TypeError: Cannot read properties of null (reading 'status')
    at _NotFoundPageComponent (/Workspace/hittten/angularSSR17/src/app/pages/not-found-page/not-found-page.component.ts:17:21)

Info

basically, I have created a project like this:

npx @angular/[email protected] new angularSSR17 --ssr --routing --scss --skip-tests
cd angularSSR17
npm i -D [email protected]
ng g c pages/homePage
ng g c pages/aboutPage
ng g c pages/notFoundPage

I also disable pre-render in angular.json:

{
    "scripts": [],
    "server": "src/main.server.ts",
    "prerender": false,
    "ssr": {
      "entry": "server.ts"
    }
}

and I have done the settings of the routes for lazy load. I have not installed @angular/fire because it is not necessary to recreate the SSR error.

ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 17.0.8
Node: 20.10.0
Package Manager: npm 10.2.5
OS: darwin arm64

Angular: 17.0.8
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, ssr

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.8
@angular-devkit/build-angular   17.0.8
@angular-devkit/core            17.0.8
@angular-devkit/schematics      17.0.8
@schematics/angular             17.0.8
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2

from angular.

hittten avatar hittten commented on May 12, 2024

Indeed, several things about SSR need to be documented, for example since the move from @nguniversal/express-engine to @angular/ssr the express tokens were lost:

https://github.com/angular/universal/blob/e798d256de5e4377b704e63d993dc56ea35df97d/modules/express-engine/tokens/injection-tokens.ts

I had to search the internet for a while to understand that I had to add the "src/express.tokens.ts" file now because it no longer comes in the @angular/ssr package and that's what I did

I have reported an issue with the specific error of injecting the response token:
RESPONSE = new InjectionToken<Response>('RESPONSE'); which also fails

See this: #53810

from angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.