fluentui-blazor icon indicating copy to clipboard operation
fluentui-blazor copied to clipboard

fix: Error in FluentDataGrid

Open JamesNK opened this issue 5 months ago • 0 comments

🐛 Bug Report

Quickly navigating to and from a page with a large grid eventually causes this error:

2024-03-01T22:53:23.8215924 warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: Cannot create a JSObjectReference from the value 'undefined'.
Error: Cannot create a JSObjectReference from the value 'undefined'.
    at f (http://localhost:15888/_framework/blazor.web.js:1:1273)
    at I (http://localhost:15888/_framework/blazor.web.js:1:6878)
    at http://localhost:15888/_framework/blazor.web.js:1:3286
      Microsoft.JSInterop.JSException: Cannot create a JSObjectReference from the value 'undefined'.
Error: Cannot create a JSObjectReference from the value 'undefined'.
    at f (http://localhost:15888/_framework/blazor.web.js:1:1273)
    at I (http://localhost:15888/_framework/blazor.web.js:1:6878)
    at http://localhost:15888/_framework/blazor.web.js:1:3286
         at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
         at Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.OnAfterRenderAsync(Boolean firstRender) in /_/src/Core/Components/DataGrid/FluentDataGrid.razor.cs:line 252
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

💻 Repro or Code Sample

Quickly navigating to and from a page with a large grid.

🤔 Expected Behavior

No error.

😯 Current Behavior

Error.

💁 Possible Solution

I looked at where the problem code is:

https://github.com/microsoft/fluentui-blazor/blob/4516f9567354f6d721ac9f78c5ec5e055b7868ef/src/Core/Components/DataGrid/FluentDataGrid.razor.cs#L247-L260

I think a null grid reference is the most likely problem.

How multithreaded is Blazor? Could the grid reference be set to null while this code is running? Will need to set the field to a local variable if that's the case.

Or, is the problem the second if statement doesn't check the grid reference is null before using it?

🔦 Context

🌍 Your Environment

  • OS & Device: [e.g. MacOS, iOS, Windows, Linux] on [iPhone 7, PC]
  • Browser [e.g. Microsoft Edge, Google Chrome, Apple Safari, Mozilla FireFox]
  • .NET and Fluent UI Blazor library Version [e.g. 8.0.2 and 4.4.1]

JamesNK avatar Mar 01 '24 14:03 JamesNK