diff --git a/CHANGELOG.md b/CHANGELOG.md index 042796b7b..52b700ef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Numbers in a descendant-combined selector no longer cause an error https://github.com/Textualize/textual/issues/1836 - Fixed superfluous scrolling when focusing a docked widget https://github.com/Textualize/textual/issues/1816 +- Fixes walk_children which was returning more than one screen https://github.com/Textualize/textual/issues/1846 +- Fixed issue with watchers fired for detached nodes https://github.com/Textualize/textual/issues/1846 ## [0.11.1] - 2023-02-17 diff --git a/src/textual/reactive.py b/src/textual/reactive.py index f03624a0c..098ab031b 100644 --- a/src/textual/reactive.py +++ b/src/textual/reactive.py @@ -239,10 +239,9 @@ class Reactive(Generic[ReactiveType]): ) ) - if obj.is_attached: - watch_function = getattr(obj, f"watch_{name}", None) - if callable(watch_function): - invoke_watcher(watch_function, old_value, value) + watch_function = getattr(obj, f"watch_{name}", None) + if callable(watch_function): + invoke_watcher(watch_function, old_value, value) # Process "global" watchers watchers: list[tuple[Reactable, Callable]] diff --git a/tests/test_screens.py b/tests/test_screens.py index ca56df9c5..3edc5dce5 100644 --- a/tests/test_screens.py +++ b/tests/test_screens.py @@ -11,6 +11,22 @@ skip_py310 = pytest.mark.skipif( ) +async def test_screen_walk_children(): + """Test query only reports active screen.""" + + class ScreensApp(App): + pass + + app = ScreensApp() + async with app.run_test() as pilot: + screen1 = Screen() + screen2 = Screen() + pilot.app.push_screen(screen1) + assert list(pilot.app.query("*")) == [screen1] + pilot.app.push_screen(screen2) + assert list(pilot.app.query("*")) == [screen2] + + async def test_installed_screens(): class ScreensApp(App): SCREENS = {