Skip to content

Getting JSInterop null exception in GetBoundingClientRect when trying <PortRenderer> with child content without CSS position:absolute #493

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

Open
konst-sh opened this issue Dec 27, 2024 · 3 comments

Comments

@konst-sh
Copy link

I'm getting this exception, if on NET8 with interactive server side rendering I try to use PortRenderer with child content like that:

<div>
    <h5 class="card-title">@Node.Instance.OwnDeclaration.Name</h5>
    @foreach (var port in Node.Ports)
    {
        <div>
            <PortRenderer @key="port" Port="port">
                <div>
                    @((port as IInstancePort)?.Name ?? "unknown name")
                </div>
            </PortRenderer>
        </div>
    }
</div>

@code {
    [Parameter] public InstanceModel? Node { get; set; } = null; //InstanceModel
}

and in CSS the position: absolute is disabled:

::deep .diagram-port {
    width: 100%;
    height: 100%;
/*    position:  absolute;*/
    background: #c1bfbe;
}

[2024-12-27T12:42:59.749Z] Error: Microsoft.JSInterop.JSException: n is null
getBoundingClientRect@https://localhost:7040/_content/Z.Blazor.Diagrams/script.min.js:1:56
beginInvokeJSFromDotNet/i<@https://localhost:7040/_framework/blazor.web.js:1:3047
beginInvokeJSFromDotNet@https://localhost:7040/_framework/blazor.web.js:1:3004
_invokeClientMethod@https://localhost:7040/_framework/blazor.web.js:1:62730
_processIncomingData@https://localhost:7040/_framework/blazor.web.js:1:60119
gn/this.connection.onreceive@https://localhost:7040/_framework/blazor.web.js:1:53760
connect/</i.onmessage@https://localhost:7040/_framework/blazor.web.js:1:81866
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at Blazor.Diagrams.Extensions.JSRuntimeExtensions.GetBoundingClientRect(IJSRuntime jsRuntime, ElementReference element)
at Blazor.Diagrams.Components.Renderers.PortRenderer.UpdateDimensions()
at Blazor.Diagrams.Components.Renderers.PortRenderer.OnPortChanged(Model _)
at System.Threading.Tasks.Task.<>c.b__128_0(Object state)
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.PostAsync[TState](Task antecedent, Action`1 callback, TState state)

@konst-sh
Copy link
Author

are we only allowed to use css position: absolute for ports? I would prefer to render ports as elements with custom content but absolute position makes it so weird.

@konst-sh konst-sh changed the title Getting JSInterop exception for GetBoundingClientRect when trying <PortRenderer> with child content without CSS position:absolute Getting JSInterop null exception in GetBoundingClientRect when trying <PortRenderer> with child content without CSS position:absolute Dec 27, 2024
@zHaytam
Copy link
Collaborator

zHaytam commented Feb 28, 2025

I'm not really sure about this, the error doesn't look like it's related to the position, do you have time to create a small repo that shows this issue?

@konst-sh
Copy link
Author

konst-sh commented Mar 2, 2025

@zHaytam this reproduces the issue for me. The diagram will throw the error, if I try to create link from any port with child content, when the position:absolute i commented out in CSS. Thanks for this awesome library, btw!

FSBuilder-diagram node non-absolute positioning issue.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants