That comparative advantage thing isn't just about cheap labour in a country supplying the avarice of another country.
It can reflect underlying advantages in other respects, such as location of source materials, and availability of energy for production in relevant quantities.
Below some threshold of energy use to transport, it will use less energy overall to produce some goods far away and transport them, than to produce them locally.
I'm not sure if shipping on the oceans is below that threshold, but I wouldn't be surprised because it's pretty energy efficient for the amount transported.
Let's stop pretending this has anything to do with natural resources or energy costs.
This is 100% about the cost of labor, and the fact that China is moving poor rice farmers out of the country and into these jobs and giving them exactly zero labor benefits or protections
Even if we moved it out of China, production for this kind of thing would still rarely be local.
And factory wages in China are rising. The money saved isn't that big. The huge and currently enduring advantages areas of China have are in supply chain availability.
And the bigger your facility is, the more efficiently you can transport things in and out. Very local production means work trucks running around wasting fuel all over.