angular / angular

Deliver web apps with confidence 🚀
https://angular.dev
MIT License
94.88k stars 24.76k forks source link

Request with HttpClient not displayed in browser inspector but works #55843

Closed Melliche closed 2 weeks ago

Melliche commented 2 weeks ago

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

JeanMeche commented 2 weeks ago

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.

Melliche commented 2 weeks ago

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...

JeanMeche commented 2 weeks ago

Are you able to reproduce it with a stackblitz example ?

Melliche commented 2 weeks ago

Are you able to reproduce it with a stackblitz example ?

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

alxhub commented 2 weeks ago

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.

Melliche commented 2 weeks ago

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

JeanMeche commented 2 weeks ago

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 !