From eaf2ef43db3519c4351a5cd6119c3c0f68d0819d Mon Sep 17 00:00:00 2001 From: Gonzalo Ruiz de Villa Date: Thu, 13 Feb 2025 18:28:08 +0100 Subject: [PATCH] fix(MarkdownFence): gracefully handle missing Static child in _retheme callback Wrap update call in try/except to prevent exceptions when the Static child isn't yet mounted. --- src/textual/widgets/_markdown.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/textual/widgets/_markdown.py b/src/textual/widgets/_markdown.py index ad796b173f..e13935e9a2 100644 --- a/src/textual/widgets/_markdown.py +++ b/src/textual/widgets/_markdown.py @@ -20,6 +20,7 @@ from textual.app import ComposeResult from textual.await_complete import AwaitComplete from textual.containers import Horizontal, Vertical, VerticalScroll +from textual.css.query import NoMatches from textual.events import Mount from textual.message import Message from textual.reactive import reactive, var @@ -425,7 +426,7 @@ class MarkdownOrderedList(MarkdownList): MarkdownOrderedList Vertical { height: auto; - width: 1fr; + width: 1fr; } """ @@ -651,7 +652,10 @@ def _retheme(self) -> None: if self.app.current_theme.dark else self._markdown.code_light_theme ) - self.get_child_by_type(Static).update(self._block()) + try: + self.get_child_by_type(Static).update(self._block()) + except NoMatches: + pass def compose(self) -> ComposeResult: yield Static(