How to prevent iTerm2 from creating overlaps and broken lines after pasting multiline chunks of text?

From docs:

Pastes (both regular and slow) are done by splitting the text to paste into chunks. There is a delay between the transmission of each chunk. To change the speed that "paste" pastes at:

defaults write com.googlecode.iterm2 QuickPasteBytesPerCall -int 1024
defaults write com.googlecode.iterm2 QuickPasteDelayBetweenCalls -float 0.01

To change the speed that "paste slowly" pastes at:

defaults write com.googlecode.iterm2 SlowPasteBytesPerCall -int 16
defaults write com.googlecode.iterm2 SlowPasteDelayBetweenCalls -float 0.125

In my case it was caused by the fact that I am using zsh-autosuggestions plugin for ZSH.

What solved this was adding this line to my .zshrc:

zstyle ':bracketed-paste-magic' active-widgets '.self-*'

as suggested in this comment.