Skip to content
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

Angular: caught errors in the queryFn do not run in the zone #8839

Closed
JoepKockelkorn opened this issue Mar 20, 2025 · 1 comment · Fixed by #8842
Closed

Angular: caught errors in the queryFn do not run in the zone #8839

JoepKockelkorn opened this issue Mar 20, 2025 · 1 comment · Fixed by #8842
Labels

Comments

@JoepKockelkorn
Copy link
Contributor

JoepKockelkorn commented Mar 20, 2025

Describe the bug

I'm experiencing weird behaviour when using the throwOnError: true setting as the default in the QueryClient options. When an error occurs that is not handled via the template because of throwOnError: true, then the error should be caught by the Angular ErrorHandler. This somehow does not happen on first pageload.

As discussed in this discord question, a working fix could be to catch synchronous errors that happen inside of the runOutsideAngular callback in create-base-query.ts and trigger the NgZone.onError.emit function manually as proposed here.

Your minimal, reproducible example

https://github.com/JoepKockelkorn/tanstack-angular-throw-on-error-bug

Steps to reproduce

See the README of the repro github repo.

Expected behavior

The ErrorHandler.handleError is called on initial pageload.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

MacOS 15.3 (24D60)
Browser: Brave Version 1.76.74 Chromium: 134.0.6998.89 (Official Build) (arm64)

Tanstack Query adapter

angular-query

TanStack Query version

5.69.0

TypeScript version

5.7.2

Additional context

No response

@JoepKockelkorn
Copy link
Contributor Author

JoepKockelkorn commented Mar 21, 2025

I made a fix, but this is my first PR to the repo so please review thoroughly 😄.

Update: found out that mutation has a separate implementation, but added it there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants