diff options
author | dan <dan.abramov@gmail.com> | 2024-02-28 01:35:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-27 17:35:25 -0800 |
commit | 2d14d0e2dbe845edb5836199ce79928395c079a0 (patch) | |
tree | d3549937a1bb809c721632e6f1ca3d7a50a852be /src/components/RichText.tsx | |
parent | 603f3c0be972e013900264d706e2d28b87a93122 (diff) | |
download | voidsky-2d14d0e2dbe845edb5836199ce79928395c079a0.tar.zst |
Remove dangerous derived state from RichText (#3007)
* Remove facet resolution from RichText * Remove derived state
Diffstat (limited to 'src/components/RichText.tsx')
-rw-r--r-- | src/components/RichText.tsx | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/src/components/RichText.tsx b/src/components/RichText.tsx index 22391cb24..3d5f08026 100644 --- a/src/components/RichText.tsx +++ b/src/components/RichText.tsx @@ -7,7 +7,6 @@ import {atoms as a, TextStyleProp, flatten, useTheme, web, native} from '#/alf' import {InlineLink} from '#/components/Link' import {Text, TextProps} from '#/components/Typography' import {toShortUrl} from 'lib/strings/url-helpers' -import {getAgent} from '#/state/session' import {TagMenu, useTagMenuControl} from '#/components/TagMenu' import {isNative} from '#/platform/detection' import {useInteractionState} from '#/components/hooks/useInteractionState' @@ -20,7 +19,6 @@ export function RichText({ style, numberOfLines, disableLinks, - resolveFacets = false, selectable, enableTags = false, authorHandle, @@ -30,31 +28,16 @@ export function RichText({ testID?: string numberOfLines?: number disableLinks?: boolean - resolveFacets?: boolean enableTags?: boolean authorHandle?: string }) { - const detected = React.useRef(false) - const [richText, setRichText] = React.useState<RichTextAPI>(() => - value instanceof RichTextAPI ? value : new RichTextAPI({text: value}), + const richText = React.useMemo( + () => + value instanceof RichTextAPI ? value : new RichTextAPI({text: value}), + [value], ) const styles = [a.leading_snug, flatten(style)] - React.useEffect(() => { - if (!resolveFacets) return - - async function detectFacets() { - const rt = new RichTextAPI({text: richText.text}) - await rt.detectFacets(getAgent()) - setRichText(rt) - } - - if (!detected.current) { - detected.current = true - detectFacets() - } - }, [richText, setRichText, resolveFacets]) - const {text, facets} = richText if (!facets?.length) { |