fix(mutation): support conditional fetching by allowing falsy keys#4226
Open
DiogenesFerminS wants to merge 2 commits intovercel:mainfrom
Open
fix(mutation): support conditional fetching by allowing falsy keys#4226DiogenesFerminS wants to merge 2 commits intovercel:mainfrom
DiogenesFerminS wants to merge 2 commits intovercel:mainfrom
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
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
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.
Description
This PR aligns the behavior of
useSWRMutationwithuseSWRregarding conditional fetching.Previously, providing a
nullkey (or a function returning a falsy value) touseSWRMutationcaused an internalconsole.errorduring serialization and threw a "missing key" error when callingtrigger(). This behavior contradicted the SWR documentation on conditional fetching, which states that falsy keys should simply prevent the request.Changes
triggerfunction to return early if the resolved key is falsy. This ensures consistency across the library and prevents unhandled console errors.should error when triggering an empty keyto reflect the correct documented behavior (it now expects a silent return instead of an error throw).serializeutility from being called with invalid keys, eliminating the reported console noise.Linked Issue
Fixes #4217
Testing
nullkeys.pnpm test mutation. All tests passed.Cc: @SL-YutoTakagi