A new widget gets no Resize or Show if its region is read before its first layout (after a scroll)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 40/100
Direzione di ricerca
Start in Compositor.reflow and Compositor.reflow_visible, and read the full_map property where the map is rebuilt lazily. The bug is that reflow computes shown_widgets against a map that a region read has already rebuilt, so a new widget is never counted as shown. Run the repro script with and without probe.region; done means both runs report the same Resize and Show events.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I hit this while writing generated tests against Textual's widgets. A Placeholder(variant="size") sometimes showed no size text at all, and I traced it to the compositor.
After a scroll, Compositor.reflow_visible marks the full map invalid, and the full_map property rebuilds it lazily the next time something asks for a widget's region. If that happens for a newly mounted widget before the next layout, the rebuilt map already contains it. Compositor.reflow then compares the new layout against that map (shown_widgets = new_widgets - old_widgets), so the widget doesn't count as shown, its size hasn't changed, and it never gets a Resize or a Show.
Repro with a plain widget that records its events:
import asyncio
import textual
from textual import events
from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Static
class Probe(Static):
def __init__(self) -> None:
super().__init__("probe")
self.seen: list[str] = []
def on_resize(self, event: events.Resize) -> None:
self.seen.append(f"Resize{tuple(event.size)}")
def on_show(self) -> None:
self.seen.append("Show")
class ProbeApp(App):
CSS = "Static { height: 5; }"
def compose(self) -> ComposeResult:
with VerticalScroll():
for n in range(5):
yield Static(f"line {n}")
async def run(read_region: bool) -> None:
app = ProbeApp()
async with app.run_test(size=(40, 12)) as pilot:
scroll = app.query_one(VerticalScroll)
scroll.scroll_to(y=2, animate=False)
await pilot.pause()
probe = Probe()
await scroll.mount(probe)
if read_region:
probe.region
await pilot.pause()
await pilot.pause()
print(f"read region before layout={read_region}: events {probe.seen}")
async def main() -> None:
await run(False)
await run(True)
print("Textual", textual.__version__)
asyncio.run(main())
Output on Textual 8.2.7 (and the same on main at 5e5b7ef):
read region before layout=False: events ['Resize(38, 5)', 'Show']
read region before layout=True: events []
The only difference between the two runs is reading probe.region once before the layout. In a real app the read can come from anything that calls find_widget, such as scroll_visible, widget.region in a handler, or a worker finishing at the wrong moment, so whether a widget gets its events depends on timing. Widgets that set state in on_resize show it: here, a Placeholder(variant="size") mounted the same way stays blank:
size text: '' actual size: (38, 5)
(without the region read it shows [b]38 x 5[/b]). Tree._on_resize is skipped the same way, if a DirectoryTree load finishes between a scroll and the next layout.
I expected the result not to depend on whether something read the region first. My suggested fix is for reflow to compare against the map from the last reflow, rather than whatever full_map was last rebuilt to. I have that as a PR with a test, but it's in the compositor, so I'm happy to take a different approach if you'd rather.
- 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
-
author-page correction move-papers
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
acl-org/acl-anthology#10978 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
HKUDS/CLI-Anything#652 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Project-N-E-K-O/N.E.K.O#3813 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Dao-AILab/flash-attention#3191 ·
I maintainer di solito rispondono entro 4 giorni