Skip to content

Update dependencies & simplify monaco cross-domain worker setup#241

Merged
MaxGraey merged 1 commit intoAssemblyScript:mainfrom
MaxGraey:upd-monaco
Apr 14, 2026
Merged

Update dependencies & simplify monaco cross-domain worker setup#241
MaxGraey merged 1 commit intoAssemblyScript:mainfrom
MaxGraey:upd-monaco

Conversation

@MaxGraey
Copy link
Copy Markdown
Member

No description provided.

@MaxGraey MaxGraey requested a review from CountBleck April 11, 2026 08:17
@MaxGraey MaxGraey changed the title Update dependencies except vuepress & friends Update dependencies Apr 11, 2026
@MaxGraey MaxGraey requested a review from dcodeIO April 12, 2026 09:22
@MaxGraey MaxGraey changed the title Update dependencies Update dependencies & simplify monaco cross-origin setup Apr 12, 2026
@MaxGraey MaxGraey changed the title Update dependencies & simplify monaco cross-origin setup Update dependencies & simplify monaco cross-domain worker setup Apr 12, 2026
Comment on lines +322 to +331
const MONACO_BASE_URL = `https://cdn.jsdelivr.net/npm/monaco-editor@${MONACO_VERSION}/min/`

window.MonacoEnvironment.getWorkerUrl = (moduleId, label) => {
const workerUrl = oldGetWorkerUrl(moduleId, label)
const { isSame, url } = isSameOrigin(workerUrl)

/* istanbul ignore else */
if (isSame) return workerUrl
else {
let blob
try {
blob = new Blob([`importScripts('${url}');`], { type: 'application/javascript' })
} catch (e) {
const blobBuilder = new window.BlobBuilder()
blobBuilder.append(`importScripts('${url}');`)
blob = blobBuilder.getBlob('application/javascript')
}
return window.URL.createObjectURL(blob)
function crossDomainWorker() {
window.MonacoEnvironment = {
getWorkerUrl() {
const proxy = `
self.MonacoEnvironment = { baseUrl: '${MONACO_BASE_URL}' };
importScripts('${MONACO_BASE_URL}vs/base/worker/workerMain.js');
`
return URL.createObjectURL(new Blob([proxy], { type: 'application/javascript' }))
Copy link
Copy Markdown
Member Author

@MaxGraey MaxGraey Apr 14, 2026

Choose a reason for hiding this comment

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

@dcodeIO WDYT for such simplification?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wondering if some of these things served a real purpose. Say when Monaco runs on some hot reload capable dev server, do we perhaps want to preserve an existing Monaco environment instead of unconditionally creating a new one and leak the old? Or do we need same origin handling in some odd configurations (like in dev)? The previous try-catch there looks like some compatibility fallback, can that still be relevant nowadays?

Iirc, originally I basically copied whatever Monaco documented. Well possible that there is generally a better way today, one that doesn't even use AMD anymore.

Copy link
Copy Markdown
Member Author

@MaxGraey MaxGraey Apr 14, 2026

Choose a reason for hiding this comment

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

New implementation based on this tutorial:
https://log.schemescape.com/posts/web-development/embedding-monaco-from-cdn.html
and it looks like this typical approach after monaco-editor >= v0.52.x
https://github.com/egoist/vue-monaco/blob/master/README.md?plain=1#L122

With one exception, I decided to preserve data url creation via URL.createObjectURL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah. I was also wondering if there is a more modern ESM-aware way of doing the setup nowadays. Have you checked?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@MaxGraey MaxGraey merged commit 03d5b82 into AssemblyScript:main Apr 14, 2026
@MaxGraey MaxGraey deleted the upd-monaco branch April 14, 2026 20:36
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.

2 participants