Skip to content

Commit 64d0d50

Browse files
authored
Rollup PRs #4677 and and #4678 (#4680)
* Implement #4677 (Fix #4674) in correct branch * Implement #4678 (Fix #4676) in correct branch
1 parent 0625bb0 commit 64d0d50

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/Core/Components/DataGrid/FluentDataGrid.razor.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ public partial class FluentDataGrid<TGridItem> : FluentComponentBase, IHandleEve
429429

430430
private GridItemsProvider<TGridItem>? _lastAssignedItemsProvider;
431431
private CancellationTokenSource? _pendingDataLoadCancellationTokenSource;
432+
private bool _isFirstVirtualizeProviderCall = true;
432433

433434
private Exception? _lastError;
434435
private GridItemsProviderRequest<TGridItem>? _lastRequest;
@@ -889,9 +890,15 @@ private async Task RefreshDataCoreAsync()
889890
_lastRefreshedPaginationState = Pagination;
890891

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

896903
if (request.CancellationToken.IsCancellationRequested)
897904
{

src/Core/Components/MessageBar/Services/MessageService.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public virtual IEnumerable<Message> AllMessages
4646
MessageLock.EnterReadLock();
4747
try
4848
{
49-
return MessageList;
49+
return MessageList.ToList();
5050
}
5151
finally
5252
{
@@ -66,11 +66,19 @@ public virtual IEnumerable<Message> MessagesToShow(int count = 5, string? sectio
6666
MessageLock.EnterReadLock();
6767
try
6868
{
69-
var messages = string.IsNullOrEmpty(section)
70-
? MessageList
71-
: MessageList.Where(x => x.Section == section);
69+
IEnumerable<Message> messages = MessageList;
7270

73-
return count > 0 ? messages.Take(count) : messages;
71+
if (!string.IsNullOrEmpty(section))
72+
{
73+
messages = messages.Where(x => x.Section == section);
74+
}
75+
76+
if (count > 0)
77+
{
78+
messages = messages.Take(count);
79+
}
80+
81+
return messages.ToList();
7482
}
7583
finally
7684
{
@@ -128,7 +136,7 @@ public Message ShowMessageBar(string title, MessageIntent intent, string section
128136
/// <summary>
129137
/// Show a message based on the provided parameters in a message bar.
130138
/// </summary>
131-
/// <param name="title"> Main info.
139+
/// <param name="title"> Main info.
132140
/// Using MarkupString can introduce XSS vulnerabilities because it renders unencoded HTML.
133141
/// Only use it with fully trusted, sanitized content.</param>
134142
/// <param name="intent">Intent of the message</param>
@@ -223,7 +231,7 @@ public async Task<Message> ShowMessageBarAsync(string title, MessageIntent inten
223231
/// <summary>
224232
/// Show a message based on the provided parameters in a message bar.
225233
/// </summary>
226-
/// <param name="title"> Main info.
234+
/// <param name="title"> Main info.
227235
/// Using MarkupString can introduce XSS vulnerabilities because it renders unencoded HTML.
228236
/// Only use it with fully trusted, sanitized content.</param>
229237
/// <param name="intent">Intent of the message</param>
@@ -263,7 +271,10 @@ public virtual async Task<Message> ShowMessageBarAsync(Action<MessageOptions> op
263271
MessageLock.ExitWriteLock();
264272
}
265273

266-
await OnMessageItemsUpdatedAsync!.Invoke();
274+
if (OnMessageItemsUpdatedAsync is { } handler)
275+
{
276+
await handler.Invoke();
277+
}
267278

268279
return message;
269280
}
@@ -326,10 +337,7 @@ private void NavigationManager_LocationChanged(object? sender, LocationChangedEv
326337
/// <summary />
327338
public void Dispose()
328339
{
329-
if (_navigationManager != null)
330-
{
331-
_navigationManager.LocationChanged -= NavigationManager_LocationChanged;
332-
}
340+
_navigationManager?.LocationChanged -= NavigationManager_LocationChanged;
333341

334342
RemoveMessageItems(section: null);
335343
}

0 commit comments

Comments
 (0)