question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 Fragments are implemented by selecting the first DOM node they contain, right?

What are your thoughts here?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
spiffytechcommented, Apr 10, 2022

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 divs that have meaning in the document.

1reaction
spiffytechcommented, Jan 28, 2022

Sounds good, I’ll add a note about doing that in the readme.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - on unmounting of component not getting the state value
So when i access the state it shows me as undefined. So before unmount i need to get this data. const [name, setName]...
Read more >
componentWillUnMount never happens with ... - GitHub
If not, then return null. After returning null the wrapped component will be unmounted. Small example: class HomeContainer extends React.
Read more >
Handling Mounting And Unmounting Of Navigation Routes In ...
In this article, we are going to walk through mounting and ... If the returned value is null , it means our userToken...
Read more >
React.Component
Once a component instance is unmounted, it will never be mounted again. Rarely Used Lifecycle Methods. The methods in this section correspond to...
Read more >
How to use componentWillUnmount with Functional ...
Right now, even if user cancels or says ok, component will anyway unmount on return funtion. Is there any way to stop unmount...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found