* fix(query-core): replaceEqualDeep max depth
* restore expected error in unit test
* ci: apply automated fixes
* Update max depth for replaceEqualDeep function
Fixes the max depth for replaceEqualDeep in query-core.
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* test(react-query): add tests should retry on mount when throwOnError returns false
* fix(react-query): refine throwOnError retry logic for error boundary cases
When throwOnError is a function, allow retryOnMount to proceed even when error boundary hasn't reset,
while maintaining the prevention behavior for boolean throwOnError values.
* fix(react-query): enhance throwOnError logic in error boundaries
Refine behavior to handle function-type throwOnError, allowing retries when appropriate. Ensure boolean throwOnError values still prevent retries when the error boundary isn't reset.
* test: Add tests for `throwOnError` behavior in `useQuery`
This commit introduces tests to verify the behavior of the `throwOnError` callback in scenarios where `retryOnMount` is enabled. It ensures proper handling of retries based on the error state and the `throwOnError` function's return value. These tests improve the reliability and coverage of error handling logic in `useQuery`.
* fix(react-query): improve throwOnError logic with query state validation
- Pass query object to ensurePreventErrorBoundaryRetry for accurate state checking
- Preserve query deduplication behavior while fixing throwOnError function handling
- Fixes issue where throwOnError function couldn't access query error state
* fix(react-query): fix test flakiness and query cache timing (#9338)
- Replace vi.waitFor with vi.advanceTimersByTimeAsync in tests
- Use separate render results to avoid stale DOM references
- Inline fresh query lookup in ensurePreventErrorBoundaryRetry after _experimental_beforeQuery
* ci: apply automated fixes
* fix(react-query): refine retryOnMount logic and error boundary handling
- move query retrieval after `_experimental_beforeQuery` in `useBaseQuery`
- refactor `ensurePreventErrorBoundaryRetry` for better clarity
- make `query` parameter required in `ensurePreventErrorBoundaryRetry`
* ci: apply automated fixes
* feat(react-query): make query param required but nullable in ensurePreventErrorBoundaryRetry
* Apply suggestions from code review
* chore: size-limit
* chore: changeset
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
In 1b54538, `setOptions` was changed to call `notifyListeners` which
eventually leads to `QueriesObserver.setQueries`
1. Updating `#observerMatches`
2. Calling `setOptions` which leads to `#notify` being called
3. Updating `#result`
This is an issue when `#notify` is called before the `#result` is
updated, as `#trackResult` assumes these two are the same length, which
may not be the case if the number of queries changed. When the length
increases, `observerResult` becomes `undefined` and the function throws
an exception.
Fix by moving the `#observerMatches` assignment later in the function,
next to the `#observers` and `#result` assignment.
Co-authored-by: nrahnema <nrahnema@hudson-trading.com>
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* fix(query-core): ensure query refetches on mount/retry when status is error (#9728)
* fix: mark queries as invalidated on background errors instead of checking error status
- Remove error status check in shouldFetchOn
- Set isInvalidated: true in reducer when background error occurs (only if data exists)
- Add tests for staleTime: 'static' and non-static queries with background errors
This approach centralizes stale logic in isStale/isStaleByTime and prevents
regression where staleTime: 'static' queries would incorrectly refetch on
window focus after a background error.
* refactor: simplify isInvalidated logic in error case
Set isInvalidated: true unconditionally since queries with no data
are always considered stale per isStaleByTime logic.
* Apply suggestion from @TkDodo
* Apply suggestions from code review
* fix: eslint
* fix: disable retry in background error tests to prevent timeout
The tests were timing out because when refetch() throws an error, the
default retry mechanism (3 retries with exponential backoff) was being
triggered. With fake timers, the retry delays weren't being advanced,
causing the tests to hang.
Adding retry: false to both tests disables retries and allows them to
complete immediately after the error, which is appropriate for these
tests that specifically check background error behavior.
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* fix(query-core): prevent reducer from being called twice in streamedQuery #9787
- Fix bug where reducer was called twice for each chunk (once in setQueryData, once in loop)
- Store reducer result in variable to avoid duplicate calls
- Add test case to verify reducer is only called once per chunk
* fix(streamed-query): prevent reducer from being called twice
Fixed an issue where the reducer was being invoked twice when refetchMode is set to 'replace'.
Added a regression test to verify the fix.
Fixes#9787
* docs: add changeset and lockfile update
* fix(changeset): change version bump to patch
* Update streamedQuery.test.tsx
fix: lint
* fix: support refetchMode append and prevent double reducer calls
- Fix refetchMode append to preserve existing data on refetch
- Fix reducer being called twice by calling it once and storing result
- Update pnpm-lock.yaml to match main branch
* chore: update pnpm-lock.yaml to include size-limit dependencies
* ci: apply automated fixes
* refactor: simplify streamedQuery logic with clearer isReplaceRefetch condition
- Extract isReplaceRefetch variable for better readability
- Use explicit if-else instead of negated conditions
- Make it clearer when reducer is called in each branch
---------
Co-authored-by: TkDodo <office@dorfmeister.cc>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* chore: move consume aware signal logic to utils
* fix: add consume aware signal to streamedQuery
* test: add a test for not a signal that is not consumed by streamFn
* chore: add changeset
* fix: made queryFn of streamedQuery not consume signal directly (so that only streamFn can consume it)
* fix: made onCancelled get called only once
* fix: memoized getSignal and made sure it is called only once
* fix: no-unnecessary-condition
* chore: size-limit
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* feat: size-limit
* fix: script
* fix: add test:size to nx
* fix: skip install and build
* really
* fix: size-limit options
* ok we need build step
* fix: test-size runs as part of its own action
docs: update bundlephobia links to @tanstack/react-query
The bundlephobia links were pointing to the old react-query package (v3)
instead of the current @tanstack/react-query package.
Co-authored-by: Claude <noreply@anthropic.com>
* test(svelte-query-persist-client/PersistQueryClientProvider): switch to fake timers, replace 'waitFor' with 'advanceTimersByTimeAsync', and use 'sleep().then()' pattern
* test(svelte-query-persist-client/PersistQueryClientProvider): replace 'setQueryDefaults' with 'onFetch' callback in FreshData
* refactor(svelte-query-persist-client/FreshData): convert complex 'then' callback to async/await pattern
* test(angular-query-persist-client/withPersistQueryClient): switch to fake timers, replace 'waitFor' with 'advanceTimersByTimeAsync', use 'sleep().then()' pattern, replace 'screen' with 'rendered', add 'toBeInTheDocument', and add '@testing-library/jest-dom/vitest'
* test(angular-query-persist-client/withPersistQueryClient): replace 'async/await' with 'sleep().then()' pattern in queryFn and restoreClient
* refactor(angular-query-persist-client/withPersistQueryClient.test): convert complex 'then' callbacks to async/await pattern
* test(solid-query-persist-client/PersistQueryClientProvider): switch to fake timers, replace 'waitFor' with 'advanceTimersByTimeAsync', and use 'sleep().then()' pattern
* refactor(solid-query-persist-client/PersistQueryClientProvider.test): convert complex 'then' callback to async/await pattern
* fix: update react and nextJs
and add a nextJs16 integration test
* ci: apply automated fixes
* oops
* Update patch versions for React and TanStack packages
Updated the patch versions for various React and TanStack packages.
* fix: streamline dependencies
* bundle size
* fix lock file
* fix: update react in example
* skip test for now
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>