Skip to content

Commit d003294

Browse files
fix: do not crash on use close menu
This is more of a workaround than a fix. But in certain cases (I suspect multiple rerenders) use get_widget call fails. This workaround did not cause the hook not to work, which confirms the suspiction. This is hard to debug, so this is a good enough fix for now.
1 parent ca7127c commit d003294

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

solara/lab/components/input_date.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime as dt
2+
import logging
23
from typing import Callable, Dict, List, Optional, Tuple, Union, cast
34

45
import ipyvue
@@ -9,6 +10,9 @@
910
from solara.components.input import _use_input_type
1011

1112

13+
logger = logging.getLogger(__name__)
14+
15+
1216
def use_close_menu(el: reacton.core.Element, is_open: solara.Reactive[bool]):
1317
is_open_ref = solara.use_ref(is_open)
1418
is_open_ref.current = is_open
@@ -17,7 +21,11 @@ def monitor_events():
1721
def close_menu(*ignore_args):
1822
is_open_ref.current.set(False)
1923

20-
widget = cast(ipyvue.VueWidget, solara.get_widget(el))
24+
try:
25+
widget = cast(ipyvue.VueWidget, solara.get_widget(el))
26+
except Exception:
27+
logger.exception("Error getting widget for use_close_menu")
28+
return
2129
widget.on_event("keyup.enter", close_menu)
2230
widget.on_event("keydown.tab", close_menu)
2331

@@ -178,9 +186,9 @@ def standard_strfy(date: Optional[dt.date]):
178186
max=max_date, # type: ignore
179187
min=min_date, # type: ignore
180188
type=date_picker_type,
189+
children=children,
181190
):
182-
if len(children) > 0:
183-
solara.display(*children)
191+
pass
184192

185193

186194
@solara.component
@@ -366,7 +374,6 @@ def set_dates_cast(values):
366374
max=max_date, # type: ignore
367375
min=min_date, # type: ignore
368376
type=date_picker_type,
377+
children=children,
369378
):
370-
if len(children) > 0:
371-
for el in children:
372-
solara.display(el)
379+
pass

0 commit comments

Comments
 (0)