microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
39.76k stars 3.55k forks source link

[Bug] Updating extra lib not working after dispose in 0.39.0 version. It is working fine till version 0.28.0 #4023

Open DharmendraSendhav opened 1 year ago

DharmendraSendhav commented 1 year ago

Reproducible in vscode.dev or in VS Code Desktop?

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

Dynamically adding extra lib is not working on 0.39.0 version. It was working fine till 0.28.0 version.

Below are the play ground link of 0.39.0 and 0.28.0

After playground editors are loaded, please follow the below steps to reproduce the issue: step1 - Click on Second_injection button. step2 - Click on Third_injection button. step3 - Click on First_injection button.

After step3, editor should not show the error for test.descriptionfirst property, because we injected the first library again on button click. But it is still showing the error in 0.39.0 version. Same workflow working fine in 0.28.0 version.

Playground_V_0.39.0

Playground_V_0.28.0

Monaco Editor Playground Code

const value = /* set from `myEditor.getModel()`: */ `function hello() {
    alert('Hello world!');
}

var test:Test;
test.descriptionfirst;`;

// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
    value,
    language: "typescript",
    automaticLayout: true,
});

var library = "declare class Test { descriptionfirst:string; } ";
 let testDisposable1 = monaco.languages.typescript.typescriptDefaults.addExtraLib(library, monaco.Uri.file("test.d.ts").toString());
let testDisposable2 = monaco.languages.typescript.javascriptDefaults.addExtraLib(library, monaco.Uri.file("test.d.ts").toString());

var firstInjectTest = function firstInjectTest() { 

    testDisposable1.dispose();
     testDisposable2.dispose();
    let library  = "declare class Test { descriptionfirst:string; } ";

    testDisposable1 = monaco.languages.typescript.typescriptDefaults.addExtraLib(library, monaco.Uri.file("test.d.ts").toString());
    testDisposable2 = monaco.languages.typescript.javascriptDefaults.addExtraLib(library, monaco.Uri.file("test.d.ts").toString());
   alert('First library Injection\n LibraryClass: '+library);
}

window['firstInjectTest'] = firstInjectTest;

var secondInjectTest = function secondInjectTest() { 

    testDisposable1.dispose();
     testDisposable2.dispose();
    let library  = "declare class Test { descriptionsecond:string;  } ";

    testDisposable1 = monaco.languages.typescript.typescriptDefaults.addExtraLib(library, monaco.Uri.file("test.d.ts").toString());
    testDisposable2 = monaco.languages.typescript.javascriptDefaults.addExtraLib(library, monaco.Uri.file("test.d.ts").toString());
   alert('Second library Injection \n LibraryClass: '+library);
}

window['secondInjectTest'] = secondInjectTest;

var thirdInjectTest = function thirdInjectTest() { 

    testDisposable1.dispose();
     testDisposable2.dispose();
    let library  = "declare class Test { descriptionthird:string; } ";

    testDisposable1 = monaco.languages.typescript.typescriptDefaults.addExtraLib(library, monaco.Uri.file("test.d.ts").toString());
    testDisposable2 = monaco.languages.typescript.javascriptDefaults.addExtraLib(library, monaco.Uri.file("test.d.ts").toString());
   alert('Third library Injection \n LibraryClass: '+library);
}

window['thirdInjectTest'] = thirdInjectTest;

// HTML CODE 
 <br><br>
 <input type = "button" value="First_Injection" onclick = "firstInjectTest();" />
 <br><br>
 <input type = "button" value="Second_Injection" onclick = "secondInjectTest();" />
 <br><br>
 <input type = "button" value="Third_Injection" onclick = "thirdInjectTest();" />
<div id="container" style="height: 100%"></div>

Reproduction Steps

After playground editors are loaded, please follow the below steps to reproduce the issue: step1 - Click on Second_injection button. step2 - Click on Third_injection button. step3 - Click on First_injection button.

After step3, editor should not show the error for test.descriptionfirst property, because we injected the first library again on First_injection button click. But it is still showing the error in 0.39.0 version. Same workflow working fine in 0.28.0 version.

Actual (Problematic) Behavior

If we dynamically dispose the library and add again with changes, first time it work fine but from the second time it is not working in 0.39.0 version but and I check in earlier version the same workflow was working till 0.28.0 version. I have mentioned steps to reproduce the issue in Reproduction Steps.

Playground_V_0.39.0

Playground_V_0.28.0

Expected Behavior

It should dynamically dispose the previous library and add changed library and also should show the intelligence for change library even if we repeat the steps multiple times.

After step3, editor should not show the error for test.descriptionfirst property, because we injected the first library again on First_injection button click. But it is still showing the error in 0.39.0 version. Same workflow working fine in 0.28.0 version.

Additional Context

No response

hediet commented 1 year ago

Can verify that it works in 0.28.1 but breaks in 0.29.0.

DharmendraSendhav commented 1 year ago

Yes, in 0.28.1, it is working but in 0.29.0 it is not working.

BTBMan commented 6 months ago

+1, The same problem for me, I found this #1998, but still don't know how to fix it.