Skip to content
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

fix: Error in FluentDataGrid #1616

Closed
JamesNK opened this issue Mar 1, 2024 · 0 comments · Fixed by #1637
Closed

fix: Error in FluentDataGrid #1616

JamesNK opened this issue Mar 1, 2024 · 0 comments · Fixed by #1637

Comments

@JamesNK
Copy link
Member

JamesNK commented Mar 1, 2024

🐛 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:

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && _gridReference is not null)
{
Module ??= await JSRuntime.InvokeAsync<IJSObjectReference>("import", JAVASCRIPT_FILE);
_jsEventDisposable = await Module.InvokeAsync<IJSObjectReference>("init", _gridReference);
}
if (_checkColumnOptionsPosition && _displayOptionsForColumn is not null)
{
_checkColumnOptionsPosition = false;
_ = Module?.InvokeVoidAsync("checkColumnOptionsPosition", _gridReference).AsTask();
}
}

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 JamesNK changed the title fix: [what is the issue?] in [where is the issue?] fix: Error in FluentGrid Mar 1, 2024
@vnbaaij vnbaaij changed the title fix: Error in FluentGrid fix: Error in FluentDataGrid Mar 2, 2024
vnbaaij added a commit that referenced this issue Mar 5, 2024
- Add try..catch for 'undefined' error. Fix #1616
@vnbaaij vnbaaij linked a pull request Mar 5, 2024 that will close this issue
vnbaaij added a commit that referenced this issue Mar 5, 2024
- Add try..catch for 'undefined' error. Fix #1616
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

Successfully merging a pull request may close this issue.

1 participant