Should widget::component be behind "lazy" feature?

The concept behind widget::component seems to me to be about encapsulation, which is quite separate from lazy re-rendering which in my mind is purely about performance. Actually they seem quite at odds since encapsulation should make the code simpler whereas if anything lazy widgets require more logic to implement. The code implementing component also does not seem to depend at all on any of the other code behind the “lazy” feature.

Given the above, I wonder if widget::component should not be behind its own feature or just in the standard crate. Or perhaps the “lazy” feature should be renamed to emphasize that it covers more than just lazy widgets. What are peoples’ thoughts?

As a seperate point, it is very unhelpful that the component() (and other) function(s) are not marked as requiring the “lazy” feature in the documentation. After some experimentation, it seems the individual functions in widget/src/lazy/helpers.rs need to have the #[cfg(feature = "lazy")] attribute, not just the re-export statement in widget/src/lib.rs. I’m aware this is a nightly feature of rustdoc and so may change but does seem like a useful addition, happy to do a PR with this change and any other instances of this problem I find.

1 Like

A component is lazy in the sense that it defers the computation of its view until its internal widget state is available.

In order to achieve this, we rely on ouroboros to store the resulting view in the widget itself.

The code behind the lazy feature is the most complex, bug-prone code we own. It needs a proper review and refactor, probably replacing ouroboros with self_cell.

Ah, interesting; that makes much more sense. Thank you for explaining.

Definitely sensible to keep those items together under the same feature flag then but I think it might still be worth thinking about renaming the feature so that it is more intuitive for the end user who does not know about the implementation.

Although, if a large review/refactor is in the timeline then perhaps any discussion should be deferred until then.