Skip to content

fix(monaco): stop reporting worker load errors after an editor closes - #335

Merged
MrYuion merged 1 commit into
developfrom
t3/fix-backoffice-4q-monaco-worker
Nov 1, 2026
Merged

MrYuion merged 1 commit into
developfrom
t3/fix-backoffice-4q-monaco-worker

Conversation

@MrYuion

@MrYuion MrYuion commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Sentry BACKOFFICE-4Q: users who open a system and then quickly open another system get an unhandled NetworkError: Failed to execute 'importScripts' for editor.worker-DM0G1eFj.js.

The worker URL is correct, and this is not a stale deploy. Monaco 0.54.0 has shipped the same worker file since April. The cause is a race on route change. Monaco stops its editor worker when the last model closes, and the settings field closes its model when the page changes. If the worker script is still downloading (in the Sentry event the user was on a mobile network), Chrome raises the failed importScripts on the window. Monaco has already removed its own listener, so Angular's global error listener sent the error to Sentry. In the Sentry event, the error arrived 21 ms after the user clicked the next system.

The fix: after editor.main loads, loadMonaco() wraps MonacoEnvironment.getWorker. Each worker records when terminate() is called and cancels its error events after that, so they no longer reach the window. Errors from workers that still run are not changed.

Proof: I ran a production build at /backoffice/ with the mock backend and delayed editor.worker by 3 s. Before the fix, the window got the same error as Sentry about 20 ms after the second route change. After the fix, the log showed the worker created, the route changed, the worker terminated 21 ms later, and the worker error cancelled, with no window error. The worker still computed diffs afterwards. I added a unit test for the stopped and running cases. bun run lint and bun run test:ci pass (992 tests).

Reviewed with sol-loop: 1 round with gpt-6.1-sol. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code (T3 Code).

🤖 Generated with Claude Code

Monaco stops its editor worker when the last model closes, for example
when the user opens a different system. If the worker script is still
loading, Chrome raises a failed importScripts NetworkError on the
window. Monaco removed its own listener first, so Angular sent the
error to Sentry as unhandled.

Wrap MonacoEnvironment.getWorker so each worker cancels its error
events after terminate(). Errors from workers that still run are not
changed.

Fixes BACKOFFICE-4Q

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
backoffice Ready Ready Preview Nov 1, 2026 10:16pm UTC

@MrYuion
MrYuion merged commit 9ee398c into develop Nov 1, 2026
6 of 7 checks passed
@MrYuion
MrYuion deleted the t3/fix-backoffice-4q-monaco-worker branch November 1, 2026 23:50

This branch was successfully deployed

1 active deployment
Preview — e601af78 Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant