Skip to content

Commit 49c85a2

Browse files
authored
fix(dashboard): bundle Monaco editor instead of fetching from CDN (#4247)
1 parent 40f8a99 commit 49c85a2

4 files changed

Lines changed: 49 additions & 7 deletions

File tree

frontend/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"js-confetti": "^0.13.1",
7070
"lodash": "^4.18.1",
7171
"lucide-react": "^1.8.0",
72+
"monaco-editor": "^0.55.1",
7273
"monaco-themes": "^0.4.8",
7374
"ms": "^2.1.3",
7475
"posthog-js": "^1.369.2",

frontend/app/pnpm-lock.yaml

Lines changed: 26 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/app/src/components/v1/ui/code-editor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import CopyToClipboard from './copy-to-clipboard';
22
import { useTheme } from '@/components/hooks/use-theme';
3+
import '@/lib/monaco-environment';
34
import { cn } from '@/lib/utils';
45
import Editor, { Monaco, OnMount } from '@monaco-editor/react';
56
import { useCallback, useEffect, useId, useRef } from 'react';
@@ -49,7 +50,8 @@ export function CodeEditor({
4950
const existingSchemas = existingOptions.schemas || [];
5051

5152
const otherSchemas = existingSchemas.filter(
52-
(s) => !s.fileMatch?.includes(modelPath),
53+
(s: (typeof existingSchemas)[number]) =>
54+
!s.fileMatch?.includes(modelPath),
5355
);
5456

5557
const newSchemas = hasJsonSchema
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Bundles Monaco locally instead of letting @monaco-editor/react fetch it
2+
// from cdn.jsdelivr.net at runtime, which breaks air-gapped/self-hosted
3+
// deployments. Importing this module configures both the editor's worker
4+
// environment and the loader before any <Editor /> instance mounts.
5+
import { loader } from '@monaco-editor/react';
6+
import * as monaco from 'monaco-editor';
7+
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
8+
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
9+
10+
self.MonacoEnvironment = {
11+
getWorker(_workerId, label) {
12+
if (label === 'json') {
13+
return new jsonWorker();
14+
}
15+
return new editorWorker();
16+
},
17+
};
18+
19+
loader.config({ monaco });

0 commit comments

Comments
 (0)