Fix TodoListWidget crash: ensure Static always has valid content before becoming visible
- SHA
f768f960cdd95d5ac19abec0f6b510974074e0dc- Parents
-
42508d2 - Tree
9e57172
f768f96
f768f960cdd95d5ac19abec0f6b510974074e0dc42508d2
9e57172| Status | File | + | - |
|---|---|---|---|
| M |
src/loader/ui/widgets/todo_list.py
|
10 | 3 |
src/loader/ui/widgets/todo_list.pymodified@@ -40,16 +40,20 @@ class TodoListWidget(Widget): | ||
| 40 | 40 | self._items: list[dict[str, str]] = [] |
| 41 | 41 | |
| 42 | 42 | def compose(self) -> ComposeResult: |
| 43 | - yield Static("", id="todo-content") | |
| 43 | + # Use a space so the Static always has valid renderable content. | |
| 44 | + # An empty string can produce visual=None and crash Textual's | |
| 45 | + # render pipeline when the widget is visible. | |
| 46 | + yield Static(" ", id="todo-content") | |
| 44 | 47 | |
| 45 | 48 | def update_todos(self, todos: list[dict[str, str]]) -> None: |
| 46 | 49 | """Replace the displayed todo list.""" |
| 47 | 50 | self._items = list(todos) |
| 48 | 51 | if not self._items: |
| 49 | 52 | self.remove_class("has-items") |
| 53 | + self.query_one("#todo-content", Static).update(" ") | |
| 50 | 54 | return |
| 51 | - self.add_class("has-items") | |
| 52 | 55 | self._render() |
| 56 | + self.add_class("has-items") | |
| 53 | 57 | |
| 54 | 58 | def _render(self) -> None: |
| 55 | 59 | content = Text() |
@@ -69,4 +73,7 @@ class TodoListWidget(Widget): | ||
| 69 | 73 | content.append(label) |
| 70 | 74 | content.append("\n") |
| 71 | 75 | |
| 72 | - self.query_one("#todo-content", Static).update(content) | |
| 76 | + try: | |
| 77 | + self.query_one("#todo-content", Static).update(content) | |
| 78 | + except Exception: | |
| 79 | + pass # widget not mounted yet; will render on next update | |