fix: prevent chatRef null errors when switching chats rapidly#894
fix: prevent chatRef null errors when switching chats rapidly#894
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Deployed to https://msg-adamant-pr-894.surge.sh 🚀 |
ac36a69 to
a37de5e
Compare
al-onyxprotocol
left a comment
There was a problem hiding this comment.
Tested: https://adamant-lqle6zz2v-adamant-team.vercel.app
Chrome on macOS
Test ADM account
Test result: Failed
I don't see Cannot read properties of null in Console, but I see Element not found when switching between chats.
|
@al-onyxprotocol |
Hey, We can:
@S-FrontendDev @graycraft @Linhead What do you think? |
…emove debug code logic
|
@dev-adamant-im @bludnic |
|
@Linhead |
|
Successfully tore down https://msg-adamant-pr-894.surge.sh 🥲 |

Description
Fixed race condition errors occurring when rapidly switching between chats. The issue manifested as multiple
TypeError: Cannot read properties of nullerrors forchatRef.valuemethods (maintainScrollPosition,scrollTo,scrollToBottom,isScrolledToBottom).Root cause:
:key="partnerId"in the parent view (Chat.vue line 5), which causes Vue to create a completely new component instance for each differentpartnerIdonMountedschedules callbacks vianextTick()to execute after the next DOM updatenextTickcallbackskeychangechatRef.valuebecomesnullnextTickcallbacks from Chat A are still in the queue and execute, attempting to access the now-nullchatRef.valuesetTimeoutinfetchChatMessagescontinued running after component unmount, causing infinite error loopsSolution:
setTimeoutID inonBeforeUnmountto prevent delayed callbacksnextTickcallbacks wherechatRef.valueis accessed (onMountedline 522,scrollBehaviorlines 921-923)?.) formaintainScrollPosition()calls infinallyblocks and recursive functions (lines 887, 894)Related issue
Closes #893
External links (optional)
N/A
Screenshots or videos (optional)
N/A
Breaking changes
No breaking changes. This is a bug fix that improves stability.
How to test
TypeError: Cannot read properties of nullerrors appearExpected outcome: No console errors, smooth chat transitions without crashes or infinite error loops.
Notes for reviewers
src/components/Chat/Chat.vueChecklist