The city’s economy is way more diverse than you’re suggesting. Biotech, law, finance, tourism, trade, etc. I have a feeling you have a tech-centric viewpoint at thus that’s what you see.
Pedantically, Zoom (San Jose) and Google (Mountain View), and most other Silicon Valley companies (Facebook, Apple, HP, Cisco, eBay, Intel, LinkedIn, Nvidia, Paypal, pre-move Oracle, pre-move Tesla) aren't headquartered in San Francisco. The city used to be this adjunct thing, close to the Valley. It's only until recently that it's become the focus.
SF invented its way out of its own reason for existing. Companies like Zoom and Google made it possible to work remote, and as the city never diversified its economy, no one really needs to live there. The absurd political situation, where it's illegal to build a house but legal to poop on the sidewalk while smoking meth, has made it also a place no one really wants to live in. It's a story of hubris and the satire writes itself https://babylonbee.com/news/san-francisco-store-clerk-confus...