The bug
After attributing yourself with a higher max health then dying the previous row added becomes ghost hearts not regenerating or giving extra hearts.
How to reproduce
Make sure your health/hunger bars are full
Run these commands in order while in survival mode:
/attribute @s minecraft:generic.max_health base set 40 /attribute @s minecraft:generic.max_health base get
✔ notice the result is 40, and the health bar has doubled and will slowly regenerate a bit
Now run these commands:
/kill @s /attribute @s minecraft:generic.max_health base get
❌ notice how it now says 20 and the hearts in the top row are now empty and refuse to regenerate
Linked issues
relates to
Attachments
Comments
Also unable to reproduce in 21w06a.
Could you please provide steps to reproduce, as well as the exact commands used?

I was only able to reproduce the "ghost" hearts that don't regenerate, in this very 20w17a snapshot. In any newer version of the game, even 1.16.5 and 21w06a, these hearts don't show but your health is still reduced back to 20.
I am unable to reproduce this issue in 20w51a.