Law firms cannot act for a party they've acted against (and vice-versa) without a waiver from their existing client. It can be costly for a firm if they make that mistake.
They can, however, take on competing companies for a single action if they all agree. It's probably best if the firm didn't have a prior relationship with any of them.
(Not a lawyer but I am a software developer who's built a legal conflict of interest search system)
Yes, this is a key difference between the US "law firm" system and the UK barrister "chambers" system. The first is focused on profits (and survival). The second seeks to reduce the inherent commercial conflict of interest during difficult cases.
I think most law firms would represent competing companies in separate cases. Conflict of interest is more representing multiple parties in the same case or issue.
E.g. I once had a lawyer review a severance agreement before I signed it, since it had non-compete language in it. He had to be sure that his firm didn't already have a relationship with the employer.
If there's no common interest in the case, lawyers are expected to be able to maintain confidentiality. Same as an accountant who might have two competing businesses as clients.
They can, however, take on competing companies for a single action if they all agree. It's probably best if the firm didn't have a prior relationship with any of them.
(Not a lawyer but I am a software developer who's built a legal conflict of interest search system)