Azure / Azure/monaco-kusto

Facing model disposed run time error from _assertDisposed() and isDisposed is always being shown as false even after disposing when upgraded to latest version

Open
#492 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
84
Forks
36
PR merge metrics
No merged PRs in 30d

Description

```
const setSchema = useCallback(() => {
const model = monacoEditorRef.current?.getModel();
if (model?.isDisposed()) { return; }
try {
//eslint-disable-next-line @typescript-eslint/no-explicit-any
window.monaco.languages.kusto.getKustoWorker().then((workerAccessor: any) => {
//eslint-disable-next-line @typescript-eslint/no-explicit-any
workerAccessor(model?.uri).then((worker: any) => {
if (model?.isDisposed()) { return; }
worker.setSchemaFromShowSchema(
props.schema,
props.kustoUrl,
props.kustoDb
);
})
})
} catch (error) {
console.error("Error while interacting with the model:", error);
}

//eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.schema, props.kustoUrl, props.kustoDb]);

const loadKustoEditor = useCallback((query?: string) => {
//eslint-disable-next-line @typescript-eslint/no-explicit-any
init().then((monacoInstance: any) => {
const wrapper = document.getElementById('monaco-root');
const properties = {
value: query ? query : ``,
language: 'kusto',
minimap: { enabled: false },
theme: isDark ? "kusto-dark" : "kusto-light",
automaticLayout: true,
'semanticHighlighting.enabled': true
};

//if there is no existing instance then only new instance created
const editor = monacoInstance.editor?.create(wrapper, properties);
monacoEditorRef.current = editor;
setSchema();
//if there was a queryParam in url and not loaded from shared queries that is props.kustoQuery is empty
editorDidMount(editor, !!queryParam && !kustoQuery);
});
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [setSchema, queryParam, kustoQuery, isDark])

useEffect(() => {
if (props.kustoQuery) {
loadKustoEditor(props.kustoQuery)
}
else if (queryParam && !props.kustoQuery) {
//if navigation url has query param
loadKustoEditor(queryParam);
} else {
const defaultTabUpdatedQuery = localStorage.getItem(LOCAL_STORAGE_KEYS.DEFAULT_TAB_UPDATED_QUERY);
if (defaultTabUpdatedQuery && defaultTabUpdatedQuery != undefined) {
loadKustoEditor(JSON.parse(defaultTabUpdatedQuery));
}
else {
loadKustoEditor();

}
}
return () => {
monacoEditorRef.current?.getModel()?.dispose();
}
}, [props.kustoQuery, queryParam, loadKustoEditor]);
```

On dependencies changed I am seeing a run time error on my local.
Even after adding try catch block it is not getting caught.
This is working fine with previous version 10 but after upgrade to 12 version it working fine but getting this run time error when dependencies are getting change frequently.
And observed this is happening with the worker. If I comment worker.setSchemFromShowSChema i am not seeing this error.

![Image](https://github.com/user-attachments/assets/94b96031-25ba-4a8c-a932-c2611177f0bc)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the setSchema and loadKustoEditor entry points shown in the report, then trace the asynchronous getKustoWorker and worker.setSchemaFromShowSchema calls alongside the cleanup that disposes the model. Reproduce rapid dependency changes and verify that worker operations do not trigger disposed-model runtime errors and that disposal state is reported consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.