Skip to content

Commit

Permalink
fix: downgrade react-markdown to v8 that supports React version < v18 (
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela authored Aug 5, 2024
1 parent 061d1a3 commit 5e6fea0
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 95 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"react-fast-compare": "^3.2.2",
"react-image-gallery": "1.2.12",
"react-is": "^18.1.0",
"react-markdown": "9.0.1",
"react-markdown": "^8.0.7",
"react-player": "2.10.1",
"react-popper": "^2.3.0",
"react-textarea-autosize": "^8.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ Array [
"
",
<blockquote>
<p>
b
</p>
Expand Down Expand Up @@ -551,8 +549,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
<li>
<p>
item 2
</p>
Expand All @@ -576,8 +572,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
<li>
<p>
item 3
</p>
Expand Down Expand Up @@ -619,8 +613,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
<li>
<p>
item 2
</p>
Expand All @@ -644,8 +636,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
<li>
<p>
item 3
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { u } from 'unist-builder';
import { visit } from 'unist-util-visit';

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

export const mentionsMarkdownPlugin = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { visit, Visitor } from 'unist-util-visit';

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

const visitor: Visitor = (node) => {
if (node.type !== 'html') return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { visit, Visitor } from 'unist-util-visit';
import { u } from 'unist-builder';

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

const visitor: Visitor = (node, index, parent) => {
if (typeof index === 'undefined' || index === 0) return;
if (typeof parent === 'undefined') return;
if (!node.position) return;
if (!(index && parent && node.position)) return;

const prevSibling = parent.children.at(index - 1);
if (!prevSibling?.position) return;
Expand Down
8 changes: 4 additions & 4 deletions src/components/Message/renderText/renderText.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ComponentType } from 'react';
import ReactMarkdown, { defaultUrlTransform, Options } from 'react-markdown';
import ReactMarkdown, { Options, uriTransformer } from 'react-markdown';
import { find } from 'linkifyjs';
import uniqBy from 'lodash.uniqby';
import remarkGfm from 'remark-gfm';
Expand All @@ -9,7 +9,7 @@ import { detectHttp, escapeRegExp, matchMarkdownLinks, messageCodeBlocks } from
import { emojiMarkdownPlugin, mentionsMarkdownPlugin } from './rehypePlugins';
import { htmlToTextPlugin, keepLineBreaksPlugin } from './remarkPlugins';

import type { PluggableList } from 'react-markdown/lib';
import type { PluggableList } from 'react-markdown/lib/react-markdown';
import type { UserResponse } from 'stream-chat';
import type { DefaultStreamChatGenerics } from '../../../types/types';

Expand Down Expand Up @@ -51,7 +51,7 @@ function encodeDecode(url: string) {
}
}

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

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

Expand Down Expand Up @@ -167,8 +167,8 @@ export const renderText = <
rehypePlugins={getRehypePlugins(rehypePlugins)}
remarkPlugins={getRemarkPlugins(remarkPlugins)}
skipHtml
transformLinkUri={urlTransform}
unwrapDisallowed
urlTransform={urlTransform}
>
{newText}
</ReactMarkdown>
Expand Down
Loading

0 comments on commit 5e6fea0

Please sign in to comment.