fix(use-fetch): default queryString in useFetchCol - #5
Open
MaxAdams98 wants to merge 1 commit into
Open
MaxAdams98 wants to merge 1 commit into
MaxAdams98 wants to merge 1 commit into
Conversation
useFetchResource interpolates queryString straight into the url, so a call that omits it requests /api/<endpoint>undefined. useFetchDoc three lines above already guards this with `|| ''`; useFetchCol does not, so the two behave differently for the same omitted argument. Caught in an app where three admin screens fetched /api/option-listsundefined and rendered empty with no error. It is invisible to typecheck, since undefined is valid for an optional string. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
The bug
useFetchResourceinterpolatesqueryStringstraight into the url:useFetchColpasses it through undefined, so a call that omits it requests/api/<endpoint>undefined:useFetchDoc, three lines above, already guards it:So the two siblings behave differently for the same omitted argument, which reads like an oversight rather than a decision.
The fix
One line, making
useFetchColmatchuseFetchDoc.How it turned up
Three admin screens in a project on 0.3.13 rendered empty with no error after adopting the shared hooks. The router logs showed the requests going to
/api/option-listsundefined. Nothing catches it locally:undefinedis valid for an optionalstring, so typecheck passes, and the request returns a response rather than throwing.Calls that pass
location.searchare unaffected, which is why it looks isolated at first.馃 Generated with Claude Code