From bfff053a48e8a0a5ab526f90717e79dcf9280ed0 Mon Sep 17 00:00:00 2001 From: melloware Date: Wed, 23 Mar 2022 15:35:29 -0400 Subject: [PATCH] Fix #2696: Toast allow immutable messages --- components/lib/toast/Toast.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/components/lib/toast/Toast.js b/components/lib/toast/Toast.js index 9dd9ef37e7..b5390d9b5d 100644 --- a/components/lib/toast/Toast.js +++ b/components/lib/toast/Toast.js @@ -53,24 +53,24 @@ export class Toast extends Component { show(value) { if (value) { - if (value) { - let newMessages; - - if (Array.isArray(value)) { - for (let i = 0; i < value.length; i++) { - value[i].id = messageIdx++; - newMessages = [...this.state.messages, ...value]; - } - } - else { - value.id = messageIdx++; - newMessages = this.state.messages ? [...this.state.messages, value] : [value]; + // GitHub #2696 copy value + const currentMessage = {...value} + let newMessages; + + if (Array.isArray(currentMessage)) { + for (let i = 0; i < currentMessage.length; i++) { + currentMessage[i].id = messageIdx++; + newMessages = [...this.state.messages, ...currentMessage]; } + } + else { + currentMessage.id = messageIdx++; + newMessages = this.state.messages ? [...this.state.messages, currentMessage] : [currentMessage]; + } - this.state.messages.length === 0 && ZIndexUtils.set('toast', this.container, PrimeReact.autoZIndex, this.props.baseZIndex || PrimeReact.zIndex['toast']); + this.state.messages.length === 0 && ZIndexUtils.set('toast', this.container, PrimeReact.autoZIndex, this.props.baseZIndex || PrimeReact.zIndex['toast']); - this.setState({ messages: newMessages }); - } + this.setState({ messages: newMessages }); } }