Giter Club home page Giter Club logo

Comments (5)

rodrigogiraoserrao avatar rodrigogiraoserrao commented on June 22, 2024

Hey Pablo, thanks for opening this issue.
Would you mind providing a minimal reproducible example that mimics the issue you're describing in your context as closely as possible?

You are probably right in all of the conclusions you made but without having some concrete code to look at and run we may end up spending a bunch of time going back and forth without even knowing if we're talking about the same thing.

from textual.

PabloLec avatar PabloLec commented on June 22, 2024

@rodrigogiraoserrao Yes, no problem, will do asap 👍

from textual.

PabloLec avatar PabloLec commented on June 22, 2024

@rodrigogiraoserrao Here is the MRE: https://github.com/PabloLec/textual_4015_mre/blob/main/textual_4015_mre/__init__.py

With test runs showing the behavior difference between versions: https://github.com/PabloLec/textual_4015_mre/actions

So, since version 0.47.0, you can't access an element's children before compose. The children parameter turns up empty.

This is just a basic example, so its practicality might not be obvious at first.
In my situation, for instance, I've got this asynchronous component that's responsible for creating ListItems with a Label, which can be pretty lengthy, without any restrictions during creation. Then, there's another component that adds these ListItems to a list and chops down the Label text depending on the screen size. And all this happens before compose, before the user can see the result.
I'm focusing on the ListItem example because it's what I'm dealing with, but this is actually a behavior that's common to all components with children.

from textual.

willmcgugan avatar willmcgugan commented on June 22, 2024

There are two ways of adding children.

You can do this...

yield ListItem(item)

Or this...

with ListItem():
    yield item

Both should work in the same way, but the second will have children added after compose. Which is why its not a good idea to rely on the children being available in the constructor.

Widgets that haven't been mounted aren't that useful, and may break if you use their methods, so we want to discourage using them until everything is mounted.

It shouldn't be much of an issue in practice. But you will need to write your tests diffrently. I assume you have seen our guide on testing Textual apps ?

from textual.

github-actions avatar github-actions commented on June 22, 2024

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

from textual.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.