Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Core/Components/DataGrid/FluentDataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ public partial class FluentDataGrid<TGridItem> : FluentComponentBase, IHandleEve

private GridItemsProvider<TGridItem>? _lastAssignedItemsProvider;
private CancellationTokenSource? _pendingDataLoadCancellationTokenSource;
private bool _isFirstVirtualizeProviderCall = true;

Comment on lines 429 to 433

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_isFirstVirtualizeProviderCall is never reset when the data source or virtualization mode changes. If ItemsProvider/Items is replaced or Virtualize is toggled off/on, the first provider call after that change will be debounced even though it’s effectively a new initial load. Consider resetting this flag when dataSourceHasChanged is true and/or when _lastVirtualizationMode changes to true.

Copilot uses AI. Check for mistakes.
private Exception? _lastError;
private GridItemsProviderRequest<TGridItem>? _lastRequest;
Expand Down Expand Up @@ -889,9 +890,15 @@ private async Task RefreshDataCoreAsync()
_lastRefreshedPaginationState = Pagination;

// Debounce the requests. This eliminates a lot of redundant queries at the cost of slight lag after interactions.
// TODO: Consider making this configurable, or smarter (e.g., doesn't delay on first call in a batch, then the amount
// of delay increases if you rapidly issue repeated requests, such as when scrolling a long way)
await Task.Delay(100);
// Skip the delay on the first call to avoid unnecessary lag on initial load.
if (_isFirstVirtualizeProviderCall)
{
_isFirstVirtualizeProviderCall = false;
}
Comment on lines 892 to +897

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_isFirstVirtualizeProviderCall is flipped to false before checking request.CancellationToken. If the first provider call gets cancelled (common during refresh/rapid parameter changes), the next call will be delayed even though no items were ever delivered, reintroducing the initial-load lag. Consider only clearing the flag after passing the cancellation check (or after returning a non-default result), or resetting it when the first call is cancelled.

Copilot uses AI. Check for mistakes.
else
{
await Task.Delay(100);

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debounce Task.Delay(100) doesn’t observe request.CancellationToken, so cancelled virtualization requests still wait the full 100ms before returning. Use a cancellable delay (and handle OperationCanceledException) so cancelled requests complete promptly and don’t contribute to perceived lag under rapid scrolling/refresh.

Suggested change
await Task.Delay(100);
try
{
await Task.Delay(100, request.CancellationToken);
}
catch (System.OperationCanceledException)
{
return default;
}

Copilot uses AI. Check for mistakes.
}

if (request.CancellationToken.IsCancellationRequested)
{
Expand Down
32 changes: 20 additions & 12 deletions src/Core/Components/MessageBar/Services/MessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public virtual IEnumerable<Message> AllMessages
MessageLock.EnterReadLock();
try
{
return MessageList;
return MessageList.ToList();
}
finally
{
Expand All @@ -66,11 +66,19 @@ public virtual IEnumerable<Message> MessagesToShow(int count = 5, string? sectio
MessageLock.EnterReadLock();
try
{
var messages = string.IsNullOrEmpty(section)
? MessageList
: MessageList.Where(x => x.Section == section);
IEnumerable<Message> messages = MessageList;

return count > 0 ? messages.Take(count) : messages;
if (!string.IsNullOrEmpty(section))
{
messages = messages.Where(x => x.Section == section);
}

if (count > 0)
{
messages = messages.Take(count);
}

return messages.ToList();
}
finally
{
Expand Down Expand Up @@ -128,7 +136,7 @@ public Message ShowMessageBar(string title, MessageIntent intent, string section
/// <summary>
/// Show a message based on the provided parameters in a message bar.
/// </summary>
/// <param name="title"> Main info.
/// <param name="title"> Main info.
/// Using MarkupString can introduce XSS vulnerabilities because it renders unencoded HTML.
/// Only use it with fully trusted, sanitized content.</param>
/// <param name="intent">Intent of the message</param>
Expand Down Expand Up @@ -223,7 +231,7 @@ public async Task<Message> ShowMessageBarAsync(string title, MessageIntent inten
/// <summary>
/// Show a message based on the provided parameters in a message bar.
/// </summary>
/// <param name="title"> Main info.
/// <param name="title"> Main info.
/// Using MarkupString can introduce XSS vulnerabilities because it renders unencoded HTML.
/// Only use it with fully trusted, sanitized content.</param>
/// <param name="intent">Intent of the message</param>
Expand Down Expand Up @@ -263,7 +271,10 @@ public virtual async Task<Message> ShowMessageBarAsync(Action<MessageOptions> op
MessageLock.ExitWriteLock();
}

await OnMessageItemsUpdatedAsync!.Invoke();
if (OnMessageItemsUpdatedAsync is { } handler)
{
await handler.Invoke();
}

return message;
}
Expand Down Expand Up @@ -326,10 +337,7 @@ private void NavigationManager_LocationChanged(object? sender, LocationChangedEv
/// <summary />
public void Dispose()
{
if (_navigationManager != null)
{
_navigationManager.LocationChanged -= NavigationManager_LocationChanged;
}
_navigationManager?.LocationChanged -= NavigationManager_LocationChanged;

RemoveMessageItems(section: null);

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dispose() calls RemoveMessageItems(section: null) without taking MessageLock. Since this class otherwise uses ReaderWriterLockSlim around MessageList, clearing it during disposal without the write lock can race with concurrent reads/writes and reintroduce enumeration/modification exceptions. Consider acquiring the write lock in Dispose() (or calling Clear()/a locking helper) before mutating MessageList.

Suggested change
RemoveMessageItems(section: null);
MessageLock.EnterWriteLock();
try
{
RemoveMessageItems(section: null);
}
finally
{
MessageLock.ExitWriteLock();
}

Copilot uses AI. Check for mistakes.
}
Expand Down
Loading