Skip to content

Replace monaco editor's useMonaco hook with its loader#1941

Merged
jeesunikim merged 5 commits intomainfrom
fix-monaco-editor
Mar 10, 2026
Merged

Replace monaco editor's useMonaco hook with its loader#1941
jeesunikim merged 5 commits intomainfrom
fix-monaco-editor

Conversation

@jeesunikim
Copy link
Contributor

I kept seeing nextjs error whenever the page has Monaco Editor. Claude found that

the useMonaco() hook from @monaco-editor/react has a bug — its internal loader.init().then(...) call has no .catch(). In React StrictMode (used by Next.js), effects are double-invoked, so the cleanup calls loader.cancel() which rejects the promise with a { type: 'cancelation' } object. This surfaces as an unhandled [object Object] rejection error in Next.js.

This PR fixes nextjs error in dev setup.

Copilot AI review requested due to automatic review settings March 9, 2026 23:42
@github-project-automation github-project-automation bot moved this to Backlog (Not Ready) in DevX Mar 9, 2026
@jeesunikim jeesunikim changed the title Fix monaco editor's Replace monaco editor's useMonaco hook with its loader Mar 9, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Next.js dev unhandled promise rejection triggered by @monaco-editor/react loader cancellation under React StrictMode by replacing useMonaco() usage with a manual loader.init() flow.

Changes:

  • Remove useMonaco() usage and gate rendering on a local isReady state.
  • Initialize Monaco via loader.init() and attach a .catch() to prevent unhandled rejections.
  • Add an optimization to skip async init when Monaco is already loaded.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@stellar-jenkins
Copy link

@jeesunikim jeesunikim requested a review from quietbits March 10, 2026 00:00
jeesunikim and others added 2 commits March 10, 2026 10:25
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@stellar-jenkins
Copy link

1 similar comment
@stellar-jenkins
Copy link

@stellar-jenkins
Copy link

@jeesunikim jeesunikim merged commit 1076b60 into main Mar 10, 2026
7 checks passed
@jeesunikim jeesunikim deleted the fix-monaco-editor branch March 10, 2026 18:47
@github-project-automation github-project-automation bot moved this from Backlog (Not Ready) to Done in DevX Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants