`App.clear_notifications()` leaves an empty `ToastHolder` behind for every toast
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 52/100
Research direction
Start in textual/widgets/_toast.py: ToastRack.show dismisses stale toasts with toast.remove(), while Toast._expire removes self.parent when it is a ToastHolder. The first thing to do is run the reproduction script from the issue and check len(rack.query(ToastHolder)) before and after app.clear_notifications(). Done means no holders remain after clearing, matching the timeout path, and the reporter's test passes. Note the reporter says a PR with a test is already prepared, so check that before starting.
Written by the indexing model from the issue text.
Description
Hi! I hit this while writing generated tests against Textual's widgets.
ToastRack.show removes stale toasts with toast.remove(), but each Toast is wrapped in a ToastHolder, and the holder stays. Toast._expire removes the holder (self.parent if isinstance(self.parent, ToastHolder) else self), so toasts that time out are fine. Toasts removed by clear_notifications() leave their holders, and they build up in the rack.
import asyncio
import textual
from textual.app import App
from textual.widgets._toast import Toast, ToastHolder, ToastRack
async def main() -> None:
app = App()
async with app.run_test(notifications=True) as pilot:
for n in range(3):
app.notify(f"message {n}")
await pilot.pause()
rack = app.screen.query_one(ToastRack)
print("after 3 notify: holders", len(rack.query(ToastHolder)), "toasts", len(rack.query(Toast)))
app.clear_notifications()
await pilot.pause()
print("after clear: holders", len(rack.query(ToastHolder)), "toasts", len(rack.query(Toast)))
app.notify("one more")
await pilot.pause()
print("after 1 notify: holders", len(rack.query(ToastHolder)), "toasts", len(rack.query(Toast)))
print("Textual", textual.__version__)
asyncio.run(main())
Output on Textual 8.2.7 (and the same on main at 5e5b7ef):
after 3 notify: holders 3 toasts 3
after clear: holders 3 toasts 0
after 1 notify: holders 4 toasts 1
The empty holders are height: auto, so in the cases I tried nothing shows on screen. They just stay in the DOM, so an app that clears notifications often keeps adding to the rack. I expected clear_notifications() to leave no holders, as when toasts time out. Removing the holder in show the way _expire does fixes it; I have a PR with a test ready.
- Dominant language
- Python
- Stars
- 37.7k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/textual
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6790 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Textualize/textual#6789 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6787 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6782 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Textualize/textual#6778 · 1 comment ·
All issues in Textualize/textual
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day