Editor: "InstantiationService has been disposed" from deferred SuggestWidget creation when multiple editors are created/disposed on one page (global hoverDelegateFactory singleton)
Maintainers usually reply within 1 day
@hediet is already working on this.
Since Oct 9, 2026.
Assessment
This issue has not been assessed yet.
Description
Summary
In an Electron desktop app that creates and disposes several Monaco editors on one page (read-only diff editors + file viewers), we captured an uncaught renderer error:
Error: InstantiationService has been disposed
thrown while SuggestWidget was being constructed — not for a user action, but from a deferred WindowIdleValue executor that ran after the editor had already been disposed.
The underlying defect is that hoverDelegateFactory is a module-global mutable singleton (with Lazy caches), and every StandaloneCodeEditor constructor overwrites it with a closure bound to that editor's own InstantiationService. When the last-created editor is disposed, the global factory keeps pointing at the disposed service, and any later widget construction that goes through createInstantHoverDelegate() throws. This is the same root cause described in microsoft/vscode#279709, manifesting here through the suggest-widget path (microsoft/monaco-editor#4612 captured the same error via the context-menu path).
Environment
- monaco-editor 0.56.0 (npm, standalone editors via
monaco.editor.createandmonaco.editor.createDiffEditor) - Electron 43 / Chromium 150, macOS arm64 (also plausible in any browser host)
- Multiple editors per page, created and disposed as the user navigates
- The error is uncaught because it is thrown inside a
requestIdleCallbackcallback
Stack trace (from production, only Monaco frames)
Error: InstantiationService has been disposed
at InstantiationService._throwIfDisposed instantiationService.js:52:19
at InstantiationService.createInstance instantiationService.js:93:14
at <anonymous> (global hoverDelegateFactory closure) standaloneCodeEditor.js:81:89
at createInstantHoverDelegate hoverDelegateFactory.js:31:12
at new ActionBar actionbar.js:40:71
at new SuggestWidgetStatus suggestWidgetStatus.js:37:29
at new SuggestWidget suggestWidget.js:214:45
at InstantiationService.createInstance instantiationService.js:102:27
at SuggestController constructor (inside WindowIdleValue executor) suggestController.js:131:55
-- async boundary: scheduled by WindowIdleValue/runWhenIdle (requestIdleCallback) async.js:636
How it happened (sequence from production logs)
- Several Monaco editors existed on the page; each creation ran
setHoverDelegateFactory(...)inStandaloneCodeEditor's constructor (line 81 in 0.56.0), so the global factory ended up bound to the last-created editor'sInstantiationService. - The user interacted with a (read-only) editor for the first time.
SuggestControlleris registered withEditorContributionInstantiation.BeforeFirstInteraction, so it was constructed at that moment. Its constructor defersSuggestWidgetcreation:this.widget = this._toDispose.add(new WindowIdleValue(getWindow(editor.getDomNode()), () => { const widget = this._instantiationService.createInstance(SuggestWidget, this.editor); ... })); - The renderer's main thread stayed busy (a background task streamed updates ~4×/second and re-rendered a large DOM), so the idle callback did not fire.
- The user navigated; React unmounted the view and
editor.dispose()ran. Editor creation/disposal had also swapped which editor owns the global factory; the owning service was disposed. - The renderer finally went idle → the pending idle callback fired →
new ActionBar→createInstantHoverDelegate()→ the stale global closure →createInstanceon a disposedInstantiationService→ uncaught throw.
Note the two compounding problems:
- A: the global
hoverDelegateFactorysingleton is bound to one specific editor'sInstantiationServiceand silently goes stale when that editor is disposed (never reset tonullHoverDelegateFactory). Every other still-alive editor inherits the stale factory. - B: deferred widget construction (
WindowIdleValueinSuggestController) executescreateInstancewithout any guard for "editor/service already disposed in the meantime". Once the idle callback is dequeued,cancelIdleCallbackcan no longer prevent it, so contribution disposal does not reliably stop it.
Minimal repro sketch
const a = monaco.editor.create(elA, { value: 'const x = 1;', language: 'javascript' });
// Creating a second editor overwrites the global hoverDelegateFactory with B's InstantiationService:
const b = monaco.editor.createDiffEditor(elB, { originalEditable: false, readOnly: true });
// First interaction with `a` creates SuggestController (BeforeFirstInteraction)
// and schedules SuggestWidget construction on requestIdleCallback. Keep the main
// thread busy (or dispose quickly) so the idle callback is still pending, then:
b.dispose(); // global factory now points at B's disposed InstantiationService
// When the idle callback fires: SuggestWidget -> SuggestWidgetStatus -> ActionBar
// -> createInstantHoverDelegate() -> stale factory -> Error: InstantiationService has been disposed
Timing-sensitive by nature (requires the idle callback to fire after the dispose), which is why it surfaces rarely and non-deterministically.
Related issues
- microsoft/vscode#279709 — root-cause analysis of the global
hoverDelegateFactorysingleton being overwritten bycreateDiffEditor/createEditor(samestandaloneCodeEditor.jsframe,FindWidgetpath) - microsoft/monaco-editor#4612 — same error message in Monaco via
ContextMenuController→ActionBar→createInstantHoverDelegate - microsoft/vscode#229026 — same class of error via
ActionBar→createActionViewItemafter dispose
Suggested fixes
- Remove the module-global factory — resolve the hover delegate per-editor (e.g., pass/look up the requesting editor's
InstantiationServiceinstead of a singleton closure). This fixes every consumer (ActionBar,FindInput, context menu, suggest widget) at once. - Alternatively, register the factory's lifecycle with the owning editor so that disposing it resets the global to
nullHoverDelegateFactory(fail fast instead of throwing from a stale closure). - Additionally/defensively: make deferred
WindowIdleValueexecutors in editor contributions dispose-safe — checkeditor.hasBeenDisposed/service state before constructing the widget, so late idle callbacks become no-ops instead of uncaught errors.
Option 1 is the real fix; option 3 additionally hardens all lazily-constructed contributions against the same timing window.
- Dominant language
- JavaScript
- Stars
- 47k
- Forks
- 4.2k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 13
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/monaco-editor
-
Difficulty 1/5 1-3 hours Newbie friendliness 65/100
microsoft/monaco-editor#5626 ·
Maintainers usually reply within 1 day
-
[Bug] package.json `"typings"` points to a file which does not exist in the npm packagePossibly taken @whoalin1 claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/monaco-editor#5615 ·
Maintainers usually reply within 1 day
-
[Bug] C# scientific-notation literals without a decimal point are split into identifiersPossibly taken @Janani-bn claimed this 15 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
microsoft/monaco-editor#5583 ·
Maintainers usually reply within 1 day
-
[Bug] Rust scientific-notation literals without an exponent sign are split into identifiersPossibly taken @Janani-bn claimed this 14 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
microsoft/monaco-editor#5582 ·
Maintainers usually reply within 1 day
-
[Bug] Go numeric literals with underscore separators are split into identifiersMay be free again @aaronanish-t claimed this 25 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
microsoft/monaco-editor#5577 · 1 comment ·
Maintainers usually reply within 1 day
All issues in microsoft/monaco-editor
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
quasarframework/quasar#18614 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug/1-unconfirmed kind/bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
521xueweihan/HelloGitHub#4714 ·
-
01 type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day