-
Notifications
You must be signed in to change notification settings - Fork 345
refactor: architectural overhaul, memory leak fixes, and UI consistency #1163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
4fe251a
cd1c7c8
8c6f9f7
1358825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -146,43 +146,46 @@ const ChatBody = ({ | |||
| ); | ||||
|
|
||||
| useEffect(() => { | ||||
| RCInstance.auth.onAuthChange((user) => { | ||||
| if (user) { | ||||
| RCInstance.addMessageListener(addMessage); | ||||
| RCInstance.addMessageDeleteListener(removeMessage); | ||||
| RCInstance.addActionTriggeredListener(onActionTriggerResponse); | ||||
| RCInstance.addUiInteractionListener(onActionTriggerResponse); | ||||
| } | ||||
| }); | ||||
|
|
||||
| return () => { | ||||
| const removeAllListeners = () => { | ||||
| RCInstance.removeMessageListener(addMessage); | ||||
| RCInstance.removeMessageDeleteListener(removeMessage); | ||||
| RCInstance.removeActionTriggeredListener(onActionTriggerResponse); | ||||
| RCInstance.removeUiInteractionListener(onActionTriggerResponse); | ||||
| }; | ||||
| }, [RCInstance, addMessage, removeMessage, onActionTriggerResponse]); | ||||
|
|
||||
| useEffect(() => { | ||||
| RCInstance.auth.onAuthChange((user) => { | ||||
| const unsubscribe = RCInstance.auth.onAuthChange((user) => { | ||||
| if (user) { | ||||
| // Clear old listeners before adding new ones to avoid duplicates | ||||
| removeAllListeners(); | ||||
| RCInstance.addMessageListener(addMessage); | ||||
| RCInstance.addMessageDeleteListener(removeMessage); | ||||
| RCInstance.addActionTriggeredListener(onActionTriggerResponse); | ||||
| RCInstance.addUiInteractionListener(onActionTriggerResponse); | ||||
|
|
||||
| getMessagesAndRoles(); | ||||
| setHasMoreMessages(true); | ||||
| } else { | ||||
| getMessagesAndRoles(anonymousMode); | ||||
| } | ||||
| }); | ||||
| }, [RCInstance, anonymousMode, getMessagesAndRoles]); | ||||
|
|
||||
| useEffect(() => { | ||||
| RCInstance.auth.onAuthChange((user) => { | ||||
| if (user) { | ||||
| fetchAndSetPermissions(); | ||||
| } else { | ||||
| removeAllListeners(); | ||||
| getMessagesAndRoles(anonymousMode); | ||||
| permissionsRef.current = null; | ||||
| } | ||||
| }); | ||||
| }, []); | ||||
|
|
||||
| return () => { | ||||
| if (typeof unsubscribe === 'function') unsubscribe(); | ||||
| removeAllListeners(); | ||||
| }; | ||||
| }, [ | ||||
| RCInstance, | ||||
| addMessage, | ||||
| removeMessage, | ||||
| onActionTriggerResponse, | ||||
| anonymousMode, | ||||
| getMessagesAndRoles, | ||||
| fetchAndSetPermissions, | ||||
| permissionsRef, | ||||
|
||||
| permissionsRef, |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scroll behavior logic has a potential issue. The condition isInitialLoad = messages.length > 0 && scrollTop === 0 may incorrectly trigger scrolling to bottom when the user has scrolled to the top to load older messages. This could disrupt the user's reading experience by unexpectedly jumping to the bottom when old messages are loaded. Consider checking if this is truly an initial load rather than just being at scroll position 0.
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect dependency in useEffect: messageListRef should not be included in the dependency array. Ref objects have stable references across renders and don't trigger re-renders when their .current value changes. Including refs in dependency arrays is incorrect and can cause unexpected behavior. Remove messageListRef from this dependency array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The catch-all error handling at line 78-81 may inadvertently catch successful login responses that don't match the expected format. If
res.status !== 'success'and!res.meand!res.error, the function will not return anything, potentially leaving the UI in an inconsistent state. Consider adding an explicit return statement for this case or logging a warning when an unexpected response format is received.