Skip to content

Commit bfe97f5

Browse files
fix: katex array breaking the app (#6963)
* fix: collapsible attachment with text duplicating the content * fix: ktex breaking the app * fix: snapshot test * chore: format code and fix lint issues [skip ci] * cleanup * cleanup * cleanup * chore: format code and fix lint issues [skip ci] --------- Co-authored-by: OtavioStasiak <OtavioStasiak@users.noreply.github.com> Co-authored-by: Rohit Bansal <40559587+Rohit3523@users.noreply.github.com>
1 parent 2038d6d commit bfe97f5

3 files changed

Lines changed: 2361 additions & 1681 deletions

File tree

app/containers/markdown/components/Katex.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,34 @@ interface IKaTeXProps {
1313
value: KaTeXProps['value'];
1414
}
1515

16+
const BLOCK_ENV_PATTERN = /\\begin\s*\{\s*(array|matrix|pmatrix|bmatrix|Bmatrix|vmatrix|Vmatrix)\s*\}/;
17+
1618
export const KaTeX = ({ value }: IKaTeXProps): React.ReactElement | null => {
1719
const { colors } = useTheme();
1820
const fixAndroidWebviewCrashStyle: StyleProp<ViewStyle> = isAndroid ? { opacity: 0.99, overflow: 'hidden' } : {};
21+
// KaTeX array does not render correctly in MathView (shows gray box).
22+
// MathView does not throw, so renderError is never triggered.
23+
if (BLOCK_ENV_PATTERN.test(value)) {
24+
return (
25+
<Katex
26+
expression={value}
27+
displayMode={true}
28+
style={[{ flex: 1, height: DEFAULT_MESSAGE_HEIGHT }, fixAndroidWebviewCrashStyle]}
29+
/>
30+
);
31+
}
32+
1933
return (
2034
<MathView
2135
math={value}
36+
config={{ inline: false }}
2237
style={{ color: colors.fontDefault }}
2338
renderError={() => (
24-
<Katex expression={value} style={[{ flex: 1, height: DEFAULT_MESSAGE_HEIGHT }, fixAndroidWebviewCrashStyle]} />
39+
<Katex
40+
expression={value}
41+
displayMode={true}
42+
style={[{ flex: 1, height: DEFAULT_MESSAGE_HEIGHT }, fixAndroidWebviewCrashStyle]}
43+
/>
2544
)}
2645
/>
2746
);

app/containers/message/Message.stories.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,25 @@ export const Katex = () => (
22382238
);
22392239
export const KatexLargeFont = () => <MessageLargeFont {...katex} />;
22402240

2241+
const katexArray = {
2242+
msg: '\\begin{array}{|c|c|c|c|c|c|} \\hline \\text{...} & \\text{...} \\\\ \\hline \\end{array}',
2243+
md: [
2244+
{
2245+
type: 'KATEX',
2246+
value:
2247+
' \\begin{array}{|c|c|c|c|c|c|} \\hline \\text{testing} & \\text{testingII} & \\text{testing III} & \\text{testing IV} & \\text{testV} & \\text{testVI} \\\\ \\hline \\text{TEST} & \\text{TEST} & \\text{TEST} & \\text{TEST} & \\text{TEST} & \\text{TEST} \\\\ \\hline\\text{TEST} & \\text{✅} & \\text{test} & \\text{test} & \\text{test} & \\text{✅} \\\\ \\hline \\end{array} '
2248+
}
2249+
]
2250+
};
2251+
2252+
export const KatexArray = () => (
2253+
<>
2254+
<Message {...katexArray} />
2255+
</>
2256+
);
2257+
2258+
export const KatexArrayLargeFont = () => <MessageLargeFont {...katexArray} />;
2259+
22412260
const inlineKatex = {
22422261
msg: '\\(xˆ2 + yˆ2 - zˆ2\\)',
22432262
md: [

0 commit comments

Comments
 (0)