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

isSuccess flashes false on subsequent queries #3353

Open
kellengreen opened this issue Apr 13, 2023 · 5 comments
Open

isSuccess flashes false on subsequent queries #3353

kellengreen opened this issue Apr 13, 2023 · 5 comments
Labels
bug Something isn't working rtk-query

Comments

@kellengreen
Copy link

Given a basic component like the one below, response.isSuccess flashes false on subsequent queries.

Basic Example

import { useState } from "react";
import api from "./api";

export default function App() {
  const [params, setParams] = useState({ req: 0 });
  const response = api.useSearchQuery(params);

  console.log(
    `request: ${params.req}\tisFetching: ${response.isFetching}\tisSuccess: ${response.isSuccess}`
  );

  return (
    <div>
      <button
        disabled={response.isFetching}
        onClick={() => setParams({ req: params.req + 1 })}
      >
        Refresh
      </button>
      <pre>{JSON.stringify(response, undefined, 3)}</pre>
    </div>
  );
}

Current Behavior in Console Log

request: 0	isFetching: true	isSuccess: false
request: 0	isFetching: true	isSuccess: false
request: 0	isFetching: false	isSuccess: true
request: 1	isFetching: true	isSuccess: false <--
request: 1	isFetching: true	isSuccess: true
request: 1	isFetching: false	isSuccess: true

Expected Behavior in Console Log

Given this quote from the documentation:

isSuccess - When true, indicates that the query has data from a successful request.

I would expect isSuccess to remain true while data is not undefined.

request: 0	isFetching: true	isSuccess: false
request: 0	isFetching: true	isSuccess: false
request: 0	isFetching: false	isSuccess: true
request: 1	isFetching: true	isSuccess: true <--
request: 1	isFetching: true	isSuccess: true
request: 1	isFetching: false	isSuccess: true

Repo to Reproduce:
https://github.com/kellengreen/rtk

@kellengreen
Copy link
Author

Anyone?

@markerikson
Copy link
Collaborator

Sorry, tbh we're all pretty busy with things lately and haven't had any time to try looking into assorted bugs.

@kellengreen
Copy link
Author

No worries, I understand.

@kellengreen
Copy link
Author

Confirmed still an issue in @reduxjs/toolkit = 2 and react-redux = 9.

@markerikson markerikson added bug Something isn't working rtk-query labels Feb 6, 2024 — with Volta.net
@CO0Ki3
Copy link

CO0Ki3 commented Mar 28, 2024

@markerikson
We should look at the definition of isSuccess in the values in 'initialized' state.

const isSuccess = currentState.isSuccess || isFetching && hasData;

If the state is 'initialized', isFetching(isLoading) is false, so isSuccess is false even if hasData is true (when it has previous data).

Can I ask why isFetching & hasData condition is necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rtk-query
Projects
None yet
Development

No branches or pull requests

3 participants