From 5858acbd5078b56c75586bb47ecd0ca2b47bda37 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 28 Sep 2025 18:27:01 +0100 Subject: [PATCH 1/4] fix for setting the theme early --- src/textual/app.py | 2 +- tests/snapshot_tests/test_snapshots.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/textual/app.py b/src/textual/app.py index 2b04f3df9e..8617cf0818 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -1419,7 +1419,7 @@ def _validate_theme(self, theme_name: str) -> str: raise InvalidThemeError(message) return theme_name - def _watch_theme(self, theme_name: str) -> None: + async def _watch_theme(self, theme_name: str) -> None: """Apply a theme to the application. This method is called when the theme reactive attribute is set. diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 89a37a204d..21c8816b88 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -4654,3 +4654,25 @@ def compose(self) -> ComposeResult: yield TextArea(placeholder=TEXT) assert snap_compare(PlaceholderApp()) + + +def test_rich_log_early_write(snap_compare) -> None: + """Regression test for https://github.com/Textualize/textual/issues/6123 + + You should see a RichLog with "Hello World" text + + """ + + class TestApp(App): + def compose(self) -> ComposeResult: + with Horizontal(): + yield RichLog() + + def on_mount(self) -> None: + self.theme = "nord" + + def on_ready(self) -> None: + log_widget = self.query_one(RichLog) + log_widget.write("Hello, World!") + + assert snap_compare(TestApp()) From 96a65f8232aa2cd11e78b35a12996712b7a06cb3 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 28 Sep 2025 18:29:14 +0100 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bb51c397f..95f32f8f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed issue where Segments with a style of `None` aren't rendered https://github.com/Textualize/textual/pull/6109 - Fixed visual glitches and crash when changing `DataTable.header_height` https://github.com/Textualize/textual/pull/6128 - Fixed TextArea.placeholder not handling multi-lines https://github.com/Textualize/textual/pull/6138 +- Fixed issue with RichLog when App.theme is set early https://github.com/Textualize/textual/pull/6141 ## [6.1.0] - 2025-08-01 From b16c7bcb2d7746f66192515236d6bbafc8dfa54d Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 28 Sep 2025 19:14:43 +0100 Subject: [PATCH 3/4] snapshot --- .../test_rich_log_early_write.svg | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 tests/snapshot_tests/__snapshots__/test_snapshots/test_rich_log_early_write.svg diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_rich_log_early_write.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_rich_log_early_write.svg new file mode 100644 index 0000000000..f4c8dc5b94 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_rich_log_early_write.svg @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TestApp + + + + + + + + + + Hello, World!                                                                  + + + + + + + + + + + + + + + + + + + + + + + + + + From 43970ae19823324d18c0986cba2e38402a7cf6e0 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 28 Sep 2025 20:31:17 +0100 Subject: [PATCH 4/4] better fix --- src/textual/app.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/textual/app.py b/src/textual/app.py index 8617cf0818..c94d0c7ade 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -1419,7 +1419,7 @@ def _validate_theme(self, theme_name: str) -> str: raise InvalidThemeError(message) return theme_name - async def _watch_theme(self, theme_name: str) -> None: + def _watch_theme(self, theme_name: str) -> None: """Apply a theme to the application. This method is called when the theme reactive attribute is set. @@ -3657,8 +3657,9 @@ def refresh_css(self, animate: bool = True) -> None: stylesheet.reparse() stylesheet.update(self.app, animate=animate) try: - self.screen._refresh_layout(self.size) - self.screen._css_update_count = self._css_update_count + if self.screen.is_mounted: + self.screen._refresh_layout(self.size) + self.screen._css_update_count = self._css_update_count except ScreenError: pass # The other screens in the stack will need to know about some style