Skip to content
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

Messages are getting duplicated on reconnect #335

Open
Dujma opened this issue Oct 25, 2023 · 0 comments
Open

Messages are getting duplicated on reconnect #335

Dujma opened this issue Oct 25, 2023 · 0 comments

Comments

@Dujma
Copy link

Dujma commented Oct 25, 2023

When the connection is restored, messages are duplicated in the local storage.

To reproduce:

  1. Exchange some messages with the chatbot.
  2. Simulate network loss. For Chrome: Developer Tools -> Network -> Change from "No throttling" to "Offline"
  3. Wait for the connection to get lost.
  4. Change back to "No throttling".
  5. Now you have double the messages in the local storage.

This can cause the chatbot to completely break if you have enough of reconnects. Messages are going to be exponentially increased until the limit is reached and exception is going to be thrown in options-middleware.ts on setting the messages in the storage:

browserStorage.setItem(key, JSON.stringify({
  messages,
  rating
}));

I believe the issue is because of reducer.ts class that has a small typo:

export const reducer = (state = rootReducer(undefined, { type: '' }), action) => {
    switch (action.type) {
        case 'RESET_STATE': {
            // We only restore messages and prepend them to the current message history
            return rootReducer({
                ...state,
                messages: [
                    ...action.state.messages, // This I believe should be ...action.state.message (singular)
                    ...state.messages,
                ],
                rating: {
                    ...state.rating,
                    hasGivenRating: action.state.rating.hasGivenRating,
                }
            }, { type: '' })
        };
    };

    return rootReducer(state, action);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant