Unfortunately, first to invent is not that simple.
If someone comes along and patents the formula to Coca-Cola without having any knowledge of Coke's trade secret, there is very little Coke can do about it even though they were first to invent.
It actually is that simple, as long as you can prove that you were first to invent. In your scenario, Coke would have no problem invalidating the patent.