Retire pending Monaco creation before editor registration
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(function () {
|
||||
const VS_BASE = "/_content/ZB.MOM.WW.OtOpcUa.AdminUI/lib/monaco/vs";
|
||||
const editors = {};
|
||||
const pendingEditors = new Map();
|
||||
let readyPromise = null;
|
||||
|
||||
function ensureLoaded() {
|
||||
@@ -227,8 +228,19 @@
|
||||
}
|
||||
|
||||
async function createEditor(id, host, options, dotNetRef) {
|
||||
await ensureLoaded();
|
||||
if (!host) return;
|
||||
if (!host || !host.isConnected) return;
|
||||
const creation = {};
|
||||
pendingEditors.set(id, creation);
|
||||
try { await ensureLoaded(); }
|
||||
catch (error) {
|
||||
if (pendingEditors.get(id) === creation) pendingEditors.delete(id);
|
||||
throw error;
|
||||
}
|
||||
// Disposal can retire an attempt while AMD loading is pending. A disconnected host
|
||||
// is likewise retired even if its managed cleanup has not reached JavaScript yet.
|
||||
if (pendingEditors.get(id) !== creation) return;
|
||||
pendingEditors.delete(id);
|
||||
if (!host.isConnected) return;
|
||||
const editor = monaco.editor.create(host, {
|
||||
value: options.value || "", language: options.language || "csharp",
|
||||
ariaLabel: typeof options.ariaLabel === "string" && options.ariaLabel.trim() ? options.ariaLabel : "Code editor",
|
||||
@@ -311,6 +323,7 @@
|
||||
}
|
||||
function setMarkers(id, m) { const e = editors[id]; const model = e && e.editor.getModel(); if (model) monaco.editor.setModelMarkers(model, "otopcua", m || []); }
|
||||
function dispose(id) {
|
||||
pendingEditors.delete(id);
|
||||
const e = editors[id]; if (!e) return;
|
||||
if (e.diagTimer) clearTimeout(e.diagTimer);
|
||||
if (e.diagAbort) e.diagAbort.abort();
|
||||
|
||||
Reference in New Issue
Block a user