Skip to content

Commit 3aa253c

Browse files
neeto-dev-bot[bot]Neeto Dev Botclaude
authored
Guard CustomOption scrollIntoView against null ref (#2832)
When a Select closes while a useEffect scroll-to-selected-option is pending (e.g. concurrent rendering or rapid open/close), React sets ref.current to null during Option unmount before the effect fires. The `props.isSelected && ref.current.scrollIntoView()` call then throws TypeError: Cannot read properties of null (reading 'scrollIntoView'). Using optional chaining (ref.current?.scrollIntoView()) makes the call a no-op when the component has already unmounted. Fixes neetozone/neeto-cal-web#23714 Co-authored-by: Neeto Dev Bot <agent@neeto-dev-bot.neetozone.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9d0cf3c commit 3aa253c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/components/Select.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const CustomOption = props => {
8787
} = props;
8888

8989
useEffect(() => {
90-
props.isSelected && ref.current.scrollIntoView();
90+
props.isSelected && ref.current?.scrollIntoView();
9191
}, [props.isSelected]);
9292

9393
const optionComponent = (

0 commit comments

Comments
 (0)