Blazor-Diagrams / Blazor.Diagrams

A fully customizable and extensible all-purpose diagrams library for Blazor
https://blazor-diagrams.zhaytam.com
MIT License
919 stars 176 forks source link

element in unobserve(element, id) is null #272

Closed adiac closed 10 months ago

adiac commented 1 year ago

The issue is reproducible in my project, tho I'm not sure how it exactly came to be. If anyone is interested into looking further into this, I can provide my project code (WPF App with Blazor).

What I did: When I have a couple of nodes in my diagram and zoom in and out further
What happens: In script.js the unobserve function fails to unobserve the given element, because it is null.

TypeError: Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element'.

https://github.com/Blazor-Diagrams/Blazor.Diagrams/blob/83beefa940990bda0cb78078973fc36e50fb6ddd/src/Blazor.Diagrams/wwwroot/script.js#L42

unobserve: (element, id) =>
    {
        s.ro.unobserve(element);  //TypeError
        delete s.tracked[id];
        delete s.canvases[id];
    }

Simple, but not so thoughtful solution:

unobserve: (element, id) =>
    {
        if (element) {
            s.ro.unobserve(element);
        }
        delete s.tracked[id];
        delete s.canvases[id];
    }

I just copied the whole script.js to my project and added this additional falsy check for the parameter. I left the rest untouched.