Footer recomposes twice for each focus change
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 52/100
Direzione di ricerca
Start by tracing Screen.set_focus, Screen._watch_focused, and Footer.bindings_changed to confirm when each bindings_updated_signal is published. Run the provided run_test reproduction and check whether the deferred refresh is needed after focus handling. Done means the intended recompose behavior is established and covered by a regression test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I noticed this while tracing messages in tests: each focus change makes the Footer recompose twice.
Screen.set_focus sets self.focused, and Screen._watch_focused calls refresh_bindings(). Then, at the end of set_focus, self.call_after_refresh(self.refresh_bindings) publishes bindings_updated_signal a second time. Footer.bindings_changed answers each one with call_after_refresh(self.recompose), so the Footer rebuilds all its keys twice.
import asyncio
import collections
import sys
import textual
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Button, Footer
class CountingFooter(Footer):
recomposes = 0
async def recompose(self) -> None:
CountingFooter.recomposes += 1
await super().recompose()
class FirstButton(Button):
BINDINGS = [Binding("f", "first", "First")]
class SecondButton(Button):
BINDINGS = [Binding("s", "second", "Second")]
class FooterApp(App):
def compose(self) -> ComposeResult:
yield FirstButton("one")
yield SecondButton("two")
yield CountingFooter()
async def once() -> int:
app = FooterApp()
async with app.run_test() as pilot:
await pilot.pause(0.2)
CountingFooter.recomposes = 0
await pilot.press("tab")
await pilot.pause(0.2)
return CountingFooter.recomposes
async def main() -> None:
runs = int(sys.argv[1]) if len(sys.argv) > 1 else 20
tally = collections.Counter()
for _ in range(runs):
tally[await once()] += 1
print(f"Textual {textual.__version__}, {runs} runs")
print("Footer recomposes after one Tab -> runs:", dict(sorted(tally.items())))
asyncio.run(main())
Output on main (5e5b7ef), Python 3.13, macOS (8.2.7 is the same):
Textual 8.2.8, 30 runs
Footer recomposes after one Tab -> runs: {2: 30}
I expected one recompose per focus change. The two requests come from different points in time (one when focused changes, one after the next refresh), so I don't think the Footer can simply coalesce them. Is the deferred refresh_bindings in set_focus still needed now that _watch_focused refreshes bindings? If it's there so that bindings are checked again after the newly focused widget has handled Focus, that would explain it, and the double recompose may just be the cost of that. I wanted to check before suggesting a change.
- Lingua principale
- Python
- Stelle
- 37.7k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Textualize/textual
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6790 · 2 commenti ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
Textualize/textual#6789 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6787 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6782 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
Textualize/textual#6778 · 1 commento ·
Tutte le issue di Textualize/textual
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mohanraj00/entelos#200 ·
I maintainer di solito rispondono entro 1 giorno
-
Dead url in mise.tomlAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
-
sweep
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
bketelsen/truenas-mcp#77 ·
I maintainer di solito rispondono entro 1 giorno
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
sandbox-quantum/switch#2163 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
openedx/xblock-lti-consumer#765 ·
I maintainer di solito rispondono entro 1 giorno