reactpy
reactpy copied to clipboard
Do Not Unmount Old View On Reconnect
Current Situation
Presently, upon reconnecting, the client unmounts the old view and mounts a new one. This results in a brief, but jarring flash as the new view loads.
Proposed Actions
Instead of unmounting the old view we can simply retain it. The first message from the server should be the new VDOM which should be set at the root. This will cause React to render the full tree of components, but it will prevent the view from flashing from the user's perspective.
Could not unmounting the view cause a memory leak?
I don't think so. As a note for this issue, it looks like ReactDOM.render is deprecated in favor of createRoot which returns an object with render and unmount methods. The docs state that calling render multiple times is allowed:
If you call render on the same root more than once, React will update the DOM as necessary to reflect the latest JSX you passed. React will decide which parts of the DOM can be reused and which need to be recreated by “matching it up” with the previously rendered tree. Calling render on the same root again is similar to calling the set function on the root component: React avoids unnecessary DOM updates.
This issue was resolved in #886 and #901.
There is still the separate issue of the initial mount deleting the inner contents of the div, which can complicate #578.
Closing this issue.