Skip to content

cancel-query prevents a cancelled initial request from retrying #4

Closed

Description

@jramosg

cancel-query prevents a cancelled initial request from retrying

Summary

::rfq/cancel-query clears the fetching flags for an in-flight query, but it
does not mark the cache entry stale. If the cancelled request was the initial
request, the entry remains in :loading state with :fetching? false and
:stale? false. A later ::rfq/ensure-query treats that entry as fresh and
does not issue another request.

Reproduction

(rfq/set-default-effect-fn!
  (fn [request on-success on-failure]
    {:http-xhrio
     (assoc request
            :on-success on-success
            :on-failure on-failure)}))

(rfq/reg-query :users/list
  {:query-fn (fn [_] {:method :get :url "/users"})})

(rf/dispatch [::rfq/ensure-query :users/list {}])
(rf/dispatch [::rfq/cancel-query :users/list {}])
(rf/dispatch [::rfq/ensure-query :users/list {}])

Actual behavior

After cancellation, the query can look like this:

{:status    :loading
 :fetching? false
 :stale?    false}

The second ensure-query does not start a new request.

Expected behavior

Logical cancellation should invalidate the current attempt. The cache entry
should remain stale when an attempt was in flight:

{:status    :loading
 :fetching? false
 :stale?    true}

A later ensure-query should start a new attempt, while the cancelled
response must still be ignored if it arrives later.

Proposed fix

In re-frame.query.db/cancel-query, detect whether any request flag is active
(:fetching?, :fetching-next?, or :fetching-prev?) and associate
:stale? true when cancelling an in-flight attempt. Preserve the existing
status and data behavior, and keep cancellation a no-op for uncached queries.

Activity

  1. added 3 commits that reference this issue on Aug 14, 2026
    e464fbb
    cf956ff
    fd0af47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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