A new widget gets no Resize or Show if its region is read before its first layout (after a scroll)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 40/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 37.7k
- Forks
- 1.5k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Textualize/textual
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6790 · 2 comentarios ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Textualize/textual#6789 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6787 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6782 · 1 comentario ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Textualize/textual#6778 · 1 comentario ·
Todos los issues de Textualize/textual
Issues similares
-
Internal ErrorAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
frappe/frappe_docker#2071 ·
Los mantenedores suelen responder en 1 día
-
bug python
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
traceloop/openllmetry#4717 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Abiertocomp/desktop P2 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NousResearch/hermes-agent#157702 ·
Los mantenedores suelen responder en 1 día
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenPosiblemente ocupada @BahaaMattar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
Los mantenedores suelen responder en 1 día