Skip to content

ref(seer): Refactor Code Review table to better optimistically update#112979

Merged
ryan953 merged 1 commit intomasterfrom
ryan953/seer-code-review-cache
Apr 15, 2026
Merged

ref(seer): Refactor Code Review table to better optimistically update#112979
ryan953 merged 1 commit intomasterfrom
ryan953/seer-code-review-cache

Conversation

@ryan953
Copy link
Copy Markdown
Member

@ryan953 ryan953 commented Apr 14, 2026

Actually update the query cache, and remove that weird workaround stuff

@ryan953 ryan953 requested a review from a team as a code owner April 14, 2026 21:14
@ryan953 ryan953 requested review from billyvg and scttcper April 14, 2026 21:14
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 14, 2026
@sentry
Copy link
Copy Markdown
Contributor

sentry bot commented Apr 14, 2026

Sentry Snapshot Testing

Name Added Removed Modified Renamed Unchanged Status
sentry-frontend
sentry-frontend
0 0 0 0 204 ✅ Unchanged

Comment on lines +42 to 52
repository,
style,
}: Props) {
const queryClient = useQueryClient();
const organization = useOrganization();
const canWrite = useCanWriteSettings();
const {isSelected, toggleSelected} = useListItemCheckboxContext();

// We're defaulting to read from the list data, which is passed in as `initialRepository`
// But if an update has been made to one record, we're going to enable reading
// from `useRepositoryWithSettings` which will have the latest data, letting us
// do optimistic updates, without re-rendering the entire table.
// `initialRepository` will become stale at that point, but we'll have fresh data
// in the cache to override it.
const {data, isError, isPending} = useRepositoryWithSettings({
repositoryId: initialRepository.id,
initialData: [initialRepository, undefined, undefined],
enabled: mutationData[initialRepository.id] !== undefined,
});
const repository = isError || isPending ? initialRepository : data;

return (
<Grid
columns={gridColumns}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: When a repository setting toggle fails, the UI doesn't revert. The onError handler updates an unused query cache instead of the infinite query cache driving the UI.
Severity: MEDIUM

Suggested Fix

The onError handler should be updated to roll back the state of the correct query cache. Instead of updating the individual repository cache, it should find the specific repository within the infinite query's cached data and revert its state there. This will ensure the UI, which reads from the infinite query, reflects the rollback immediately upon failure.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
static/gsApp/views/seerAutomation/components/repoTable/seerRepoTableRow.tsx#L32-L52

Potential issue: When a user toggles a repository setting and the backend mutation
fails, the `Switch` component does not visually revert to its previous state. The
`onError` handler attempts a rollback by calling `queryClient.setQueryData` on an
individual repository's query cache. However, the UI's state is derived from a parent
component's infinite query cache. Since the error handler only updates the individual
cache, the UI remains in the incorrect, optimistically toggled state until the infinite
query is invalidated and refetched. This presents a temporarily misleading state to the
user.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing this will conflict with #112926

I'll revisit once 112926 is in

@ryan953 ryan953 merged commit 94daa28 into master Apr 15, 2026
66 checks passed
@ryan953 ryan953 deleted the ryan953/seer-code-review-cache branch April 15, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants