Webchat
Webchat copied to clipboard
mutated redux state
Hi!
The code
fmtMessages = () => {
return reduceRight(
this.props.messages,
(acc, cur) => {
const nextMessage = acc[0]
cur.displayIcon = !nextMessage || nextMessage.participant.isBot !== cur.participant.isBot
acc.unshift(cur)
return acc
},
[],
)
}
is muting redux state, which is dangerous practise. I believe it to be the source of a bug that duplicates sent messages, although I'm not sure.
this is my correction to the code:
fmtMessages = () => {
return reduceRight(
this.props.messages,
(acc, cur) => {
const nextMessage = acc[0]
cur.displayIcon = !nextMessage || nextMessage.participant.isBot !== cur.participant.isBot
acc.unshift(cur)
return acc
},
[],
)
}
Hi @DiesIrae,
Thanks for taking your time to debug our application. It seems that you c/c the same code, so we can't test it.
Don't hesitate to do a merge request. It will help us a lot !
Hi @OlivierNguyen !
You're welcome. Indeed, here is the updated code:
fmtMessages = () => {
return reduceRight(
this.props.messages,
(acc, cur) => {
const nextMessage = acc[0]
const displayIcon = !nextMessage || nextMessage.participant.isBot !== cur.participant.isBot
const newCur = {...cur, displayIcon}
acc.unshift(newCur)
return acc
},
[],
)
}