reactpy icon indicating copy to clipboard operation
reactpy copied to clipboard

Do Not Unmount Old View On Reconnect

Open rmorshea opened this issue 3 years ago • 2 comments
trafficstars

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.

rmorshea avatar Jun 13 '22 02:06 rmorshea

Could not unmounting the view cause a memory leak?

Archmonger avatar Jan 24 '23 08:01 Archmonger

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.

rmorshea avatar Jan 24 '23 18:01 rmorshea

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.

Archmonger avatar Sep 15 '23 00:09 Archmonger