Elon Musk has changed his mind again. Tesla won’t be taken private after all. Following three weeks of market tumult triggered by Musk tweeting that he wanted to privatize the electric carmaker, the tech billionaire has abruptly reversed course, writing in a blog post on Friday that he’s dropping the plan. Although the decision won’t resolve the regulatory and legal issues his wayward tweet has caused, at least it will allow Musk to focus on problems elsewhere, like the increasingly fierce competition Tesla is facing in China.

The company has long planned to expand its presence in the country, which is the world’s largest market for electric vehicles. It recently announced plans for a Gigafactory in Shanghai, with an estimated cost of $2 billion that’s expected to be funded mostly by loans from a local bank. The factory will initially produce 250,000 of Tesla’s mass-market Model 3 sedans and battery packs annually starting in 2021, with the capacity to double over time.

At first glance, Tesla seems to be an obvious winner in China. Last year, the country’s buyers accounted for more than half of the 1 million units sold globally. Unlike the U.S., China’s policymakers have never wavered in their support of electric vehicles. Beijing has been eager to cut pollution and reduce oil imports, wanting to put as many as 7 million clean energy vehicles on the road by 2025.

Tesla also stands to benefit from China’s phasing out of foreign ownership caps on auto ventures. Its Shanghai factory will be solely owned by the American company, allowing it to have better control over the production process, while protecting its core technologies and eliminating the need to share revenues with a local partner, says Alex Xie, a partner at the Boston Consulting Group.

Meanwhile, manufacturing locally will also help Tesla avoid the 40% tariffs Beijing recently levied on autos imported from the U.S. amid tit-for-tat trade tensions. A specific location hasn’t been announced yet, but if Tesla builds the factory outside the city’s free-trade zone, the cars produced there will be classified as local, says Wang Jiajia, an analyst at consultancy IHS Markit.

A Tesla Model 3 sedan sits next to a Model X on display outside a showroom in Littleton, Colorado on July 8, 2018. (AP Photo/David Zalubowski)

Keeping prices low will help Tesla attract more customers from the country’s growing middle class. Last year, it sold about 10,000 cars in the country, but mostly to wealthier consumers, estimates John Zeng, director of China forecasting at consultancy LMC Automotive. This year, Tesla hiked prices of its Model S and Model X cars in China by as much as $30,000 due to higher import duties. Tesla did not respond to multiple requests for comment.

“Tesla really needs China,” Zeng says. “ If it doesn’t establish a bigger presence in China, then its position in the global electric-car market will be threatened.”

Tesla will be the first foreign automaker to build a local supplier network and navigate the country’s regulatory whims without the help of a Chinese partner. But whether the company can continue to grow its sales in China is anything but certain, analysts say.

“Without a local partner, Tesla could be at a disadvantage when it comes to marketing and finding local resources.” says Wang of IHS Markit. “In China, the competitive pressure is much higher because everyone is setting their sights here.”

Currently, Shenzhen-based BYD, an automaker backed by billionaire investor Warren Buffett, is China’s top seller, shipping 113,600 new-energy cars last year. Global auto brands from Ford Motor to Volkswagen have set up joint ventures in the country, pouring tens of billions of dollars to make electric cars there and enlisting local partners to help build sales channels and promote their vehicles. New models expected to hit the China market in the next few years include BMW’s iX3, Audi’s e-tron and Mercedes-Benz’s EQC, making competition in the country even more cut throat.

And Tesla’s rivals appear to have no difficulties in accessing capital. Earlier this month, Chinese electric-car startup Xpeng raised $587 million at a $4 billion valuation in its latest funding round. The company hasn’t shipped a single vehicle to date, but investors, including Chinese e-commerce giant Alibaba, are betting that it will one day become the Tesla of China. William Li, the founder of Shanghai-based electric car maker Nio, is already a billionaire. He's building glitzy showrooms across the country for his 7-seater electric SUV ES8 and other electric race cars. The Tencent-backed company has filed to go public on the New York Stock Exchange, seeking to raise $1.8 billion.

He Xiaoping, co-founder and chairman of Xpeng Motors Technology. (Photo by Giulia Marchi/Bloomberg)

To be sure, Tesla isn’t without advantages of its own. Starting from 2021, Beijing will end its subsidies for electric vehicles manufactured locally, putting everyone on the same footing. There’s also a possibility that Tesla might bring in outside investors to its China unit for further funding, BCG’s Xie says (Chinese web giant Tencent already has a 5% stake in the automaker). And the company still holds the lead in electric car technology, especially in its battery management systems that lead to better vehicle performance, according to Zeng.

“In terms of technology, Tesla still leads, but local players are catching up with Tesla's operational ranges,” he says. “By 2020, the technology gap will be further reduced and Tesla’s advantage will be smaller.”