“Uprooting an entire supply chain is a nightmare task,” said Jon Cowley, an attorney in the Hong Kong office of Baker McKenzie, a global law firm, who advises corporate clients on tariffs and supply chains. “It takes years, if not decades.”

President Trump warned this past week that he was concerned about the influx of goods from Vietnam. The surge could invite scrutiny from the Trump administration if it believes that companies are pretending to make products outside China but are simply clipping together Chinese-made parts.

Still, China has few options to stop those shifts. Trade between the two countries is so lopsided that China has many fewer American imports to tax. It could slam American companies that sell vast amounts of products in China, like Apple or General Motors, but pinching those companies could hurt the Chinese workers who make those products.

Its strategy so far has been to target agricultural goods from states that Mr. Trump would need to win if he hopes to be re-elected in 2020. The strategy has worked. American farmers have suffered from a loss of sales to China and have been urging the White House to resolve the trade war. To help cushion the blow, Mr. Trump rolled out two rounds of financial support to help subsidize the farmers. But China’s dangling of agricultural purchases in front of Mr. Trump appeared to once again persuade the president to back off from his bigger threat, saying farmers “are going to be a tremendous beneficiary.”

On Saturday, Mr. Trump said China had agreed to resume purchasing some of the farm goods and other products that it has not been buying lately in retaliation for the American tariffs. “China is going to be buying a tremendous amount of food and agricultural product and they’re going to start that very soon, almost immediately,” Mr. Trump said in remarks in Osaka. “We’re going to give them lists of things we would like them to buy.”

Mr. Trump’s position could change if the American economy slows or if financial markets take a hit. While the trade war may be popular among Mr. Trump’s base and in some parts of manufacturing swing states, and resumed farm purchases could improve its image, it is disliked by the electorate at large.

Even then, leaders from both major American parties have indicated that the United States could continue to take a tough line on China no matter who is in the White House. The attitudes toward Huawei, in particular, show an appetite on both sides of the aisle for taking a tough line. Mr. Trump on Saturday said he would allow American companies greater leeway in selling their products to the Chinese telecom giant. His comments provided little clarity on which companies might be able to resume sales. The technology industry has argued that it should be able to sell products to Huawei that do not pose a threat to national security.