Skip to content

Update react-query depency to require at least v5.83 #10838

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

Merged
merged 8 commits into from
Jul 21, 2025

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Jul 16, 2025

Problem

We received some requests and questions for enabling list components data fetching conditionally.
It's actually easier to do with react-query versions more recent than the one we install by default.

Solution

  • Upgrade react-query
  • Document how to enabling data fetching conditionally
  • Add a story to show this use case

How To Test

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date

Also, please make sure to read the contributing guidelines.

@djhi djhi added the WIP Work In Progress label Jul 16, 2025
@@ -1174,6 +1174,26 @@ const ProductList = () => (
)
```

## Enabling Data Fetching Conditionally
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about where to put this documentation as it's actually useGetList that we configure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine here 👍

Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also prepare the changelog to mention that there is a risk of duplicate react-query, and how to fix that?

@@ -57,8 +57,7 @@
"react-router-dom": "^6.28.1 || ^7.1.1"
},
"dependencies": {
"@tanstack/react-query": "^5.21.7",
"clsx": "^2.1.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good catch

@@ -248,7 +248,6 @@ export type UseInfiniteGetListOptions<
GetInfiniteListResult<RecordType>,
ErrorType,
InfiniteData<GetInfiniteListResult<RecordType>>,
GetInfiniteListResult<RecordType>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that mean that the type of UseInfiniteQueryOptions has changed in react-query? That would be a breaking change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I believe we used it incorrectly before but it wasn't detected until this update

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's due to TanStack/query#8956. It doesn't seem to be a breaking change.

@@ -176,7 +176,7 @@ export const useGetList = <
}
: result,
[result]
) as UseQueryResult<RecordType[], Error> & {
) as unknown as UseQueryResult<RecordType[], Error> & {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why do we only need to do that when calling dataProvider.getList() and not for every other usage of useQuery (e.g. useGetOne) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because useGetOne returns the same format as react query and we made the decision to do things differently in all hooks that also return a total. Instead of data.total we wanted to have total directly on the result.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, I'd love to change that in v6

@djhi djhi added RFR Ready For Review and removed WIP Work In Progress labels Jul 16, 2025
@slax57 slax57 self-requested a review July 18, 2025 09:13
Comment on lines 261 to 273
const ConditionalDataFetchingView = () => {
const context = useListContext();

if (context.filterValues.q == null || context.filterValues.q === '') {
return (
<CardContentInner>
Type a search term to fetch data
</CardContentInner>
);
}

return <BookList />;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This story is working, but since you are rendering a different child when the filter condition is not true, we can't really tell if the dataProvider is called or not. It would help to enable the fakerest debug logs.

docs/List.md Outdated
Comment on lines 1195 to 1196
context.filterValues.q == null ||
context.filterValues.q === '' ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too bad you copied the wrong condition: in the docs the condition was q.length > 2 and not q !== '' 😅

@fzaninotto fzaninotto changed the title Upgrade react query Update react-query depency to require at least v5.83 Jul 21, 2025
@fzaninotto fzaninotto merged commit 23ccbfe into next Jul 21, 2025
15 checks passed
@fzaninotto fzaninotto deleted the upgrade-react-query branch July 21, 2025 10:12
@fzaninotto fzaninotto added this to the 5.10.0 milestone Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Development

Successfully merging this pull request may close these issues.

3 participants