angular / angular

Deliver web apps with confidence 🚀

Home Page:https://angular.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request with HttpClient not displayed in browser inspector but works

Melliche opened this issue · comments

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

Yes

Description

Hello, the bug is very simple, I perform a simple get request using httpClient in one of my services, knowing that this request returns a promise

If I call the method of my service in the constructor or ngOnInit of my component, the request works, if I log in the subscribe I have the data. But no request appears in my browser's network inspector.

However if I call this method of my service in a method of my component triggered when a button is clicked, the request works fine, but the request appears in the browser inspector

There is no error

on MacOs and windows

service.ts

  get(): Observable<any> {
    return this.http.get<any>(`${this.uri}`, {});
  }

component.ts

    constructor(private readonly service: Service) {
     service.get().subscribe((data) => { // I don't see request in inspector
       console.log(data); // data is present
     });
    }


  clickGet(): void { // I see request in inspector when I click on button
    this.service.get().subscribe(data) => {
       console.log(data); // data is present
     });
  }

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Node: 20.12.2
Angular CLI: 17.1.0

Anything else?

No response

Are you devtools open when you execute the request in the constructor ?

Devtools only log requests when the devtools are open when the request is emitted.

Are you devtools open when you execute the request in the constructor ?

Devtools only log requests when the devtools are open when the request is emitted.

Yes everything is already open in the network tab, with doubt I even put all the requests, but nothing...

Are you able to reproduce it with a stackblitz example ?

Are you able to reproduce it with a stackblitz example ?

thanks for tag, it works on my stackblitz... I don't understand haha

Devtools also has a filter which can hide certain types of requests. I've spent a good amount of time wondering why things don't show up when I didn't realize I had a filter set.

For now I'm going to close this issue as it's not actionable for us.

the problem was with the ssr, so this is normal behavior. After deactivating the ssr I no longer had the problem

Of course !
This is due to request caching. GET requests made on the server are cached so the client doesn't have to make the same requests !