Retire pending Monaco creation before editor registration

This commit is contained in:
Joseph Doherty
2026-11-13 23:36:55 -05:00
parent c6fe9c46e0
commit 50942b4a75
15 changed files with 809 additions and 3 deletions
@@ -71,6 +71,7 @@
private string AccessibleLabel => string.IsNullOrWhiteSpace(AriaLabel) ? "Code editor" : AriaLabel;
private bool _disposed;
private bool _initialized;
private bool _initializing;
private int _tooLargeBytes;
private bool _wrap;
private bool _minimap;
@@ -78,12 +79,14 @@
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (_disposed) return;
if (firstRender)
{
_dotNetRef = DotNetObjectReference.Create(this);
_lastSentValue = Value ?? "";
var createdLabel = AccessibleLabel;
var createdReadOnly = ReadOnly;
_initializing = true;
try
{
await JS.InvokeVoidAsync(
@@ -103,6 +106,7 @@
maxReportedMessageChars = ScriptEditorLimits.MaxReportedMessageChars
},
_dotNetRef);
if (_disposed) return;
_initialized = true;
_lastSentAriaLabel = createdLabel;
_lastSentReadOnly = createdReadOnly;
@@ -121,6 +125,7 @@
// A genuine Monaco init failure — surface it instead of hiding it.
Logger.LogError(ex, "Monaco editor {EditorId} failed to initialize.", _id);
}
finally { _initializing = false; }
}
else if (_initialized && (Value ?? "") != _lastSentValue)
{
@@ -258,10 +263,11 @@
public async ValueTask DisposeAsync()
{
if (_disposed) return;
_disposed = true;
try
{
if (_initialized)
if (_initialized || _initializing)
{
try
{