Skip to content

Some clarification on smart refresh #5780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

davidfokkema
Copy link
Contributor

A bit of clarification on how smart refresh works. It just calls the render() method of the widget where the reactive attribute is defined. It does nothing more. If you have a compound widget, that will not work and you'll need watch methods or use recompose.

Please review the following checklist.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

I did not update the changelog since nothing changed in the code.

@@ -96,6 +96,10 @@ The `Name` widget has a reactive `who` attribute. When the app modifies that att

Textual will check if a value has really changed, so assigning the same value wont prompt an unnecessary refresh.

!!! information

[Compound widgets](widgets.md/#compound-widgets) do not contain a `render()` method, but rather a `compose()` method. Smart refresh will do nothing, but you can use a [watch method](#watch-methods) to run code to update child widgets if needed. Alternatively, you can use [recompose](#recompose) to remove all child widgets and call `compose()` again.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite accurate. Compound widgets do have render methods, and they are called. Although for most compound widgets, the child widgets cover the parent fully so you never see that.

I've updated the initial paragraph, but I feel this may be too much information at this point. I don't like to have two admonitions next to each other. I also prefer to keep things as linear as possible within a single page, so we aren't encouraging the reader to jump down before they have read the initial text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that the render method of compound widgets was actually called. Makes sense, but in my head, writing widgets, it was always either a render() method or a compose() method. But the one does not exclude the other.

I agree that too much information is not good, and two admonitions are a bit ugly. If you don't want users to jump ahead, I feel that a remark should be made in the relevant sections. I had a bit of trouble with smart refresh as well, and understanding that I should use a watch method for updating child widgets. The word "child" is only first mentioned in the recompose section. But, for most uses, you don't want to use recompose since that is not efficient for simply updating child widgets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants