Basic supply and demand along with every study I've seen points to housing supply being one of and usually the main factor in the level of homelessness of a city.
As to San Francisco homeless coming from outside the Bay Area, that's true for only around 10% of the population. Most (70%) became homeless in San Francisco and many others became homeless in other parts of the Bay Area. See the `PLACE OF RESIDENCE` section from https://hsh.sfgov.org/wp-content/uploads/2020/01/2019HIRDRep...
As to San Francisco homeless coming from outside the Bay Area, that's true for only around 10% of the population. Most (70%) became homeless in San Francisco and many others became homeless in other parts of the Bay Area. See the `PLACE OF RESIDENCE` section from https://hsh.sfgov.org/wp-content/uploads/2020/01/2019HIRDRep...