stevermeister/ngx-cookie-service

[Angular 18] `ngx-cookie-service-ssr` `get` returns empty string even if cookie is available

Closed this issue ยท 5 comments

Describe the bug

It seems that this service inherits the same issue reported here where Angular 18's ng serve is not using server.ts which means that adding the providers { provide: SSR_REQUEST, useValue: req } and { provide: 'RESPONSE', useValue: res } won't serve its purpose.

I tried building and serving the dist/<project>/server/server.mjs and it did get the existing cookie successfully.

Steps to Reproduce

  1. Use Angular 18
  2. install ngx-cookie-service-ssr and follow instructions in readme regarding adding of the providers in the express server
  3. ng serve and test .get method (make sure cookie exists)

Expected behaviour

  1. should work with ng serve
  2. should work seemlessly on the client and ssr runtime

What version of the library you see this issue?

"ngx-cookie-service-ssr": "^18.0.0"

What version of Angular are you using?

Angular 18

Screenshots

No response

Desktop? Please complete the following information

No response

Mobile? Please complete the following information

No response

Anything else?

No response

Hello ๐Ÿ‘‹ @apappas1129
Thank you for raising an issue. We will investigate into the issue and get back to you as soon as possible. Please make sure you have given us as much context as possible.
Feel free to raise a PR if you can fix the issue

Upgrading to v19 pre-release solved the issue. ATTOW, ng update @angular/cli @angular/core --next=true --force pulled in version 19.0.0-next.9 and ng serve now successfully "provides" the providers defined in the server.ts CommonEngine.render.

Thanks for the feedback. Unfortunately, I'm not sure there's a path forward for fixing ng serve use cases. As I understand it, ng serve is intended for testing your client-side application, which means the server-side architect isn't even used by default. Webpack stands up a minimal expressJS instance just so your browser has a local server to get the built files from.

While I'd say this is somewhat intended behavior, it's definitely a little misleading. I'm happy to hear NG19's default architect configuration fixes this though.

Upgrading to v19 pre-release solved the issue. ATTOW, ng update @angular/cli @angular/core --next=true --force pulled in version 19.0.0-next.9 and ng serve now successfully "provides" the providers defined in the server.ts CommonEngine.render.

Closing as per this

Upgrading to v19 pre-release solved the issue. ATTOW, ng update @angular/cli @angular/core --next=true --force pulled in version 19.0.0-next.9 and ng serve now successfully "provides" the providers defined in the server.ts CommonEngine.render.

Closing as per this

Still need to push an update to the documentation to write a disclaimer that Angular 18 is not fully supported.