microsoft / microsoft/monaco-editor

[Bug] Changing content of a hidden editor and showing it again leaves the editor in a broken state

Open
#5,185 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.55.1#XQAAAAIgAgAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw0YIcwueg53JDuXmAka3eBDre1NaYeMhYILDPrX81Adbu3V-MMXb66toTN4KD8g2OWhiftOLosRgc82OMn0qZ2jWXpoL5FvRew-ijLT9WTRKGadJm1hez2G1j_G7szdKv7qJ8ScH77SAcA9J8IEZfGjlWp96yeP2EK7yd4ONxVcFLdHK8pZ6T59ryq2AmXSGQnTpgTeLCsONE_fhC9yk6GhdoadyDJd7pnoEO__YBgATI2h96BDNMrPtLVy0ElkmpZuz01Jne2Vn4-nxs_9xGEKokNhunsVhHlx3BVg1diRVaBoJQ_-wOCmXyR-0PQcDvjn7tcZ7QfJR6INiTLVlHsagO2fHbY1oIJP5eGMY

Monaco Editor Playground Code
var editor = monaco.editor.create(document.getElementById("container"), {
	value: "// First line\nfunction hello() {\n\talert('Hello world!');\n}\n// Last line",
	language: "javascript",
});
setTimeout(function () {
	editor.getDomNode().classList.add('hidden');
	editor.setValue("function hello() {\n\talert('Hello world!');\n}\n");
}, 2000);
setTimeout(function () {
	editor.getDomNode().classList.remove('hidden');
	editor.render(true);
}, 4000);
Reproduction Steps

Run the code in the playground using Firefox or Safari.

After 2s it will hide the editor, change its content, and after another 2s it will show the editor again.

Actual (Problematic) Behavior

After the editor is shown again, it is left in a broken state, even despite the editor.render(true) call. It is impossible to place cursor or select text within a line using the mouse. Clicking on a line will always place the cursor at the end of the line.

Expected Behavior

The editor is expected to function normally in this case.

Additional Context

The issue cannot be reproduced using Chrome.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Monaco Editor Playground reproduction and compare behavior in Firefox or Safari after the editor is hidden, updated with setValue, shown, and refreshed with render(true). Trace the editor's mouse positioning and rendering behavior across that sequence; done means the restored editor allows the cursor and text selection to work normally, while Chrome behavior remains unaffected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.