-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
feat(tanstack-query): allow to pass in a custom callback for computing optimistic data #1143
Conversation
…g optimistic data
WalkthroughWalkthroughThe recent update introduces the concept of optimistic data handling in the Tanstack Query library, specifically focusing on the ability to compute and manage optimistic updates more effectively. This is achieved through the introduction of a new type and function dedicated to optimistic data provision, along with enhancements in existing functions to support this feature. Additionally, the update includes a test case to validate the functionality of optimistic mutations using a custom provider, ensuring the library handles cache updates correctly after mocking API calls. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- packages/plugins/tanstack-query/src/runtime/common.ts (6 hunks)
- packages/plugins/tanstack-query/tests/react-hooks-v5.test.tsx (1 hunks)
Additional comments: 5
packages/plugins/tanstack-query/src/runtime/common.ts (4)
- 46-63: The
OptimisticDataProviderResult
type is well-defined, covering all possible outcomes for optimistic updates. However, consider documenting the expected behavior whendata
is provided butkind
is not 'Update', as this might lead to confusion.- 75-81: The
OptimisticDataProvider
type is correctly defined to accept necessary arguments for computing optimistic data. Ensure that the documentation clearly explains how to use this callback, especially the significance of each argument, to aid developers in implementing their custom logic effectively.- 100-100: Adding the
optimisticDataProvider
callback toExtraMutationOptions
is a significant enhancement. It's important to document examples of how to use this new option, including scenarios where it's beneficial. This will help users understand its value and how to integrate it into their applications.- 392-434: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [322-427]
The updates to
setupOptimisticUpdate
andoptimisticUpdate
functions to handle theoptimisticDataProvider
callback are correctly implemented. However, ensure thorough testing, especially edge cases where the callback might return unexpected results. Consider adding more inline documentation explaining the flow, especially around the handling of differentkind
values fromOptimisticDataProviderResult
.packages/plugins/tanstack-query/tests/react-hooks-v5.test.tsx (1)
- 622-715: The new test case for optimistic updates with a custom provider is well-implemented and covers the scenario of using a custom provider for optimistic updates. However, consider adding more assertions to verify the state of the cache before and after the mutation in both test scenarios. This will ensure the test is robust and accurately reflects the expected behavior of the library when handling optimistic updates with custom logic.
Fixes #1142
Summary by CodeRabbit