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 diff --git a/src/textual/app.py b/src/textual/app.py index 2b04f3df9e..c94d0c7ade 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -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 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!                                                                  + + + + + + + + + + + + + + + + + + + + + + + + + + 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())