Skip to content

Conversation

fit2bot
Copy link
Contributor

@fit2bot fit2bot commented Jun 16, 2025

perf: chat websocket init

@fit2bot fit2bot requested a review from a team June 16, 2025 03:04
@@ -89,6 +89,7 @@ export default {
window.addEventListener('message', (event) => {
if (event.data === 'show-chat-panel') {
this.$refs.drawer.show = true
this.initWebSocket()
}
})
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code does not seem to contain any syntax errors or logical flaws. However, I can offer some recommendations for improvement:

Recommendation 1:

Add explicit return statements to prevent uncontrolled execution when this.$refs.drawer.show is truthy.

export default {
   ... // other definitions...

// Update:
   export default {
       window.addEventListener('message', (event) => {
            if (event.data === 'show-chat-panel') {

                this$refs.drawer.show = true;

                // Add this line to fix the above issue.
                return;
              } else {
                console.log("Message received but it's not a show chat panel request.");
              }

              this.initWebSocket();
        });
   },
};

Recommendation 2:

Handle cases where WebSocket initialization fails gracefully instead of exiting prematurely.

// Initialize WebSocket before showing drawer.
if (!this.websocketConnectionStatus.ok || !['open'].includes(this.websocketConnectionStatus.status)) {
      console.error("Failed to connect to WebSocket server");
}

export const showChatPanel = () =>
    this.window?.addEventListener('message', ({ data }) => {
       if (data === 'show-chat-panel') {
          this.$refs.drawer.show = true;                
  
          this.initWebSocket();      
      }

      console.error(data);  // Log error message
}
...

These modifications ensure that JavaScript runs smoothly without causing unexpected side effects and provides clear feedback on WebSocket connection status during asynchronous operations involving communication with clients outside of Vue.js components.

Copy link

@LeeEirc LeeEirc merged commit 18d5194 into dev Jun 16, 2025
5 of 6 checks passed
@LeeEirc LeeEirc deleted the pr@dev@perf_chat_panel branch June 16, 2025 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants