Angular: whenStable() resolves while a mutation started with mutate() is still running
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 30/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- angular, typescript
Piste de recherche
Commencez par l’enregistrement de la tâche en attente dans packages/angular-query-experimental/src/inject-mutation.ts#L135-L146 et exécutez le cas de régression dans packages/angular-query-experimental/src/tests/pending-tasks.test.ts. Vérifiez qu’après mutation.mutate(), ApplicationRef.whenStable() attend que la mutation soit terminée et que les assertions sur le statut et les données réussissent sans délai d’attente arbitraire.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
ApplicationRef.whenStable() resolves while a mutation started with mutate() is still running, so tests and SSR see the mutation as untouched.
injectMutation registers the Angular pending task from inside the observer subscription callback:
That callback is wrapped in notifyManager.batchCalls, so it runs in a later task than the mutate() call that started the mutation. In the window between the two there is no pending task, the application counts as stable, and whenStable() resolves right away. At that point the result signals have not been updated either, so status() still reads idle.
mutate() is fire and forget, so there is nothing else holding the application busy. mutateAsync() is not affected in the same way because the caller gets a promise back and can await it.
Your minimal, reproducible example
Failing test against main, added to packages/angular-query-experimental/src/__tests__/pending-tasks.test.ts:
it('should let whenStable wait for a mutation that was just triggered', async () => {
vi.useRealTimers()
const app = TestBed.inject(ApplicationRef)
const mutation = TestBed.runInInjectionContext(() =>
injectMutation(() => ({
mutationFn: (value: string) => sleep(5).then(() => value),
})),
)
TestBed.tick()
mutation.mutate('mutated')
await app.whenStable()
expect(mutation.status()).toBe('success')
expect(mutation.data()).toBe('mutated')
})
On current main this fails with expected 'idle' to be 'success'.
Steps to reproduce
- Set up a zoneless
TestBedwithprovideTanStackQuery. - Create a mutation with
injectMutationwhosemutationFntakes any real time. - Call
mutation.mutate(...). await ApplicationRef.whenStable().- Read
mutation.status().
Expected behavior
whenStable() should not resolve until the mutation has settled, the same way it already waits for queries once they have been reported. Right now the only way to make it wait is to insert an arbitrary setTimeout before calling it.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Reproduced with the repository test suite on Windows 11, Node 24.
Tanstack Query adapter
angular-query
TanStack Query version
5.101.4 (current main)
TypeScript version
5.9.3
Additional context
The same batching gap exists on the query side and is reported in #9981, #9910 and #10046. This issue is only about the mutation path, which those reports do not cover. I have a fix and a regression test ready and will open a PR.
- Langage dominant
- TypeScript
- Étoiles
- 50.4k
- Forks
- 4.3k
- Merge moyen
- 11 h 37 min
- PR mergées (30 j)
- 521
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de TanStack/query
-
QueryClient.isFetching and useIsFetching accept a fetchStatus filter and ignore itPeut-être pris @Apu-Emdad l’a pris il y a 6 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Peut-être à nouveau libre @LeonxLJX l’a pris il y a 46 jours, et aucune pull request n’est ouverte. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
TanStack/query#11358 · 2 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
solid-query 6.0.0-rc.5: onCacheEvent throws NotReadyError during a Solid 2 (rc.14+) transition landingPeut-être pris @UzumakiODZ l’a pris il y a 5 jours. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 28/100
TanStack/query#12031 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Explicit gcTime schedules a GC timer during SSR, retaining the whole render in memoryPeut-être pris @AdzerKI l’a pris il y a 6 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 25/100
TanStack/query#12025 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
restoreQueries and persisterGc throw on malformed persisted entriesPeut-être pris @VGontier-cmd l’a pris il y a 14 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de TanStack/query
Issues similaires
-
area: repo priority: P2 type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
appandflow/stim#4107 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulté 1/5 1-3 heures Accessibilité débutants 60/100
lingdojo/kana-dojo#32859 · 1 commentaire · 5 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
code-quality refactoring
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
github/gh-aw-firewall#10364 ·
Les mainteneurs répondent en général sous 1 jour
-
Merge the duplicate kaffir_corn record into sorghumPeut-être pris @Crypto-Shroom l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
Crypto-Shroom/Bird-Feed-Calculator#322 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
drizzle-team/drizzle-orm#6552 ·
Les mainteneurs répondent en général sous 2 jours