Footer recomposes twice for each focus change
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 37.7k
- フォーク
- 1.5k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Textualize/textual のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Textualize/textual#6790 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
Textualize/textual#6789 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Textualize/textual#6787 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Textualize/textual#6782 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
Textualize/textual#6778 · コメント 1 件 ·
Textualize/textual の issue をすべて見る
似ている issue
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskオープン
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
sandbox-quantum/switch#2163 ·
メンテナーはふだん 1 日以内に返信
-
bug pydanty:is-working
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
pydantic/pydantic-ai#13939 ·
メンテナーはふだん 1 日以内に返信
-
priority: low python
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
LearningCircuit/local-deep-research#8849 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
francescopace/espectre#223 ·
メンテナーはふだん 3 日以内に返信
-
good first issue Status: Triaged
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
canonical/imagecraft#538 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信