Skip to content

Angular: injectMutation skips pending state when triggered in constructor or ngOnInit #9020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ThiloAschebrock opened this issue Apr 15, 2025 · 0 comments

Comments

@ThiloAschebrock
Copy link

Describe the bug

useMutation does indicate a pending state and remains idle until the mutation concludes if triggered in a Component constructor or ngOnInit lifecycle method, whereas triggering the mutation from ngAfterContentInit works as expected.

Your minimal, reproducible example

https://stackblitz.com/edit/angular-query-aqv6yuzm?file=src%2Fmain.ts

Steps to reproduce

  1. Refresh the page.
  2. Observe the state changes for the three mutations triggered in an Angular constructor, ngOnInit, or ngAfterContentInit.
  3. Notice that the two mutations triggered in the constructor and ngOnInit remain idle and do not indicate the pending state while the mutations are running.

Expected behavior

As a user, I expect the mutation to always indicate the correct idle and pending state, i.e., switch from idle to pending when a mutation has been triggered.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows, maxOS,
  • Browser: Chrome, Edge

Tanstack Query adapter

angular-query

TanStack Query version

v5.74.3

TypeScript version

v5.6.3

Additional context

No response

@ThiloAschebrock ThiloAschebrock changed the title useMutation skips pending state when triggered in constructor or ngOnInit Angular: injectMutation skips pending state when triggered in constructor or ngOnInit Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant