DataGrid.RowCreated renders before save has completed

Based on the DataGrid Inline Edit example, I am saving the InsertedRow item when the RowCreated event is raised. Saving will set the id property of the item, but the grid keeps showing the id as 0. It seems the grid rendering only occurs before the item is updated even though the DataGrid source code says it should render at the end.

protected override void OnAfterRender(bool firstRender)
{
	Console.WriteLine($"OnAfterRender");
}

async void OnCreateRow(Row item)
{
	Console.WriteLine($"OnCreateRow BeforeSave Id = {item.Id}");
	await SaveAsync(item);
	Console.WriteLine($"OnCreateRow AfterSave Id = {item.Id}");
}

Console output:
OnCreateRow BeforeSave Id = 0
OnAfterRender
OnCreateRow AfterSave Id = 54

If I call StateHasChanged myself at the end of OnCreateRow the grid shows the updated id, but I find it strange that I would have to do that? (v 3.9.8)

You need to update whatever the Data property of the DataGrid is set to to contain the newer value of the item. The DataGrid always renders the contents of its Data property (after applying data operations to it - paging, sorting, filtering etc.).

The item belongs to the DataGrid.Data and the item.Id is updated in the OnCreateRow method (above), but no OnAfterRender happens after the OnCreateRow has finished. Only if StateHasChanged is explicitly called at the end of OnCreateRow does the grid show the updated value.

Isn't that strange, or am I missing something?

Looking at the DataGrid source code it certainly looks like StateHasChanged is called after raising the RowCreate event.

I am not sure what is happening. You can still debug the source code and see if the Data is updated when the DataGrid is rendering after StateHasChanged is called. By the way calling StateHasChanged of the page is not the same as StateHasChanged of the DataGrid.