Unfortunately, I am not aware of a workaround for this bug, so your only option would be to use Arduino IDE 1.8.16 until the bug in Arduino IDE 2.x is fixed.
If anyone has any ideas about a fix/workaround, or any other information about the issue, please do comment here. Unfortunately, I have not been afflicted by this problem. I say "unfortunately" because I'm a beta tester and would be able to more effectively investigate the problem if I could reproduce it myself.
If you have a GitHub account, you can subscribe to the issue report in order to get notifications about any progress the developers have on finding a fix. If you do that, please subscribe to this bug report:
I didn't notice while making my previous reply that the bug report I linked to had been closed as a duplicate https://github.com/arduino/arduino-ide/issues/437 will be used as the sole unique bug report for tracking the situation.