Skip to content

Commit c604322

Browse files
committed
Remove react-prism
It doesn't seem to be updated anymore and our uses are small enough.
1 parent 16bcb57 commit c604322

10 files changed

+54
-29
lines changed

ui/frontend/.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ module.exports = {
8282
'Output/PaneWithMir.tsx',
8383
'Output/SimplePane.tsx',
8484
'PopButton.tsx',
85+
'Prism.tsx',
8586
'Stdin.tsx',
8687
'actions.ts',
8788
'api.ts',
@@ -91,6 +92,7 @@ module.exports = {
9192
'editor/SimpleEditor.tsx',
9293
'hooks.ts',
9394
'observer.ts',
95+
'prism-shim.ts',
9496
'reducers/**/*.ts',
9597
'reducers/websocket.ts',
9698
'selectors/index.spec.ts',

ui/frontend/.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ node_modules
2222
!Output/PaneWithMir.tsx
2323
!Output/SimplePane.tsx
2424
!PopButton.tsx
25+
!Prism.tsx
2526
!Stdin.tsx
2627
!actions.ts
2728
!api.ts
@@ -31,6 +32,7 @@ node_modules
3132
!editor/SimpleEditor.tsx
3233
!hooks.ts
3334
!observer.ts
35+
!prism-shim.ts
3436
!reducers/**/*.ts
3537
!selectors/index.spec.ts
3638
!types.ts

ui/frontend/HelpExample.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import 'prismjs/components/prism-rust.min';
21
import React, { useCallback } from 'react';
3-
import { PrismCode } from 'react-prism';
42
import root from 'react-shadow';
53

4+
import Prism from './Prism';
65
import * as actions from './actions';
76
import { useAppDispatch } from './hooks';
87

@@ -25,9 +24,7 @@ const HelpExample: React.FC<HelpExampleProps> = ({ code }) => {
2524
<root.div>
2625
<link href={prismTheme} rel="stylesheet" />
2726

28-
<pre>
29-
<PrismCode className="language-rust">{code}</PrismCode>
30-
</pre>
27+
<Prism language="rust">{code}</Prism>
3128
</root.div>
3229
</div>
3330
);

ui/frontend/Output/OutputPrism.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import React from 'react';
2-
import { PrismCode } from 'react-prism';
2+
3+
import Prism from '../Prism';
34

45
import styles from './OutputPrism.module.css';
56

67
interface OutputPrismProps {
7-
children: React.ReactNode;
8-
languageCode: 'language-rust_mir' | 'language-rust_errors';
8+
children?: string;
9+
language: 'rust_mir' | 'rust_errors';
910
}
1011

11-
const OutputPrism: React.FC<OutputPrismProps> = ({ languageCode, children }) => (
12-
<pre>
13-
<PrismCode className={`${styles.container} ${languageCode}`}>{children}</PrismCode>
14-
</pre>
12+
const OutputPrism: React.FC<OutputPrismProps> = ({ language, children }) => (
13+
<Prism className={styles.container} language={language}>
14+
{children}
15+
</Prism>
1516
);
1617

1718
export default OutputPrism;

ui/frontend/Output/PaneWithMir.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const PaneWithMir: React.FC<PaneWithMirProps> = ({ code, ...rest }) => (
1212
<SimplePane {...rest}>
1313
<div data-test-id="output-result">
1414
<Header label="Result" />
15-
<OutputPrism languageCode="language-rust_mir">{code}</OutputPrism>
15+
<OutputPrism language="rust_mir">{code}</OutputPrism>
1616
</div>
1717
</SimplePane>
1818
);

ui/frontend/Output/SimplePane.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import OutputPrism from './OutputPrism';
66
import Section from './Section';
77

88
interface HighlightErrorsProps {
9-
children: React.ReactNode;
9+
children?: string;
1010
label: string;
1111
}
1212

@@ -24,7 +24,7 @@ const onOutputPrismCopy: React.ClipboardEventHandler = (event) => {
2424
const HighlightErrors: React.FC<HighlightErrorsProps> = ({ label, children }) => (
2525
<div data-test-id="output-stderr" onCopy={onOutputPrismCopy}>
2626
<Header label={label} />
27-
<OutputPrism languageCode="language-rust_errors">{children}</OutputPrism>
27+
<OutputPrism language="rust_errors">{children}</OutputPrism>
2828
</div>
2929
);
3030

ui/frontend/Prism.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { useEffect, useRef } from 'react';
2+
3+
import RealPrism from './prism-shim';
4+
5+
interface PrismProps {
6+
children?: string;
7+
language: 'rust' | 'rust_mir' | 'rust_errors';
8+
className?: string;
9+
}
10+
11+
const Prism: React.FC<PrismProps> = ({ children, language, className = '' }) => {
12+
const element = useRef(null);
13+
14+
useEffect(() => {
15+
if (!element.current) {
16+
return;
17+
}
18+
19+
RealPrism.highlightElement(element.current);
20+
}, [element, children, language]);
21+
22+
return (
23+
<pre>
24+
<code ref={element} className={`${className} language-${language}`}>
25+
{children}
26+
</code>
27+
</pre>
28+
);
29+
};
30+
31+
export default Prism;

ui/frontend/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"react-dom": "^18.2.0",
2121
"react-monaco-editor": "^0.55.0",
2222
"react-portal": "^4.1.4",
23-
"react-prism": "^4.0.0",
2423
"react-redux": "^9.0.2",
2524
"react-shadow": "^20.0.0",
2625
"redux-thunk": "^3.1.0",

ui/frontend/pnpm-lock.yaml

-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/frontend/prism-shim.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Prism from 'prismjs';
2+
import 'prismjs/components/prism-rust';
3+
4+
Prism.manual = true;
5+
6+
export default Prism;

0 commit comments

Comments
 (0)