Skip to content

perf(logs): Fix memoization on log row content#110310

Merged
k-fish merged 1 commit intomasterfrom
perf/logs/memo-log-row-autorefresh
Mar 10, 2026
Merged

perf(logs): Fix memoization on log row content#110310
k-fish merged 1 commit intomasterfrom
perf/logs/memo-log-row-autorefresh

Conversation

@k-fish
Copy link
Member

@k-fish k-fish commented Mar 10, 2026

Meta was being recreated, and highlight terms was referencing MutableSearch which were both causing identity cycling.

Meta was being recreated, and highlight terms was referencing MutableSearch which were both causing identity cycling.
@k-fish k-fish requested a review from a team as a code owner March 10, 2026 16:26
@k-fish k-fish enabled auto-merge (squash) March 10, 2026 16:27
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 10, 2026
}
return terms;
}, [search, localOnlyItemFilters?.filterText]);
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't feel like boxing here, it's just more hooks to hide the fake deps.

) ?? {fields: {}, units: {}}
);
}, [data]);
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Member Author

Choose a reason for hiding this comment

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

Page count should be fine since new pages only are added upon a request firing, and are reset when changing the query.

Comment on lines 656 to 663
{fields: {}, units: {}}
) ?? {fields: {}, units: {}}
);
}, [data]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pageCount]);

const _fetchPreviousPage = useCallback(() => {
if (autoRefresh || hasPreviousPage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: The useMemo hook for _meta has an incomplete dependency array (pageCount), causing it to serve stale metadata when data.pages content changes without altering the page count.
Severity: HIGH

Suggested Fix

The dependency array for the _meta useMemo hook should be corrected to include the data it actually depends on. Instead of [pageCount], it should be [data?.pages] to ensure the memo re-calculates whenever the page data changes.

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/app/views/explore/logs/useLogsQuery.tsx#L656-L663

Potential issue: The `_meta` variable in `useLogsQuery.tsx` is calculated using a
`useMemo` hook that only has `pageCount` in its dependency array. However, the memo's
callback function accesses the full `data?.pages` object to aggregate metadata. This
creates a staleness bug. When existing page data is updated (e.g., during a refetch)
without changing the total number of pages, the memo will not re-execute. This results
in `_meta` holding stale values for field types and units, which can lead to incorrect
column alignment and data formatting in the logs table. The presence of an
`eslint-disable-next-line react-hooks/exhaustive-deps` comment indicates this was an
intentional but incorrect optimization.

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

@k-fish k-fish merged commit 5adbe2c into master Mar 10, 2026
61 checks passed
@k-fish k-fish deleted the perf/logs/memo-log-row-autorefresh branch March 10, 2026 16:34
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