-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use in React 18: Destroying a component with DistortableImage crashes app #1391
Comments
Thanks for opening your first issue here! This space is protected by our Code of Conduct - and we're here to help. |
Fixed the problem for anyone who find a problem implementing DistortableImage into React /React leaflet - think it relates to issue #1381 in a way with
crashing the app
context being from @react-leaflet/core I used #1381 solution getting reference to the map via context and it works as expected
|
I believe it's a similar issue to one we experienced when unmounting the whole map: #1381 The whole remove operation errors because removing each individual layer fails if it's a DistortableImage layer with certain handles like you described. I'm not sure what causes it but we did find a hacky workaround. I suggest you keep track of L.DistortableImageLayer in your hook and unmount it like this: /* eslint-disable @typescript-eslint/ban-ts-comment */
// @ ts-ignore
if (layer.editing) {
// @ts-ignore
const layers = layer.editing.currentHandle?._layers ?? {};
// @ts-ignore
Object.values(layers).forEach(layer => layer.remove());
// @ts-ignore
layer.editing.currentHandle = null;
}
layer.remove();
/* eslint-enable @typescript-eslint/ban-ts-comment */ I'm not entirely sure this will work for your in your case but we also had problems when removing individual layers like I assume you are trying to do. When attempting to remove the entire map after this, our app crashed just like yours does. The error we were getting was slightly different but also occurred in Edit: beat me to it 😄 |
@jpoep a simultaneous response :D |
Any updates on this issue? |
thank you for this solution. finally, i solved this issue but i have confused when call this logic in hooks,
|
Scope:
React v.18.2.0, vite v.4.4.5, React-Leaflet: v4.2.1, Leaflet.DistortableImage: v0.21.9
Description:
Not sure if this is a bug, my usage, or simply DistortableImage isn't set up for use in React?
Destroying a component results in a crash of the app, specifically if I included the action L.RotateAction or L.LockAction (pass in as an array or used as default) When I have these eliminated everything works as expected.
Think the problem lays with the unbinding of the event handlers and the loss of context relating to 'this' , initialized by React during diffing stage ?
See console error(s)
offending line of code in editHandle.js
useEffect in compoment
Parent component
As a side note I tried to remove the action in useEffect (using the useeffect clean up function) but cannot locate the method 'removeTool' I dont see it on any of the instances prototypes ?
The text was updated successfully, but these errors were encountered: