From 51f7affe030d552151ed1ea923e8b504fe7db2da Mon Sep 17 00:00:00 2001 From: Aleksandr Vasiuro Date: Thu, 25 Jul 2024 17:32:09 +0200 Subject: [PATCH] fix: listbox crash in CI --- components/lib/listbox/ListBox.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/lib/listbox/ListBox.js b/components/lib/listbox/ListBox.js index 5a8bbcb26c..4825db46d4 100644 --- a/components/lib/listbox/ListBox.js +++ b/components/lib/listbox/ListBox.js @@ -474,6 +474,10 @@ export const ListBox = React.memo( const scrollInView = (index = -1) => { setTimeout(() => { + // As long as this is a timeout - there is not guarantee that listRef will still + // exist by the moment of calling that function. So, if list is already destroyed + // by this moment - do nothing: + if (!listRef.current) return; const idx = index !== -1 ? `${id.current}_${index}` : focusedOptionId(); const element = listRef.current.querySelector(`li[id="${idx}"]`);