Skip to content

preact-query: retryOnMount is still disabled when a function-form throwOnError returns false (#9338 was only applied to react-query) #11165

Description

@S-jooyoung

Describe the bug

react-query fixed this in #9338 (reported in #9336): ensurePreventErrorBoundaryRetry now evaluates a function-form throwOnError against the actual query error before deciding to set retryOnMount = false.

preact-query's copy of ensurePreventErrorBoundaryRetry is still the pre-#9338 version — it treats any function as truthy:

// packages/preact-query/src/errorBoundaryUtils.ts
if (
  options.suspense ||
  options.throwOnError ||               // <- a function that returns false still passes this check
  options.experimental_prefetchInRender
) {
  if (!errorResetBoundary.isReset()) {
    options.retryOnMount = false
  }
}

So with throwOnError: () => false (or a predicate like (error) => error.status >= 500 that returns false for the current error), an errored query is not retried on remount, even though the error was never thrown to an error boundary. Both useBaseQuery and useQueries call sites pass the 2-arg form, so the query's actual error state is never consulted.

Reproduction

Porting the three regression tests from #9338 into packages/preact-query/src/__tests__/useQuery.test.tsx on current main:

  • should retry on mount when throwOnError returns false — fails (expected 1 to be 2 fetches; the remount never refetches)
  • should handle throwOnError function based on actual error state — fails (same)
  • should not retry on mount when throwOnError function returns true — passes

Expected behavior

Same as react-query after #9338: a function-form throwOnError should only prevent retryOnMount when it actually returns true for the query's current error.

Additional context

Found while diffing react-querypreact-query for parity — same class of drift as #11155 (a react-query fix that didn't make it into the preact mirror). The port is mechanical (errorBoundaryUtils.ts + the two call sites + the #9338 tests); I have it ready and will open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions