microsoft / microsoft/monaco-editor

[Bug] Calling setModel in command action or immediately after performing a command action causes "Uncaught (in promise) Canceled: Canceled" exception

Open
#5,135 0 comments 0 reactions 1 assignee View on GitHub

@hediet is already working on this.

Since Dec 9, 2025.

bug diff-editor
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

(Not sure how to reproduce this in VS Code, so assuming it's probably not affected)

Reproducible in the monaco editor playground?
Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.52.0#XQAAAAL4AgAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw2sW0Eu-n-4FNw7EJFXfE5zHCAAPkGl4JHQWBB-9rQk5cWb5_-IQthYi5LCkIpStT1Cwli_WYwzdvtRT8dHAKV8AEOSssMDVZGi-gxT-nJtum2pfG65aTMv6c9Qs1O8j-QjEg5AmMjdAttdYaBPXO9xUPVcXtq5QSPTvjiZai3NVgX0mBh5c9LVd-44C2br4bQqH6Aha3eDoWFTY6XLgm7N6_w5oNHNmr7u--k9DrvIa-pwQo9e2Jpz6dIP54SruJYl2omjWoAU-5GZOJanS_evRiBjxsBh_yiQ7hHB2smYqzbYb-DPSB4jR-Jm8JmQpmIA5hXQmE6CirFn4RgfYlcIljfggZvoq_MOw1fUtSAyDaHGsKGRoRz_lPfwo1199ahzx0HekhvMZbKpPWILZN5AUDhBjyyY4eBWApywHCRv_5VoSJ

Monaco Editor Playground Code
const originalModel = monaco.editor.createModel(
	/* set from `originalModel`: */ `hello world`,
	"text/plain"
);

const modifiedModel = monaco.editor.createModel(
	/* set from `modifiedModel`: */ `Hello World! This is the modified text.`,
	"text/plain"
);

const diffEditor = monaco.editor.createDiffEditor(
	document.getElementById("container"),
	{
		originalEditable: true,
		automaticLayout: true,
	}
);

diffEditor.setModel({
	original: originalModel,
	modified: modifiedModel,
});

diffEditor.addAction({
  id: "swap",
  label: "Swap",
  run: () => { 
    diffEditor.setModel({
      original: modifiedModel,
      modified: originalModel,
    });
  },
  contextMenuGroupId: "swap",
});
Reproduction Steps

In the Monaco Editor playground, run the provided code. In the modified editor, right-click and select Swap. In the JavaScript console, notice the "Uncaught (in promise) Canceled: Canceled" exception.

Actual (Problematic) Behavior

Here's the exception logged in the JavaScript console:

editor.api-CykLys8L.js:2921  Uncaught (in promise) Canceled: Canceled
cancel @ editor.api-CykLys8L.js:2921
dispose @ editor.api-CykLys8L.js:2930
dispose @ editor.api-CykLys8L.js:1386
clear @ editor.api-CykLys8L.js:1457
dispose @ editor.api-CykLys8L.js:1441
dispose @ editor.api-CykLys8L.js:161490
(anonymous) @ editor.api-CykLys8L.js:161516
_deliver @ editor.api-CykLys8L.js:2394
_deliverQueue @ editor.api-CykLys8L.js:2403
fire @ editor.api-CykLys8L.js:2423
setModel @ editor.api-CykLys8L.js:75061
(anonymous) @ editor.api-CykLys8L.js:96516
batchEventsGlobally @ editor.api-CykLys8L.js:8257
(anonymous) @ editor.api-CykLys8L.js:96514
transaction @ editor.api-CykLys8L.js:7046
subtransaction @ editor.api-CykLys8L.js:7076
setDiffModel @ editor.api-CykLys8L.js:96512
setModel @ editor.api-CykLys8L.js:96504
run @ VM847:27
run @ editor.api-CykLys8L.js:183055
invokeFunction @ editor.api-CykLys8L.js:181406
executeCommand @ editor.api-CykLys8L.js:182212
run @ editor.api-CykLys8L.js:14010
runAction @ editor.api-CykLys8L.js:10801
run @ editor.api-CykLys8L.js:10794
onClick @ editor.api-CykLys8L.js:86328
(anonymous) @ editor.api-CykLys8L.js:174428
setTimeout
(anonymous) @ editor.api-CykLys8L.js:174427

Expected Behavior

No response

Additional Context

Our use case was to swap the original and modified models. I'm also able to reproduce the issue just updating either the original or modified model. I was able to reproduce the issue starting on version 0.52.0.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.