SHANGHAI — The Nets came to China to help grow their footprint and set down roots in a huge basketball-mad market. But their first appearance on this weeklong trip has already been shut down by the government.

Just hours before the Nets players were supposed to take part in an NBA Cares event at the New World Experimental School in Shanghai, the event was cancelled by the Chinese government in wake of a swirling controversy touched off by Rockets general manager Daryl Morey’s tweet regarding the Hong Kong riots, and how the tweet incensed many in mainland China.

The Education Bureau shut down the event — a dedication ceremony for the new NBA Cares Learn and Play Center in Shanghai – with no explanation given to the media.

The event was nixed not so much because of fear the players would be put in the awkward position of answering questions about the festering situation, but more out of the Chinese government’s hurt feelings over Morey’s comments.

It’s unclear whether the Lakers’ NBA Cares event Wednesday will be impacted.

What’s clear is the league now has a full-fledged situation on its hands.

The Nets face the Lakers on Thursday in Shanghai and in Shenzhen two days later. Shenzhen is close to Hong Kong, a city that may well be at the root of the issue.

Morey — who reportedly has friends in Hong Kong — waded into the politically charged situation with a tweet that appeared to support the months-long protests in that city. The tweet predictably got pushback in China, which has more than 1.3 billion people and is the NBA’s biggest international market.

Now the NBA is caught trying to play defense in a situation it clearly didn’t anticipate.

New Nets owner Joe Tsai penned an open letter about the testy situation on Facebook. With more than 300 million Chinese playing basketball, and twice that many watching NBA content last season, it’s a vital market for the league’s global growth.