Remove struct components #2282
Replies: 15 comments 26 replies
-
Ofc i am worried about performance/bundle sizes. We need to make sure of what we would be losing/sacrificing first, before making the decision. |
Beta Was this translation helpful? Give feedback.
-
Somebody here. ;) I do support the move to function component whenever possible. However, there’re a couple things to consider before removing struct components:
I think removing most struct component examples / mentions from the website should be good enough for the moment. |
Beta Was this translation helpful? Give feedback.
-
Is part of the suggestion of special treatment of function components to auto-detect Hooks provide a way to interact with the lifecycle in a function component, but there are several rough edges, like dealing with lifetimes of the contained state, or the fact that you have to call them always in the same order. Dealing with those problems in react, for example, there's a custom lint pass that warns you if you have a hook under a conditional. But at the end of the day, that's just pretending that function components are the end-all-be-all of design which they aren't, imo. If they are the only thing appearing in docs, a loud wake-up call will be heard when another paradigm evolves that solves any of the issues function components still have (do I see generators on the horizon?). Tl;dr: the |
Beta Was this translation helpful? Give feedback.
-
I think supporting both at least in main documentation and philosophy isn't a great idea. All it will do is split an already small community and confuse newcomers when tutorials offer completely different directions. I believe one side would feel neglected and eventually just fork off. I actually prefer Components v2 to functional components so it pains me to say that, but I don't think pushing both is healthy for the project. I don't think v2 is really all that much boiler plate compared to functional components and it does a better job of making code readable. If the direction is functional components there needs to be a really strong push toward in depth documentation, examples, and ergonomics. I do like the functional components, but they push some of the more complicated aspects of Rust to the forefront. There's a lot of roadblocks that a beginning Rust user is going to slam head first into using functional components, mainly A LOT of borrow checking. Maybe it's not important to hand hold new Rust developers in Yew, but I think Yew will become a really attractive crate for people coming over to Rust. Web development is extremely popular and there's a lot of people excited to hop off JavaScript. I fear with the state of functional components newbies are going to slam head first into the roadblocks and give up immediately. With components, most newbies can probably follow a simple tutorial and start building simple websites on their own without having to worry about the intricacies of Rc and the borrow checker immediately. |
Beta Was this translation helpful? Give feedback.
-
TL;DR: We should keep struct components as the underlying implementation, but promote function components as the recommended way to start building Yew apps. If we do decide to make the switch to having function components be the primary way to define and interact with components, I think that keeping struct components as the underlying basis is the way to go. I personally find struct components easier to reason about and understand in terms of my own mental model. While I agree that there is a lot of value in presenting a single unified approach to building Yew apps, especially for newcomers to the framework, removing documentation for an equally valid and sometimes preferred approach just introduces friction for those who choose to use struct components. Relegating the relevant docs around struct components to a dedicated section of the docs could be a good compromise, in my opinion. That way, those who are new to Yew can be presented function components as the recommended approach, but those who prefer to use struct components still get documentation to help them with their desired approach. Removing struct components as the underlying implementation feels premature at this point, at least until some of the above-mentioned concerns with function components are ironed out. Regarding #2212, it looks like a super useful feature, but not enough to justify only supporting it in function components. |
Beta Was this translation helpful? Give feedback.
-
For my part, I basically never use function components. I considered them bad in React, and I consider them bad in Yew as well as well for the same reasons. Once in a while I might use one for a component that's nothing more than literally a pure function from props to HTML, but absolutely never for anything more complex.
..and this sort of thing is exactly why. It means that you have mutable state where the parts of that state are named by the order in which they happen to be encountered at runtime and it's mind-boggling to me that anyone considers that anything other than an enormous flashing sign saying "stay away from this!" |
Beta Was this translation helpful? Give feedback.
-
This discussion is spooky because as @JtotheThree said "I believe one side would feel neglected and eventually just fork off." I also learned that its possible function components group may be the minority in yew and as a maintainer i have to make sure struct components will not get neglected. Lets not do any actions of removing either, perhaps given time everything will marinate a bit and actions we need to take will become more clear, be it embracing struct components or functional components. |
Beta Was this translation helpful? Give feedback.
-
I agree with others have mentioned: struct components won't simply go away. But we should focus on one type of components in examples and documentation. Also worth noting is that today, function components have an additional cost of initializing global state for hooks to be used. We need to be remove (or at least benchmark/reduce) that before making a decision to fully switch to them. Also, like I mentioned in #2282 (reply in thread) hooks have the potential to benefit from macros and code gen. We should to explore that too. There's many things that should be explored before a concrete decision here can be made. |
Beta Was this translation helpful? Give feedback.
-
Hello! Just a random person on the internet adding my two cents. |
Beta Was this translation helpful? Give feedback.
-
I agree documentation and simple examples should focus more on functional components. They are easier to understand initially, and what most developers will recognize coming from frameworks like React. That said, hooks can easily become an anti-pattern when used for too complex a task. Elm architecture works because it clearly organizes component behavior. Struct components are a vital foundation, which functional builds on top of. Removing them would effectively cut the legs off this project. |
Beta Was this translation helpful? Give feedback.
-
I'd like to provide a different view point. Being mostly a C++/Python/Rust developer, but with quite a bit of foray into frontend, I find struct components much easier to understand and much cleaner to compose. The functional components feel like 80% use cases to me, but I struggle to implement what I need with them some times. The documentation is frustratingly lacking - right now I am working myself through To me, the struct components have more boilerplate, but the design feels cleaner and easier to understand. Functional components are shorter and are full of magic. I understand functional components is the React way and that might appease frontend devs coming in, however struct components feel like the Rust way to me. I personally would have preferred to never have functional components at all and focus on the functional one. Whatever remains, better documentation for both would be highly appreciated. |
Beta Was this translation helpful? Give feedback.
-
I have created a prototype (#2957) to demonstrate what would be possible if function components are the only type supported by Yew. In summary, If struct components are removed, we can:
This means that without struct components. Yew will have:
Whilst I do not expect that struct components to actually become removed at anytime soon, I think a function component-only Yew does provide some significant advantages than being compatible with both component variants. |
Beta Was this translation helpful? Give feedback.
-
What if we feature-gated struct components? Those who want it can enable
it. Every one can get benefit from function component only Yew
…On Wed, Nov 9, 2022, 5:50 PM Kaede Hoshikawa ***@***.***> wrote:
I have created a prototype (#2957
<#2957>) to demonstrate what would be
possible if function components are the only type supported by Yew.
In summary,
If struct components are removed, we can:
1. remove many allocations.
2. remove generics from most internal types.
3. remove some workarounds in the codebase (e.g.: priority render on
hydration).
This means that without struct components. Yew will have:
1. smaller bundle size.
2. better performance.
3. a cleaner codebase.
4. a smaller public API.
Whilst I do not expect that struct components to actually become removed
at anytime soon, I think a function component-only Yew does provide some
significant advantages than being compatible with both component variants.
—
Reply to this email directly, view it on GitHub
<#2282 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALJJ7WIYTUCIEJSCDNZI6EDWHOMZNANCNFSM5KKVLVKA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I feel struct components are easier to understand - as a beginner. I am still getting used to functional components |
Beta Was this translation helpful? Give feedback.
-
Using struct components I can separate my CSS from my component similar to Svelte. I impl a styled trait beneath my component impl, that way the styles are out of the way and don't clutter my screen. If there's a way to do this with function components that would be nice. |
Beta Was this translation helpful? Give feedback.
-
So more and more I'm dealing with the camp that loves function components and does not give proper attention for struct components.
Context API has lacking documentation and I know its fixable, but we should have noticed the lack of clarity in the docs for struct components. Just look at this issue #2280
Then we already have a case where somebody wants to add a feature that will not be available in struct components #2212
Hooks overall just cause confusion because we need to be super clear everywhere that your struct component will not rerender on its own when just calling a hook function.
I say lets stop the split. Get rid of the legacy, because unlike react we are in
0.x
version and we can do it.Beta Was this translation helpful? Give feedback.
All reactions