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
Conditional Rendering and Children component interact strangely #3256
Comments
The "omitted" element is rendered as an empty fragment, |
I solved this by just moving the condition outside of the If this is considered a bug, feel free to keep it open! |
I opened a PR to change this but was convinced by @futursolo that omitting these is not the semantically correct fix. The problem remains though. The insertion of a default // not allowed
html! {
{ () }
} I understand if this is considered pedantic, there's IMO no need to fix this if it is community-disruptive. If there is appetite to fix it, I propose either:
|
When you write An argument can be raised for For the issue itself, I think there is a discrepancy in the design of
Ideally, like in React, if you wish to further process children, you need to pass it in a way other than This provides 2 advantages:
I am actually fine with making |
This will most likely break quite a few existing components, especially those that are used in non-trivial applications, which makes it even harder to find work-arounds and alternatives for those if we were to do this. VDom should stay introspectable, but on the other hand I think breaking changes are to be expected and implied if one ends up using that introspection API. Can we have both? For example, with the following - maybe too subtle, but I think teachable - semantic change. Currently there are a few syntaxes with similar, but imo inconsistent, meaning:
The The Small note: This is also related to #3262. I think it's important that extending the children, instead of the react behaviour of starting sublists, remains possible. Think of a list where I want to separate elements into two categories, e.g. "inactive" and "active" and render I would expect that all six cases here work! But, with slight changes in semantics. Using braces - cases (Vec1, Vec3, If1, If3) - should lead to exactly one child in the parent list, i.e. a nested fragment which is then reconciled as a list of its own like in react. Vec2 and If2 should be useable for a variable number of children. Vec2 extends the list with those elements from the iterator. If2 extends the list if the condition is true, otherwise inserts no element (instead of the current placeholder) - related to #3157, the proposed workaround there would then be automatic. |
React's documentation says the following:
React considered their Children API as a Legacy API for the reasons they described in their documentation, which applies to our Children API as well. I think we should consider eventually removing Children as Rust crates should have a higher bar against unsound API. React's Children manipulation API is more limited than ours, but they still cannot eliminated all edge cases. Our Children API allows all iterator methods, which created more unfixable edge cases and enabled users to easier "abusing" the API.
We don't have to make this a breaking change. We can deprecate We also already broke every non-trivial function component in the next release by changing the dependency order so I think it's fine to have another big change even if it is a breaking change (which it can be done without being a breaking change). I am also fine with keeping a
However, I still wouldn't recommend this to anyone if we have to explain things like #3256. I wish to save the discussion that extends Why I think Children trying to inspect / manipulate what
|
Problem
I am trying to conditionally render some HTML that goes through a Children component. When using
enumerate()
on the Children iterator, should-be-skipped components are rendered anyways.Steps To Reproduce
Steps to reproduce the behavior:
C
is not rendered, but is still given an iteration.Expected behavior
The enumerator should only give 3 iterations, skipping the would-be
C
iteration.I assume that the
x
iterator is getting some ghost value at some point. Can I just check for that instead as a workaround? What would that look like?Environment:
Whatever is on Yew playground on May 3, 2023
Questionnaire
The text was updated successfully, but these errors were encountered: