The Board of Supervisors in San Francisco approved a controversial law on Tuesday that legalizes for the first time — with some crucial caveats — short-term rentals in Airbnb's hometown.

The bill attempts to navigate a third way between creating a carte blanche for "homeshares" (as some of its advocates would like) and banning them all together (as opponents in cities like New York have demanded). In one of the most expensive cities in the U.S., the law also tries to strike a balance between fiercely competing claims about what happens to housing affordability when just about any home can suddenly become a part-time hotel.

Under the new law, which Mayor Ed Lee is expected to sign, permanent residents of San Francisco who want to rent out their homes through services like Airbnb will have to register with the city for a permit and pay hotel taxes on the income they earn. The law limits rentals to 90 days a year, effectively preventing residences from converting into year-round hotels. Because the law applies only to permanent residents renting out their own homes, its protections also likely won't extend to out-of-towners with permanent vacation homes in San Francisco on sites like VRBO.

Until now, rentals of less than 30 days in private homes were technically illegal in the city, although the ban was seldom enforced.

Airbnb and its backers, who've been well-organized in San Francisco, have argued throughout the public battle that short-term rentals help keep the city affordable for residents who wouldn't be able to cover their rent or mortgage payments without the extra cash that occasional tourists bring. Tenant organizers, on the other hand, contend that Airbnb does just the opposite: By enabling people to rent homes (or bedrooms in them) to tourists instead of locals, the service cuts down on available housing and drives up the cost of the scarce housing that remains. Currently in the city, about 5,000 homes are listed on Airbnb.

In some ways, this debate is particular to San Francisco, a city where housing supply has massively struggled to keep up with demand (thanks both to an influx of new residents and long-time limits on new construction). In San Francisco, to a much greater degree than Chicago or Atlanta or New Orleans, Airbnb has become a wedge between housing organizers and "sharing economy" enthusiasts. The policy battle over its business model has become one largely about the cost of living.

It's unclear at this point whether the city's new law, set to go into effect in February, really can serve both goals: protecting the housing supply, while also aiding residents who have to rent out their homes just to afford living in them. Much will depend on how (and how well) the city enforces the new rules. Tuesday night, though, Airbnb was celebrating.