Uart seems not to clear

I’ve tested some stuff with UART recently and couldn’t figure out how to clear the UART buffer all the way.

Sometimes it worked like this and sometimes not:

while (Serial2.available())

I couldn’t figure out any other way to clear the buffer, anyone got an idea?

I use a WT32-WROVER-S3 board with the arduino framework…