From 37aac01e93cd4d6a21142067edeba39c347efd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Mon, 30 Oct 2023 17:02:18 +0000 Subject: [PATCH] Deduplicate screen CSS errors. Related issue: #3581. --- CHANGELOG.md | 1 + src/textual/css/stylesheet.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf154b5ba8..5393e7a919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed `OptionList` event leakage from `CommandPalette` to `App`. - Fixed crash in `LoadingIndicator` https://github.com/Textualize/textual/pull/3498 - Fixed crash when `Tabs` appeared as a descendant of `TabbedContent` in the DOM https://github.com/Textualize/textual/pull/3602 +- Duplicate CSS errors when parsing CSS from a screen https://github.com/Textualize/textual/issues/3581 ### Added diff --git a/src/textual/css/stylesheet.py b/src/textual/css/stylesheet.py index 3362520293..7852b2c1dd 100644 --- a/src/textual/css/stylesheet.py +++ b/src/textual/css/stylesheet.py @@ -372,10 +372,19 @@ def reparse(self) -> None: tie_breaker=tie_breaker, scope=scope, ) - stylesheet.parse() - self._rules = stylesheet.rules - self._rules_map = None - self.source = stylesheet.source + try: + stylesheet.parse() + except Exception: + # If we don't update self's invalid CSS, we might end up reparsing this CSS + # before Textual quits application mode. + # See https://github.com/Textualize/textual/issues/3581. + self._invalid_css.update(stylesheet._invalid_css) + raise + else: + self._rules = stylesheet.rules + self._rules_map = None + self.source = stylesheet.source + self._require_parse = False @classmethod def _check_rule(