gl-react icon indicating copy to clipboard operation
gl-react copied to clipboard

Update project to work with latest react

Open martinbooth opened this issue 1 year ago • 0 comments

Summary

This removes the usage of the legacy context apis which have been completely removed in react 19.

Additionally, it fixes: https://github.com/gre/gl-react/issues/408. It's not a great fix as it removes code deliberately added to help chrome GC unused webglcontexts, but chrome will GC them (eventually).. this is an api that is only supposed to be used for testing. The bug is caused because react (in dev mode) double renders to ensure your app is compatible with concurrent mode features, and destroying the webglcontext like this means on the second render the webglcontext is unusable. I've found no way to restore it

Finally it fixes an issue with nested Nodes also caused by the double render. When a parent Node is unmounted it tells the children it is no longer a dependent but it doesn't remove the child node from itself as a dependency. When the tree is reconstructed in the second render it doesn't re-add the child as a dependency (because it was never removed on unmount) but this no-op means it doesn't add itself as a dependent again (which does need to happen because it was removed)

Test plan

I've tested the example in the readme, and more complicated examples that have nested Nodes.. The PR should be pretty safe because things can't get much more broken then they are now (with the latest react at least)

martinbooth avatar Jan 04 '25 01:01 martinbooth