You can always back up the secret ID on, for example, a piece of paper, if you don’t want to use a TOTP app with sync/backups (there are several, both proprietary and FLOSS)
if using normal TOTP apps, print the QR code and store it somehwere secure. It’s a risk, but it’s one part of the puzzle needed and it reduces a more likely risk of being locked out.
Microsoft Authenticator and Authy both backup to the cloud. I also have a non-Microsoft email linked to receive 2FA codes, as well as 2 hardware security keys, and an account recovery code. I think I'm covered.
I always keep both.