Closed
Description
I've just released v2.0 of a react-xarrows it breaks on apps that are wrapped with React.StrictMode. the component works perfectly fine on trees that are not wrapped with React.StrictMode
React version: 17.0.0
Steps To Reproduce
simple demo
ready to use dev enviroment
it takes about a minute to set up. this env will link react-xarrows to the running example on port 300, so any changes on ./src would immediately be reflected.
- after entering to gitpod, wait to setup.
- explore the demos, they work fine.
- the index file of create-react-app should be opened. if not go to ./examples/src/index.jsx .
- on render function of react-dom replace
<ExamplePage />
with<React.StrictMode><ExamplePage /></React.StrictMode>
- refresh the page(in the mini gitpod browser on the right, not the main page).
- explore demos. The component does not behave the same!
I've tested the lifecycle of react-xarrows in both mods and it appears to be identical, so I can't figure out why apps that use strictmode breaks react-xarrows. I could not figure out why react-xarrows is not printed in StrictMode,
related and possible cause
- react-arrows v2 manage global object of references to update functions to break the dependency between 2 related contexts. details, Xwrapper code.
In simple words - I use a global object in the module Xwrapper.tsx, I pass a reference to this object to both contexts, then one context assigning 'update function'(a function that will cause xarrow to rerender) as a property and the second context consumes that function, and then elements connected to xarrow can selectively rerender only xarrow without triggering renders on other boxes.
I thought that maybe the fact that on StrictMode each render becomes 2 renders causing this issue, but it does not seem to be the problem.
The current behavior
react-xarrows does not work properly on react-trees wrapped with React.StrictMode
The expected behavior
the behavior should be identical in both cases.