angular / universal

Server-side rendering and Prerendering for Angular
MIT License
4.04k stars 484 forks source link

Angular 9: View caching bug when using @angular/localize #1491

Closed udos86 closed 1 year ago

udos86 commented 4 years ago

🐞 Bug report

What modules are related to this issue?

Is this a regression?

No ### Description When using new @angular/localize package and building multiple localizations via --localize flag the internal express view caching causes the app to crash when switching between different languages at runtime. Due to the changing of base href the server incorrectly responds with the initially cached bundle. This has already been reported to and discussed with @manfredsteyer ## πŸ”¬ Minimal Reproduction

To reproduce this issue please clone this minimal GitHub repository: https://github.com/udos86/ng9-localize-ssr and follow these steps:

  1. Build the application via npm run build:ssr
  2. Run the application via npm run serve:ssr
  3. Switch the language in the UI from English to German

The application crashes due to the cached English localization being send to the browser instead of the requested German one.

  1. Disable view caching in server.ts by removing comment in line 39: server.disable('view cache');
  2. Rebuild the application via npm run build:ssr
  3. Rerun the application via npm run serve:ssr
  4. Switch the language in the UI from English to German

Everything works fine now!

πŸ”₯ Exception or Error

Due to the wrong base href the Angular router throws because it's not able to resolve the client-side routes anymore:



main-es2015.39ddb7147ea9299e4380.js:8 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'de'
Error: Cannot match any routes. URL Segment: 'de'

🌍 Your Environment




Angular CLI: 9.0.0-rc.14
Node: 13.6.0
OS: darwin x64

Angular: 9.0.0-rc.14
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, platform-server, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-rc.14
@angular-devkit/build-angular     0.900.0-rc.14
@angular-devkit/build-optimizer   0.900.0-rc.14
@angular-devkit/build-webpack     0.900.0-rc.14
@angular-devkit/core              9.0.0-rc.14
@angular-devkit/schematics        9.0.0-rc.14
@ngtools/webpack                  9.0.0-rc.14
@nguniversal/builders             9.0.0-rc.1
@nguniversal/common               9.0.0-rc.0
@nguniversal/express-engine       9.0.0-rc.0
@schematics/angular               9.0.0-rc.14
@schematics/update                0.900.0-rc.14
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2
alan-agius4 commented 1 year ago

Let keep tracking i18n support in https://github.com/angular/angular-cli/issues/25726

angular-automatic-lock-bot[bot] commented 1 year ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.