perf(logs): Fix memoization on log row content#110310
Conversation
Meta was being recreated, and highlight terms was referencing MutableSearch which were both causing identity cycling.
| } | ||
| return terms; | ||
| }, [search, localOnlyItemFilters?.filterText]); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Page count should be fine since new pages only are added upon a request firing, and are reset when changing the query.
| {fields: {}, units: {}} | ||
| ) ?? {fields: {}, units: {}} | ||
| ); | ||
| }, [data]); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [pageCount]); | ||
|
|
||
| const _fetchPreviousPage = useCallback(() => { | ||
| if (autoRefresh || hasPreviousPage) { |
There was a problem hiding this comment.
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.
Meta was being recreated, and highlight terms was referencing MutableSearch which were both causing identity cycling.