Skip to content

Commit f43556f

Browse files
committed
don't update styles when not attached
1 parent b53b628 commit f43556f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## Unreleased
9+
10+
### Changed
11+
12+
- Optimized startup
13+
814
## [3.4.0] - 2025-06-14
915

1016
### Fixed

src/textual/dom.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,8 @@ def _update_styles(self) -> None:
17071707
17081708
Should be called whenever CSS classes / pseudo classes change.
17091709
"""
1710+
if not self.is_attached:
1711+
return
17101712
try:
17111713
self.app.update_styles(self)
17121714
except NoActiveAppError:
@@ -1727,7 +1729,7 @@ def add_class(self, *class_names: str, update: bool = True) -> Self:
17271729
self._classes.update(class_names)
17281730
if old_classes == self._classes:
17291731
return self
1730-
if update and self.is_attached:
1732+
if update:
17311733
self._update_styles()
17321734
return self
17331735

@@ -1746,7 +1748,7 @@ def remove_class(self, *class_names: str, update: bool = True) -> Self:
17461748
self._classes.difference_update(class_names)
17471749
if old_classes == self._classes:
17481750
return self
1749-
if update and self.is_attached:
1751+
if update:
17501752
self._update_styles()
17511753
return self
17521754

0 commit comments

Comments
 (0)