Closed sweco-nlgucu closed 2 months ago
Is this something you actually need or your only goal was to make it crash?
Put all of your controls in a separate <div>
when using dynamic layers and it won't crash. This is too complex to fix given its benefit.
function App() {
const [anArray, setAnArray] = useState([1, 2]);
useEffect(() => {
setAnArray([1, 2, 3]);
}, []);
return (
<RMap className='example-map' initial={{center: fromLonLat(coords.origin), zoom: 11}}>
<ROSM />
<>
{anArray.map((value) => (
<RLayerVector key={value} />
))}
</>
<div>
<RControl.RCustom></RControl.RCustom>
</div>
</RMap>
);
}
Is this something you actually need or your only goal was to make it crash?
Hi, thanks for looking into this.
Unfortunately I don't have the luxury of time at my work to see if something can crash. Like many of us we need to deliver features and this one appeared when I tried to implement one.
Too bad it's too complex to fix, but thanks for the suggested workaround. We'll create something like a rcustom container component with just the div and maybe some linting rule to avoid using the rcustom components directly in the map container.
Hi there,
we're encountering an Uncaught DOMException in a very specific situation where we have a changing amount of layers, in combination when a
RControl.RCustom
is also in the map.The error:
Uncaught DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
It took me a bit to isolate the issue, as we're building a larger application than just this example. The example is trivial, but triggers the same error as we have in our app. In our own application this happens because we have to load the configuration of layers somewhere from an endpoint and a user will be able to add layers themselves. I've simulated that below with the
useState
anduseEffect
combination. This piece ofApp.jsx
code shows the error, with pointers on how to work around and avoid the error:I can reproduce this error with at least rlayers versions
2.1.0
and3.1.0
To try to reproduce it, please use this repo: https://github.com/sweco-nlgucu/rlayers-bug
I hope this description helps. If you need anything else, let me know! We can work around the issue by making sure there's an empty layer or something between that "array" of layers and the rcontrol.rcustom (similar to solution 2). But I do think this issue is a bug and unexpected behavior.
Cheers, Guus