Skip to content

UI: Load Monaco workers via a same-origin Blob shim (fix dev-mode noise)#67352

Draft
pierrejeambrun wants to merge 2 commits into
apache:mainfrom
astronomer:fix-monaco-worker-foreign-module-dev
Draft

UI: Load Monaco workers via a same-origin Blob shim (fix dev-mode noise)#67352
pierrejeambrun wants to merge 2 commits into
apache:mainfrom
astronomer:fix-monaco-worker-foreign-module-dev

Conversation

@pierrejeambrun
Copy link
Copy Markdown
Member

@pierrejeambrun pierrejeambrun commented May 22, 2026

Stacked on top of #67316 only last commit is relevant

What this fixes

#67342: in dev mode the browser console fills with

```
TypeError: Cannot read properties of undefined (reading 'toUrl')
at FileAccessImpl.toUri (...)
at EditorSimpleWorker.$loadForeignModule (...)
```

every time a Monaco editor mounts (XComs, Audit Log, DAG code, ...).
Production builds are unaffected; this is dev-mode only.

Why

In dev mode the SPA shell is served by the airflow api-server while
Vite serves assets on a different origin. Vite's `?worker` import
generates `new Worker(crossOriginUrl, { type: "module" })` which the
browser refuses for cross-origin module workers — `server.cors` does
not help here, the Worker constructor itself rejects it ('Script at
cannot be accessed from origin '). Monaco then
falls back to 'main-thread workers'; that fallback path executes
`$loadForeignModule` synchronously and resolves module IDs through the
non-existent AMD `require.toUrl`, throwing repeatedly.

Fix

Swap the `?worker` constructor imports for `?url` imports and build
workers from a same-origin Blob shim that simply re-imports the
resolved URL. The Blob URL lives on the page origin so the Worker
constructor accepts it, and the inner cross-origin `import` is allowed
by Vite's CORS response.

Closes #67342

Screen.Recording.2026-05-22.at.19.27.11.mov

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.7)

Generated-by: Claude Code (Opus 4.7) following the guidelines

@boring-cyborg boring-cyborg Bot added the area:UI Related to UI/UX. For Frontend Developers. label May 22, 2026
@pierrejeambrun
Copy link
Copy Markdown
Member Author

Merge #67316 first

@pierrejeambrun pierrejeambrun added this to the Airflow 3.2.2 milestone May 22, 2026
@pierrejeambrun pierrejeambrun added the backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch label May 22, 2026
In dev mode the SPA shell is served by the airflow api-server while
Vite serves assets on a different origin. Module workers cannot be
constructed cross-origin even when CORS allows the fetch — Chrome
refuses with 'Script at <vite url> cannot be accessed from origin
<api-server>'. Monaco then falls back to 'main-thread workers', whose
`$loadForeignModule` path tries to resolve module IDs through the
non-existent AMD `require.toUrl`, flooding the console with
`Cannot read properties of undefined (reading 'toUrl')` errors.

Swap the `?worker` constructor imports for `?url` imports and
construct workers from a same-origin Blob shim that simply re-imports
the resolved URL. The Blob lives on the page origin so the Worker
constructor accepts it, and the inner cross-origin `import` is
permitted by Vite's CORS response.

Closes apache#67342.
@pierrejeambrun pierrejeambrun force-pushed the fix-monaco-worker-foreign-module-dev branch from a071e11 to ece18ce Compare May 22, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI Related to UI/UX. For Frontend Developers. backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI: Monaco workers throw "Cannot read properties of undefined (reading 'toUrl')" — foreign-module loader broken after #66647

2 participants