Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(monaco): keep DiffEditor off the jsdelivr CDN (#59562)

posthog[bot]18fe757a4b45
diff --git a/frontend/src/lib/monaco/CodeEditor.tsx b/frontend/src/lib/monaco/CodeEditor.tsx
index 45bd13b5b50f..cbcbe534dc91 100644
--- a/frontend/src/lib/monaco/CodeEditor.tsx
+++ b/frontend/src/lib/monaco/CodeEditor.tsx
@@ -1,6 +1,6 @@
import './CodeEditor.scss'
-import MonacoEditor, { type EditorProps, Monaco, DiffEditor as MonacoDiffEditor, loader } from '@monaco-editor/react'
+import MonacoEditor, { type EditorProps, Monaco, DiffEditor as MonacoDiffEditor } from '@monaco-editor/react'
import { BuiltLogic, useActions, useMountedLogic, useValues } from 'kea'
import * as monacoModule from 'monaco-editor'
import { IDisposable, editor, editor as importedEditor } from 'monaco-editor'
@@ -24,10 +24,6 @@ import { inStorybookTestRunner } from 'lib/utils'
import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { AnyDataNode, HogLanguage, HogQLMetadataResponse, NodeKind } from '~/queries/schema/schema-general'
-if (loader) {
- loader.config({ monaco: monacoModule })
-}
-
export interface CodeEditorProps extends Omit<EditorProps, 'loading' | 'theme'> {
queryKey?: string
autocompleteContext?: string
diff --git a/frontend/src/lib/monaco/monacoEnvironment.ts b/frontend/src/lib/monaco/monacoEnvironment.ts
index 8c739ea99c47..15ca17d408f5 100644
--- a/frontend/src/lib/monaco/monacoEnvironment.ts
+++ b/frontend/src/lib/monaco/monacoEnvironment.ts
@@ -2,6 +2,9 @@
// instead of trying to load them from a CDN or different origin.
// This prevents cross-origin errors with json.worker.js and other language workers.
+import { loader } from '@monaco-editor/react'
+import * as monacoModule from 'monaco-editor'
+
function createWorker(path: string): Worker {
try {
return new Worker(path, { type: 'module' })
@@ -26,3 +29,11 @@ globalThis.MonacoEnvironment = {
return createWorker('/static/monacoEditorWorker.js')
},
}
+
+// Point @monaco-editor/react at the bundled monaco-editor module so its components
+// don't race to fetch a different Monaco build (and its workerMain.js) from jsdelivr.
+// Must run before any @monaco-editor/react component instantiates, so this side-effect
+// lives here rather than inside CodeEditor.tsx (which only loads when CodeEditor mounts).
+if (loader) {
+ loader.config({ monaco: monacoModule })
+}
diff --git a/frontend/src/scenes/hog-functions/misc/activityDescriptions.tsx b/frontend/src/scenes/hog-functions/misc/activityDescriptions.tsx
index d1312a545aa7..b8968cebc942 100644
--- a/frontend/src/scenes/hog-functions/misc/activityDescriptions.tsx
+++ b/frontend/src/scenes/hog-functions/misc/activityDescriptions.tsx
@@ -1,5 +1,6 @@
import { DiffEditor } from '@monaco-editor/react'
+import 'lib/monaco/monacoEnvironment'
import {
ActivityLogItem,
HumanizedChange,