Skip to content

fix: configure MonacoEnvironment.getWorkerUrl to prevent worker 404 fallback - #39341

Open
li-lizhe wants to merge 4 commits into
langgenius:mainfrom
li-lizhe:fix/monaco-worker-url
Open

fix: configure MonacoEnvironment.getWorkerUrl to prevent worker 404 fallback#39341
li-lizhe wants to merge 4 commits into
langgenius:mainfrom
li-lizhe:fix/monaco-worker-url

Conversation

@li-lizhe

Copy link
Copy Markdown

Problem

Fixes #39340

Monaco Editor's Web Worker always fails to load because MonacoEnvironment.getWorkerUrl is not configured. Without it, Monaco appends the worker label as a URL fragment (workerMain.js#editorWorkerService), which browsers encode to %23, causing a 404. The worker falls back to the main thread every time.

Solution

Add self.MonacoEnvironment.getWorkerUrl configuration that returns the worker URL without the #label fragment. The worker name is preserved via the name parameter of new Worker().

Changes

File: web/app/components/workflow/nodes/_base/components/editor/code-editor/index.tsx

Before:

if (typeof window !== 'undefined')
  loader.config({ paths: { vs: `${window.location.origin}${basePath}/vs` } })

After:

if (typeof window !== 'undefined') {
  loader.config({ paths: { vs: `${window.location.origin}${basePath}/vs` } })

  // Configure worker URL to prevent the worker label from being appended as a URL fragment.
  // Without this, Monaco generates URLs like workerMain.js#editorWorkerService, which browsers
  // encode to %23, causing a 404 and forcing the worker to fall back to the main thread.
  self.MonacoEnvironment = {
    getWorkerUrl: () => `${window.location.origin}${basePath}/vs/base/worker/workerMain.js`,
  }
}

Testing

  • Verified workerMain.js loads successfully (304, 2ms) without %23 encoding
  • Verified worker types: editorWorkerService and json both affected
  • No breaking changes - getWorkerUrl is the standard Monaco Editor configuration

Impact

  • Eliminates unnecessary 404 responses (~350KB each, 100-700ms latency)
  • Worker runs in a dedicated thread instead of main thread
  • Reduces server load from SSR-rendered 404 pages

…allback

Without MonacoEnvironment.getWorkerUrl, Monaco Editor appends the worker label
as a URL fragment (workerMain.js#editorWorkerService). Browsers encode # to
%23, causing a 404. The worker falls back to the main thread every time the
workflow editor is opened.

This fix returns the worker URL without the #label fragment. The worker name
is preserved via the name parameter of new Worker().
@li-lizhe
li-lizhe requested review from iamjoel and zxhlyh as code owners July 21, 2026 04:20
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 21, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Jul 21, 2026
li-lizhe added 3 commits July 21, 2026 14:59
TypeScript complains that 'MonacoEnvironment' does not exist on
'Window & typeof globalThis'. Use type assertion to bypass it.
Replace (self as any) type assertion with window.MonacoEnvironment,
backed by the type declaration added to global.d.ts.
@li-lizhe

Copy link
Copy Markdown
Author

@iamjoel @zxhlyh Could you please review this PR when you have time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monaco Editor Web Worker always fails with 404 due to missing MonacoEnvironment.getWorkerUrl configuration

1 participant