The correct answer is as far upstream as you need to in order to swim/wade/jump across the stream and still provide the margin for error you are comfortable.
The problem answering the question in a more straight forward manner you have waterfalls like victoria falls (pictured below) that would almost certainly result in a fatal fall if you were to go over, but the chance of flushing over even when on the edge of the waterfall are low because of the depth and flow at the lip.
To Contrast here is huka falls, a waterfall that even hundreds of meters upstream you cannot safely cross because of the heavy currents and lack of exit points from the river.
In general you should avoid any water crossing with any meaningful current; unless you have whitewater experience or you can maintain your footing, shin deep or less, the entire time.
In an emergency type scenario ropes can be helpful to mitigate risks, but require careful application as they add complexity to a potentially dangerous situation. Again experience goes a long way.
Edit: I should probably add the Victoria falls is not actually travesable all the way across the lip, but was used as an extreme example of getting close to a lip of a waterfall in one location.
Source: I'm a whitewater enthusiast who has willingly gone over numerous waterfalls and navigated safely around even more using a variety of watercraft, swimming, wading etc.