So, that's my point.
"Ready an action to drink this potion when I get attacked".
They get attacked first. Then they turn invisible.
"Ready an action to drink this potion when the enemy gets within 5 feet of me".
Even if the player says "I run up and attack" is really a concatenation of "I use X-amount of my movement to move up to this guy. -pause- I use the Attack action"
It's during that pause, before the action is really declared, that the ready would "trigger"