Bluesky app fork with some witchin' additions 💫

#929 Wrap `PasteInput` updates in a `setTimeout` (#1033)

* wrap PasteInput updates in a setTimeout

* just wrap the whole callback

authored by

Eric Bailey and committed by
GitHub
4515559b abd2c8e6

+48 -36
+48 -36
src/view/com/composer/text-input/TextInput.tsx
··· 79 79 })) 80 80 81 81 const onChangeText = useCallback( 82 - async (newText: string) => { 83 - const newRt = new RichText({text: newText}) 84 - newRt.detectFacetsWithoutResolution() 85 - setRichText(newRt) 82 + (newText: string) => { 83 + /* 84 + * This is a hack to bump the rendering of our styled 85 + * `textDecorated` to _after_ whatever processing is happening 86 + * within the `PasteInput` library. Without this, the elements in 87 + * `textDecorated` are not correctly painted to screen. 88 + * 89 + * NB: we tried a `0` timeout as well, but only positive values worked. 90 + * 91 + * @see https://github.com/bluesky-social/social-app/issues/929 92 + */ 93 + setTimeout(async () => { 94 + const newRt = new RichText({text: newText}) 95 + newRt.detectFacetsWithoutResolution() 96 + setRichText(newRt) 86 97 87 - const prefix = getMentionAt( 88 - newText, 89 - textInputSelection.current?.start || 0, 90 - ) 91 - if (prefix) { 92 - autocompleteView.setActive(true) 93 - autocompleteView.setPrefix(prefix.value) 94 - } else { 95 - autocompleteView.setActive(false) 96 - } 98 + const prefix = getMentionAt( 99 + newText, 100 + textInputSelection.current?.start || 0, 101 + ) 102 + if (prefix) { 103 + autocompleteView.setActive(true) 104 + autocompleteView.setPrefix(prefix.value) 105 + } else { 106 + autocompleteView.setActive(false) 107 + } 97 108 98 - const set: Set<string> = new Set() 109 + const set: Set<string> = new Set() 99 110 100 - if (newRt.facets) { 101 - for (const facet of newRt.facets) { 102 - for (const feature of facet.features) { 103 - if (AppBskyRichtextFacet.isLink(feature)) { 104 - if (isUriImage(feature.uri)) { 105 - const res = await downloadAndResize({ 106 - uri: feature.uri, 107 - width: POST_IMG_MAX.width, 108 - height: POST_IMG_MAX.height, 109 - mode: 'contain', 110 - maxSize: POST_IMG_MAX.size, 111 - timeout: 15e3, 112 - }) 111 + if (newRt.facets) { 112 + for (const facet of newRt.facets) { 113 + for (const feature of facet.features) { 114 + if (AppBskyRichtextFacet.isLink(feature)) { 115 + if (isUriImage(feature.uri)) { 116 + const res = await downloadAndResize({ 117 + uri: feature.uri, 118 + width: POST_IMG_MAX.width, 119 + height: POST_IMG_MAX.height, 120 + mode: 'contain', 121 + maxSize: POST_IMG_MAX.size, 122 + timeout: 15e3, 123 + }) 113 124 114 - if (res !== undefined) { 115 - onPhotoPasted(res.path) 125 + if (res !== undefined) { 126 + onPhotoPasted(res.path) 127 + } 128 + } else { 129 + set.add(feature.uri) 116 130 } 117 - } else { 118 - set.add(feature.uri) 119 131 } 120 132 } 121 133 } 122 134 } 123 - } 124 135 125 - if (!isEqual(set, suggestedLinks)) { 126 - onSuggestedLinksChanged(set) 127 - } 136 + if (!isEqual(set, suggestedLinks)) { 137 + onSuggestedLinksChanged(set) 138 + } 139 + }, 1) 128 140 }, 129 141 [ 130 142 setRichText,