You fold preflop. Small to medium suited connectors are some of the most overvalued hands in poker, and the potential for getting over-flushed is just one of multible issues with these hands. Nearly everyone loses money with suited connectors, so if you treated them like junk and always folded them, your results would almost certainly improve significantly compared to, what they are now.
Ok this is a bit of an exaggeration, but nearly everyone play suited connectors far to often and almost nobody play them to rarely. They should also usually be played with agression, so that ideally you dont even get to see a flop or at least not make your flush, because at that point your opponent has already folded.
With that being said, if you correctly enter a hand with a suited connector, like for instance by open raising from BTN and getting called by BB, and you end up getting over-flushed on a 3-flush board, then it is usually just a cooler, and there is no way to avoid getting stacked. On a 4-flush board its a different story though, since a million different hands then beat a 7 high flush.