Components are unmounted / never mounted if they return null
See original GitHub issue#37 got me curious to seek clarity on what Forgo does when a component returns null. I see that Forgo unmounts the component if it returns null, throwing away the component’s state (sandbox).
This makes sense given the explanation that component state is stored on its DOM node, but is unexpected as an application developer. The decision not to display any HTML seems unrelated to the decision to discard component state. For example, if a component wants to return null until a resource has loaded that seems to not work right now.
If Forgo bases all its internal bookkeeping assuming a component always corresponds to a DOM node, does that mean this behavior would be pretty involved to change? I think even Fragment
s are implemented by selecting the first DOM node they contain, right?
What are your thoughts here?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Fun fact: HTML comments count as DOM nodes. You can add/remove/retrieve them, and add properties onto them. It seems pretty similar to using text nodes.
At some point I’m going to take a crack at handling null renders by rendering an HTML comment that we can put the component state onto. That should let stateful components recover from a null render, without polluting the DOM with stuff like
div
s that have meaning in the document.Sounds good, I’ll add a note about doing that in the readme.