-
Notifications
You must be signed in to change notification settings - Fork 77
Issue 41 #375
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
Open
Danny-Devs
wants to merge
5
commits into
Kong:master
Choose a base branch
from
Danny-Devs:issue-41
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Issue 41 #375
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Introduced a `compare` option in the configuration to allow custom data comparison logic. - Updated README to document the new feature and provide usage examples. - Added `dequal` library as a dependency for deep equality checks. - Modified relevant types and functions to support the new comparison feature.
- Implemented tests to verify default and custom comparison logic in the `useSWRV` hook. - Added scenarios for deep equality checks, updates on data changes, and edge cases handling. - Ensured that the comparison function behaves correctly under various conditions.
- Added "packageManager" field to package.json to specify the version of yarn being used. - Updated useSWRV hook to include the custom comparison function in mutate calls for improved data handling.
👷 Deploy request for docs-swrv pending review.Visit the deploys page to approve it
|
- Added a comprehensive test suite for the custom data comparison feature in the `useSWRV` hook. - Included tests for default dequal behavior, custom compare function scenarios, and edge cases handling. - Ensured robust verification of component re-renders based on data changes, including special values and circular references.
- Eliminated the test case that checked for error handling when the compare function throws an error, as the current implementation of swrv does not support this feature. - Updated comments to reflect the removal and clarify the focus of the remaining tests on valid comparison scenarios.
Author
|
Just @'ing folks in case that helps with visibility (lmk if this is bad practice and I won't do it again!) @adamdehaven @darrenjennings |
Member
|
Our team can take a look in the coming weeks - thanks for the submission |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello swrv team! I was examining issue #41 and thought that I'd be able to submit a solution for it--here it is.
Do note that I have utilized Claude 3.7 Sonnet through much of this process. I reviewed the code already, so I thought I'd create a PR for it so others can review it.
I've implemented comprehensive unit tests for this feature. I plan to test with the example applications in the repo as a follow-up to verify real-world behavior.
Looking forward to your feedback,
Add
compareoption for smarter data change detectionOverview
This PR implements a custom data comparison mechanism, allowing developers to precisely control when components re-render based on data changes. It also upgrades the default comparison to use
dequal/lite, providing more intuitive deep equality checks.Problem Solved
Without a custom
compareoption, swrv must re-render components whenever a new object reference is returned from a fetcher, even if the actual data content is identical. This leads to unnecessary re-renders when:Implementation
The implementation is straightforward and minimally invasive:
dequal/liteas a dependency for efficient deep equality comparisonIConfiginterface with acomparefunction optionmutateto use this function for data change detectionBenefits
This improvement enables several key use cases:
Example Usage
Testing
Added comprehensive tests verifying:
dequalbehavior prevents unnecessary updates for identical dataCompatibility
Maintains 100% backward compatibility with existing code. The default behavior is improved but semantically equivalent for most use cases.
Resolves #41