Skip to content

Commit b1c2660

Browse files
committed
fix(chat): avoid link card render loop
1 parent 0b3169a commit b1c2660

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

frontend/components/chat/LinkCard.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { defineComponent, h, ref } from 'vue'
2+
import { defineComponent, h, ref, watch } from 'vue'
33
import miniProgramIconUrl from '~/assets/images/wechat/mini-program.svg'
44
55
export default defineComponent({
@@ -19,7 +19,15 @@ export default defineComponent({
1919
setup(props) {
2020
const fromAvatarImgOk = ref(false)
2121
const fromAvatarImgError = ref(false)
22-
const lastFromAvatarUrl = ref('')
22+
23+
watch(
24+
() => String(props.fromAvatar || '').trim(),
25+
() => {
26+
fromAvatarImgOk.value = false
27+
fromAvatarImgError.value = false
28+
},
29+
{ immediate: true }
30+
)
2331
2432
const getFromText = () => {
2533
const raw = String(props.from || '').trim()
@@ -47,12 +55,6 @@ export default defineComponent({
4755
const isCoverVariant = !isMiniProgram && String(props.variant || '').trim() === 'cover'
4856
const Tag = canNavigate ? 'a' : 'div'
4957
50-
if (fromAvatarUrl !== lastFromAvatarUrl.value) {
51-
lastFromAvatarUrl.value = fromAvatarUrl
52-
fromAvatarImgOk.value = false
53-
fromAvatarImgError.value = false
54-
}
55-
5658
const showFromAvatarImg = Boolean(fromAvatarUrl) && !fromAvatarImgError.value
5759
const showFromAvatarText = (!fromAvatarUrl) || (!fromAvatarImgOk.value)
5860
const fromAvatarStyle = fromAvatarImgOk.value

0 commit comments

Comments
 (0)