Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove dangerous derived state from RichText (#3007)

* Remove facet resolution from RichText

* Remove derived state

authored by

dan and committed by
GitHub
2d14d0e2 603f3c0b

+8 -23
+4 -21
src/components/RichText.tsx
··· 7 7 import {InlineLink} from '#/components/Link' 8 8 import {Text, TextProps} from '#/components/Typography' 9 9 import {toShortUrl} from 'lib/strings/url-helpers' 10 - import {getAgent} from '#/state/session' 11 10 import {TagMenu, useTagMenuControl} from '#/components/TagMenu' 12 11 import {isNative} from '#/platform/detection' 13 12 import {useInteractionState} from '#/components/hooks/useInteractionState' ··· 20 19 style, 21 20 numberOfLines, 22 21 disableLinks, 23 - resolveFacets = false, 24 22 selectable, 25 23 enableTags = false, 26 24 authorHandle, ··· 30 28 testID?: string 31 29 numberOfLines?: number 32 30 disableLinks?: boolean 33 - resolveFacets?: boolean 34 31 enableTags?: boolean 35 32 authorHandle?: string 36 33 }) { 37 - const detected = React.useRef(false) 38 - const [richText, setRichText] = React.useState<RichTextAPI>(() => 39 - value instanceof RichTextAPI ? value : new RichTextAPI({text: value}), 34 + const richText = React.useMemo( 35 + () => 36 + value instanceof RichTextAPI ? value : new RichTextAPI({text: value}), 37 + [value], 40 38 ) 41 39 const styles = [a.leading_snug, flatten(style)] 42 - 43 - React.useEffect(() => { 44 - if (!resolveFacets) return 45 - 46 - async function detectFacets() { 47 - const rt = new RichTextAPI({text: richText.text}) 48 - await rt.detectFacets(getAgent()) 49 - setRichText(rt) 50 - } 51 - 52 - if (!detected.current) { 53 - detected.current = true 54 - detectFacets() 55 - } 56 - }, [richText, setRichText, resolveFacets]) 57 40 58 41 const {text, facets} = richText 59 42
+4 -2
src/view/screens/Storybook/Typography.tsx
··· 22 22 <Text style={[a.text_2xs]}>atoms.text_2xs</Text> 23 23 24 24 <RichText 25 - resolveFacets 25 + // TODO: This only supports already resolved facets. 26 + // Resolving them on read is bad anyway. 26 27 value={`This is rich text. It can have mentions like @bsky.app or links like https://bsky.social`} 27 28 /> 28 29 <RichText 29 30 selectable 30 - resolveFacets 31 + // TODO: This only supports already resolved facets. 32 + // Resolving them on read is bad anyway. 31 33 value={`This is rich text. It can have mentions like @bsky.app or links like https://bsky.social`} 32 34 style={[a.text_xl]} 33 35 />