ref(tsc): refactor self-contained endpoints that need response headers to apiOptions#112347
Merged
ref(tsc): refactor self-contained endpoints that need response headers to apiOptions#112347
Conversation
TkDodo
commented
Apr 7, 2026
| enabled: pathParams !== skipToken, | ||
| staleTime, | ||
| select: data => data.json, | ||
| select: selectJson, |
Collaborator
Author
There was a problem hiding this comment.
note: inline functions run on every render and perform structualSharing on every render. giving a stable identity makes sure we can avoid that and hit the internal queryObserver cache instead.
| return existingData.filter(member => member.id !== variables.memberId); | ||
| return { | ||
| ...existingData, | ||
| json: existingData.json.filter(member => member.id !== variables.memberId), |
Collaborator
Author
There was a problem hiding this comment.
we get type inference here for existingData which is a huge win
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Error handling narrowed to only catch RequestError
- Added isError check from useQuery to catch all error types, with instanceof narrowing inside for type-safe access to RequestError properties.
Or push these changes by commenting:
@cursor push 4536c1d9d5
Preview (4536c1d9d5)
diff --git a/static/app/views/alerts/rules/issue/details/issuesList.tsx b/static/app/views/alerts/rules/issue/details/issuesList.tsx
--- a/static/app/views/alerts/rules/issue/details/issuesList.tsx
+++ b/static/app/views/alerts/rules/issue/details/issuesList.tsx
@@ -46,7 +46,7 @@
cursor,
}: Props) {
const organization = useOrganization();
- const {data, isPending, error} = useQuery({
+ const {data, isPending, isError, error} = useQuery({
...apiOptions.as<GroupHistory[]>()(
'/projects/$organizationIdOrSlug/$projectIdOrSlug/rules/$ruleId/group-history/',
{
@@ -70,10 +70,14 @@
});
const groupHistory = data?.json;
- if (error instanceof RequestError) {
+ if (isError) {
return (
<LoadingError
- message={(error.responseJSON?.detail as string) ?? t('default message')}
+ message={
+ error instanceof RequestError
+ ? ((error.responseJSON?.detail as string) ?? t('default message'))
+ : t('default message')
+ }
/>
);
}This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e79ffcc. Configure here.
george-sentry
pushed a commit
that referenced
this pull request
Apr 9, 2026
…s to apiOptions (#112347) as discussed in last week’s TSC, we need to start moving endpoints over to `apiOptions` so that we can re-use caches. the quickest win would be to implement `useApiQuery` with `apiOptions` internally, and to get there, we need to migrate endpoints that now need `getResponseHeader` over to `apiOptions` because those headers are exposed differently. this PR takes the first couple of endpoints that are (mostly) self-contained (no other usages of the url found) and moves them over. I’ve also exposed `selectJsonWithHeaders` because the default impl only selects `json` without `headers`. I plan to tackle the other occurrences with an endpoint-by-endpoint approach, as we need to identify all places where an endpoint is used (e.g. `invalidateQueries` or `getApiQueryData` or `setApiQueryData`) and migrate them together.
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.


as discussed in last week’s TSC, we need to start moving endpoints over to
apiOptionsso that we can re-use caches.the quickest win would be to implement
useApiQuerywithapiOptionsinternally, and to get there, we need to migrate endpoints that now needgetResponseHeaderover toapiOptionsbecause those headers are exposed differently.this PR takes the first couple of endpoints that are (mostly) self-contained (no other usages of the url found) and moves them over.
I’ve also exposed
selectJsonWithHeadersbecause the default impl only selectsjsonwithoutheaders.I plan to tackle the other occurrences with an endpoint-by-endpoint approach, as we need to identify all places where an endpoint is used (e.g.
invalidateQueriesorgetApiQueryDataorsetApiQueryData) and migrate them together.