Skip to content

Commit 356db05

Browse files
committed
fix(CodeEditor): Don't use CDN for loading monaco
The @patternfly/react-code-editor library uses a CDN to load some Monaco stuff by default. This doesn't work for all consumers. Adjusting so we can do without the CDN.
1 parent c082f9c commit 356db05

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ module.exports = {
3838
customReact: 'react',
3939
reactRedux: 'react-redux',
4040
PFReactCore: '@patternfly/react-core',
41-
PFReactTable: '@patternfly/react-table'
41+
PFReactTable: '@patternfly/react-table',
42+
'^monaco-editor$': '<rootDir>/packages/module/src/__mocks__/monaco-editor.ts'
4243
},
4344
globalSetup: '<rootDir>/config/globalSetup.js',
4445
transform: {

package-lock.json

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

packages/module/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@patternfly/react-table": "^6.1.0",
4040
"@segment/analytics-next": "^1.76.0",
4141
"clsx": "^2.1.0",
42+
"monaco-editor": "^0.54.0",
4243
"path-browserify": "^1.0.1",
4344
"posthog-js": "^1.194.4",
4445
"react-markdown": "^9.0.1",

packages/module/src/CodeModal/CodeModal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import type { FunctionComponent, MouseEvent } from 'react';
66
import { useState, useEffect, useRef } from 'react';
77
import path from 'path-browserify';
8-
import type monaco from 'monaco-editor';
8+
import * as monaco from 'monaco-editor';
9+
import { loader } from '@monaco-editor/react';
910

1011
// Import PatternFly components
1112
import { CodeEditor } from '@patternfly/react-code-editor';
@@ -22,6 +23,9 @@ import FileDetails, { extensionToLanguage } from '../FileDetails';
2223
import { ChatbotDisplayMode } from '../Chatbot';
2324
import ChatbotModal from '../ChatbotModal/ChatbotModal';
2425

26+
// Configure Monaco loader to use the npm package instead of CDN
27+
loader.config({ monaco });
28+
2529
export interface CodeModalProps {
2630
/** Class applied to code editor */
2731
codeEditorControlClassName?: string;

0 commit comments

Comments
 (0)