Korthax / BlazorSplitGrid

MIT License
3 stars 2 forks source link

Blazor Server sometimes requires additional script import as Split method is not found #3

Closed thatstatsguy closed 9 months ago

thatstatsguy commented 1 year ago

I realise that this might a niche issue with the specific 3rd party libraries I'm using, but thought I'd mention this incase anyone else runs into this.

When running my Blazor Server application I'm running into the following exception.

blazor.server.js:1  [2023-07-30T18:56:34.846Z] Error: Microsoft.JSInterop.JSException: window.Split is not a function
TypeError: window.Split is not a function
    at Module.initSplitGrid (https://localhost:7218/_content/BlazorSplitGrid/splitGridInterop.js:49:26)
    at https://localhost:7218/_framework/blazor.server.js:1:3506
    at new Promise (<anonymous>)
    at Ft.beginInvokeJSFromDotNet (https://localhost:7218/_framework/blazor.server.js:1:3480)
    at Ft._invokeClientMethod (https://localhost:7218/_framework/blazor.server.js:1:75072)
    at Ft._processIncomingData (https://localhost:7218/_framework/blazor.server.js:1:72696)
    at Ft.connection.onreceive (https://localhost:7218/_framework/blazor.server.js:1:67009)
    at i.onmessage (https://localhost:7218/_framework/blazor.server.js:1:51322)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
   at BlazorSplitGrid.Interop.SplitGridInterop.Initialise(IEnumerable`1 rowGutters, IEnumerable`1 columnGutters, SplitGridOptions options)
   at BlazorSplitGrid.Elements.Grid.Initialise(ISplitGridInterop splitGridInterop)
   at BlazorSplitGrid.SplitGrid.Initialise()
   at BlazorSplitGrid.SplitGrid.OnAfterRenderAsync(Boolean firstRender)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Based on a bit of fiddling, I realised that split-grid.min.js containing the above Split method wasn't being correctly imported. This required an additional line to be inserted into the Host.cshtml file to fix the issue.

<script src="_content/BlazorSplitGrid/splitGrid/split-grid.min.js"></script>

May be worth noting in the readme that you may need to do this if using BlazorSplitGrid within an existing application.

Update: I've isolated the issue - it seems that the issue occurs when used in conjunction with the BlazorMonaco library which has it's own requirements to add script imports into the Host.cshtml!

Korthax commented 9 months ago

Thanks for raising this. I've followed your suggestion and updated the README.md to mention referencing the split-grid.js in your HTML file.