I think I’ve seen somewhere that you can’t repeatedly do serial.available() at infinite speed. In any case not good do something like that too fast. Have to give the serial hardware and software time to do its own thing. 40 gives 25 mS/cycle. That’s probably faster than most users/applications care about and gives time for 25 chars to arrive at 9600 baud.
When I added the loop(), it started working, frameRate(40) was better. After I added the .bufferUntil I didn’t go back and try without the first two fixes.