Nobody moved factories anywhere. Western retailers stopped buying from their own companies and instead bought from Chinese companies that subcontracted for them. If they "moved factories", they could easily move them back, since they're wholly owned by foreigners and under foreign control. They can simply accept subsidies for it, even. But they can't. They don't own those factories. The relationship is not boss and worker, it is customer and supplier. At worst they can stop buying from those suppliers, but then their competitors will, and they'll go out of business. That is why they have such a hard time exploiting and controlling China, yet have such an easy time exploiting and controlling 3rd world countries.
And it wasn't FDI that changed China's economy.
FDI flows into China never exceeded 7% GDP. Exports as %GDP never exceeded 40% (contrast to over 100% for Vietnam, Germany, South Korea, etc).