UI: Load Monaco workers via a same-origin Blob shim (fix dev-mode noise)#67352
Draft
pierrejeambrun wants to merge 2 commits into
Draft
UI: Load Monaco workers via a same-origin Blob shim (fix dev-mode noise)#67352pierrejeambrun wants to merge 2 commits into
pierrejeambrun wants to merge 2 commits into
Conversation
Member
Author
|
Merge #67316 first |
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.
a071e11 to
ece18ce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?
Generated-by: Claude Code (Opus 4.7) following the guidelines