LayTec-AG / Plotly.Blazor

This library packages the well-known charting library plotly.js into a razor component that can be used in a Blazor project.
MIT License
340 stars 48 forks source link

Lazy Load of plotly-interop.js uses a rooted Path #418

Closed wleader closed 4 months ago

wleader commented 4 months ago

The new Lazy Load code uses path that starts with '/' causing the loading code to make a request where the path is from the server root.

See: https://github.com/LayTec-AG/Plotly.Blazor/blob/f8e5e8508f1a64242c4d51637f04539f1c015456/Plotly.Blazor/PlotlyJsInterop.cs#L17

In my case, my Blazor WASM app is served up from a uri like: https://server.domain/application/

This means that the correct uri to plotly-interop.js is: https://server.domain/application/_content/Plotly.Blazor/plotly-interop.js

At run time, it is trying to load from: https://server.domain/_content/Plotly.Blazor/plotly-interop.js

This results in the following exception:

Loading module from “https://server.domain/_content/Plotly.Blazor/plotly-interop.js” was blocked because of a disallowed MIME type (“text/html”).
Loading failed for the module with source “https://server.domain/_content/Plotly.Blazor/plotly-interop.js”. 
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: error loading dynamically imported module: https://server.domainv/_content/Plotly.Blazor/plotly-interop.js
Microsoft.JSInterop.JSException: error loading dynamically imported module: https://server.domain/_content/Plotly.Blazor/plotly-interop.js
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.IJSObjectReference, Microsoft.JSInterop, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at Plotly.Blazor.PlotlyJsInterop.NewPlot(CancellationToken cancellationToken)
   at Plotly.Blazor.PlotlyChart.NewPlot(CancellationToken cancellationToken)
   at Plotly.Blazor.PlotlyChart.OnAfterRenderAsync(Boolean firstRender)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

The initial error is a bit of red-herring reporting that it is the wrong content type of text/html, but that this because the 404 error body is text/html.

sean-mcl commented 4 months ago

Will merge it on monday and will create a new release. 😊 Thanks for the fix.

wleader commented 4 months ago

The new release is working fine for me. Thanks!