Skip to content

Dispatching initiate() function resolves with a status of pendingΒ #4720

@npfitz

Description

@npfitz

I'm currently running into a situation where I call initiate() on an endpoint that currently has a request in flight (due to tag invalidation), but the value I'm returned is the previously cached entry, alone with some metadata such as isLoading: true and status: pending. For example:

await dispatch(cardApi.endpoints.getCard.initiate({id}, {forceRefetch:true})

returns an object like

{
    "status": "pending",
    "endpointName": "getCard",
    "requestId": "JOhITYA33zsbG75F0IuRo",
    "originalArgs": {
        "id": 18
    },
    "startedTimeStamp": 1732104749367,
    "data": {
        /* Cached data entry */
    },
    "fulfilledTimeStamp": 1732104744906,
    "isUninitialized": false,
    "isLoading": true,
    "isSuccess": false,
    "isError": false
}

For some reason, even though there is an in flight request we are resolving the promise immediately with cached data. However, if I delete the cache entry before my call to initiate, awaiting initiate will work as expected. So my current work around is to dispatch cardApi.internalActions.removeQueryResult before calling initiate.

Is this expected behavior? Is there any way to access the promise of the in flight response above? Thanks in advance.

Edit:
This is using @reduxjs/[email protected]

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