This an iTerm2 bug and has likely been fixed in https://github.com/gnachman/iTerm2/commit/223eacd424db38e0a5b7c93b48bcde06af1bafbd.
You can track this in:
https://gitlab.com/gnachman/iterm2/-/issues/12039,
https://gitlab.com/gnachman/iterm2/-/issues/12266.