Conversation
| </CheckWrap> | ||
| )} | ||
| {leading ? <LeadWrap aria-hidden="true">{leading}</LeadWrap> : null} | ||
| {leadingItems} |
There was a problem hiding this comment.
Bug: The component will crash if the leadingItems prop is a function because it's rendered directly instead of being called first.
Severity: HIGH
Suggested Fix
In listBox/option.tsx, before rendering leadingItems, check if it is a function. If it is, call it with the appropriate state arguments ({disabled: isDisabled, isFocused, isSelected}) to get the renderable React.ReactNode, similar to the implementation in gridList/option.tsx.
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/components/core/compactSelect/listBox/option.tsx#L96
Potential issue: In `listBox/option.tsx`, the `leadingItems` prop is rendered directly.
However, the type definition for this prop allows it to be a function that returns a
`React.ReactNode`. If a function is passed as the `leadingItems` prop, which is a valid
use case as seen in `hybridFilter.tsx`, React will attempt to render the function itself
as a child. This will cause a runtime error stating "Functions are not valid as a React
child", crashing the component. The corresponding implementation in
`gridList/option.tsx` correctly handles this by checking if `leadingItems` is a function
and invoking it if so.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| </CheckWrap> | ||
| )} | ||
| {leading ? <LeadWrap aria-hidden="true">{leading}</LeadWrap> : null} | ||
| {leadingItems} |
There was a problem hiding this comment.
Function leadingItems not called in listBox option
High Severity
The leadingItems prop can be a function (of type ExtraContent), but line 96 renders {leadingItems} directly without checking the type. When leadingItems is a function, it won't be invoked and will render incorrectly or not at all. The sibling component gridList/option.tsx correctly handles this with typeof leadingItems === 'function' ? leadingItems({disabled, isFocused, isSelected}) : leadingItems, and menuListItem.tsx follows the same pattern.
| ); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [multiple, isSelected, isDisabled, isFocused, size, leadingItems, hideCheck]); | ||
| }, [multiple, isSelected, isDisabled, size, leadingItems, hideCheck]); |
There was a problem hiding this comment.
Missing isFocused dependency causes stale closure
Medium Severity
The useMemo dependency array on line 114 is missing isFocused, but line 109 passes isFocused to the leadingItems function call. When the focus state changes, the memoized value won't recalculate, causing the leadingItems function to receive a stale isFocused value.
This reverts commit 56c668f.