That depends on the layout engine, I believe. Just tried it in Firefox (on macOS; not sure if it uses Core Text or something custom there), and it does sometimes break around the em dash in "foo—bar" style, not just "foo – bar" style.
I've definitely noticed the behavior you describe on some layout engines, too, and it's another reason why I personally prefer "foo – bar" style.
I've definitely noticed the behavior you describe on some layout engines, too, and it's another reason why I personally prefer "foo – bar" style.