Skip to content

Commit 0028527

Browse files
committed
fix: downgrade react-markdown to v8 that supports React version < v18
1 parent 061d1a3 commit 0028527

File tree

7 files changed

+409
-94
lines changed

7 files changed

+409
-94
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"react-fast-compare": "^3.2.2",
8484
"react-image-gallery": "1.2.12",
8585
"react-is": "^18.1.0",
86-
"react-markdown": "9.0.1",
86+
"react-markdown": "^8.0.7",
8787
"react-player": "2.10.1",
8888
"react-popper": "^2.3.0",
8989
"react-textarea-autosize": "^8.3.0",

src/components/Message/renderText/__tests__/__snapshots__/renderText.test.js.snap

-10
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ Array [
260260
"
261261
",
262262
<blockquote>
263-
264-
265263
<p>
266264
b
267265
</p>
@@ -551,8 +549,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
551549
552550
553551
<li>
554-
555-
556552
<p>
557553
item 2
558554
</p>
@@ -576,8 +572,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
576572
577573
578574
<li>
579-
580-
581575
<p>
582576
item 3
583577
</p>
@@ -619,8 +613,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
619613
620614
621615
<li>
622-
623-
624616
<p>
625617
item 2
626618
</p>
@@ -644,8 +636,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
644636
645637
646638
<li>
647-
648-
649639
<p>
650640
item 3
651641
</p>

src/components/Message/renderText/rehypePlugins/mentionsMarkdownPlugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { u } from 'unist-builder';
44
import { visit } from 'unist-util-visit';
55

66
import type { Nodes } from 'hast-util-find-and-replace/lib';
7-
import type { Element } from 'react-markdown/lib';
7+
import type { Element } from 'react-markdown/lib/ast-to-react';
88
import type { UserResponse } from 'stream-chat';
9-
import type { DefaultStreamChatGenerics } from '../../../../types/types';
9+
import type { DefaultStreamChatGenerics } from '../../../../types';
1010

1111
export const mentionsMarkdownPlugin = <
1212
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics

src/components/Message/renderText/remarkPlugins/htmlToTextPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { visit, Visitor } from 'unist-util-visit';
22

3-
import type { Nodes } from 'react-markdown/lib';
3+
import type { Nodes } from 'hast-util-find-and-replace/lib';
44

55
const visitor: Visitor = (node) => {
66
if (node.type !== 'html') return;

src/components/Message/renderText/remarkPlugins/keepLineBreaksPlugin.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { visit, Visitor } from 'unist-util-visit';
22
import { u } from 'unist-builder';
33

44
import type { Break } from 'mdast';
5-
import type { Nodes } from 'react-markdown/lib';
5+
import type { Nodes } from 'hast-util-find-and-replace/lib';
66

77
const visitor: Visitor = (node, index, parent) => {
8-
if (typeof index === 'undefined' || index === 0) return;
9-
if (typeof parent === 'undefined') return;
8+
if (index === null || typeof index === 'undefined' || index === 0) return;
9+
if (parent === null || typeof parent === 'undefined') return;
1010
if (!node.position) return;
1111

1212
const prevSibling = parent.children.at(index - 1);

src/components/Message/renderText/renderText.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ComponentType } from 'react';
2-
import ReactMarkdown, { defaultUrlTransform, Options } from 'react-markdown';
2+
import ReactMarkdown, { Options, uriTransformer } from 'react-markdown';
33
import { find } from 'linkifyjs';
44
import uniqBy from 'lodash.uniqby';
55
import remarkGfm from 'remark-gfm';
@@ -9,7 +9,7 @@ import { detectHttp, escapeRegExp, matchMarkdownLinks, messageCodeBlocks } from
99
import { emojiMarkdownPlugin, mentionsMarkdownPlugin } from './rehypePlugins';
1010
import { htmlToTextPlugin, keepLineBreaksPlugin } from './remarkPlugins';
1111

12-
import type { PluggableList } from 'react-markdown/lib';
12+
import type { PluggableList } from 'react-markdown/lib/react-markdown';
1313
import type { UserResponse } from 'stream-chat';
1414
import type { DefaultStreamChatGenerics } from '../../../types/types';
1515

@@ -51,7 +51,7 @@ function encodeDecode(url: string) {
5151
}
5252
}
5353

54-
const urlTransform = (uri: string) => (uri.startsWith('app://') ? uri : defaultUrlTransform(uri));
54+
const urlTransform = (uri: string) => (uri.startsWith('app://') ? uri : uriTransformer(uri));
5555

5656
const getPluginsForward: RenderTextPluginConfigurator = (plugins: PluggableList) => plugins;
5757

@@ -167,8 +167,8 @@ export const renderText = <
167167
rehypePlugins={getRehypePlugins(rehypePlugins)}
168168
remarkPlugins={getRemarkPlugins(remarkPlugins)}
169169
skipHtml
170+
transformLinkUri={urlTransform}
170171
unwrapDisallowed
171-
urlTransform={urlTransform}
172172
>
173173
{newText}
174174
</ReactMarkdown>

0 commit comments

Comments
 (0)