Traditionally speaking, it's because they're the most qualified to do it. Every FAANG company takes from Open Source in order to succeed, so contributing back to a FOSS codebase is the ultimate act of corporate goodwill. You are burning real-life money and engineering hours to fix a problem for everyone and ensure that it stays protected under the same Open license that let your company succeed.
There is no legal obligation per-se. Open Source is a charity, but you can understand a lot about a company's motives if you compare their FOSS usage to their FOSS contributions.
It’s not a charity if it becomes or serves as part of a standard. Sort of how semis and the various suppliers/buyers of that industry wind up agreeing on standards despite being competitors in some cases. Definitely things like the Linux kernel make sense to give back to - you’re ensuring the kernel lines up with your own corporate investments in a sense. A company unilaterally needing to fork and maintain their own Linux compatible kernel would need to sink a lot of time and money to come up with something as developed as the modern kernel. And it would become more expensive, unwieldy, and akin to technical debt over time.
It’s clearly not perfect calculus since so many defect from OSS, but there’s also clearly some business sense there.
> It’s not a charity if it becomes or serves as part of a standard.
Then it just transitions to a charity that everyone relies on. It's been embarrassingly difficult for people to admit this vis-a-vis Linux and the like, but it's obvious in a situation like programming languages. We rely on the enduring charity of it's authors, license-holders and distributors to write and distribute software.
"Giving back" is not an inherently cynical process. Meta has no obligation to publish these patches in the first place, much less work as a part of the community to solve a common issue. But they do, and it's just kinda part of their culture at this point. Yes, they do still gain from it; but so do their direct competitors. It's difficult to characterize as a purely business-motivated decision, because there are much greedier avenues to pursue if that's their MO.
I think this misses the point. FAANGs don’t improve OSS code out of goodwill, they do it because it benefits them. Upstreaming those improvements has very little marginal cost, and it bolsters an environment where other companies do the same. Rising tide and all that.
There is no legal obligation per-se. Open Source is a charity, but you can understand a lot about a company's motives if you compare their FOSS usage to their FOSS contributions.