Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
React 18 workaround
This PR makes react-spaces work with React18, by replacing calls to
useEffect
with a customuseEffectOnce
(taken from https://blog.ag-grid.com/avoiding-react-18-double-mount/ )This fixes an incompatibility issue with the changes in React v18 Strict Mode, which is causing components to be (un)mounted twice, which breaks react-spaces: https://reactjs.org/blog/2022/03/29/react-v18.html#new-strict-mode-behaviors
Strict Mode and react-spaces
When a space is rendered with the new strict mode, react spaces goes through the following steps:
spaces
storeuseEffect
hook initializer, set a reference to the DOM element inspace.element
useEffect
clean up function: destroy the space and remove it from the storespaces
storeuseEffect
init a second time, thereforce missing the reference tospace.element
useEffectOnce
works around the problem by not running the clean up function when React18 is doing this double (un)mount