Angular: injectMutation skips pending state when triggered in constructor or ngOnInit
Open
@arnoud-dv is already working on this.
Since Oct 21, 2025.
- Dominant language
- TypeScript
- Stars
- 50.3k
- Forks
- 4.2k
- Avg merge
- 18h 25m
- Merged PRs (30d)
- 200
Description
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
- Refresh the page.
- Observe the state changes for the three mutations triggered in an Angular
constructor,ngOnInit, orngAfterContentInit. - Notice that the two mutations triggered in the
constructorandngOnInitremain 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.