My old 2017 MBP met that fate after mere couple of years, these machines tend to run annoyingly hot (I can hear it right now from the other room - partner is still using it). When it was mine, I kept using it with the lid closed (because the internal screen+keyboard were useless to me). I totally wasn't expecting the battery to suddenly become a spicy pillow! The Apple tech was a little bit scared to touch it, said it's gonna take a while to repair, I guess they can't open this sort of thing on site.
Of course some things changed with M1 (less hot) and later macOS updates (smarter/delayed charging), but the general advice applies to literally any device with a battery.
Some relevant links for Macbook and Thinkpad owners: https://github.com/davidwernhart/AlDente-Charge-Limiter https://www.thinkwiki.org/wiki/tp_smapi
So the battery stays about 80% charged and gets topped up to 80% intermittently when it naturally discharges. Is that not basically they optimum case for battery longevity?
Regardless, all of my MacBooks eventually have battery problems whether they were plugged in all the time or not: it is extremely common for MacBook batteries to eventually get so damaged they start to swell and either need to be replaced or crack the case (and that's ignoring the fire hazard).
For UPS applications you can use 3rd party software to force the battery to stay at 80% charge and lose less capacity per year.