> mainly because their domestic production was good enough that foreign goods couldn't compete
Most international trade (well intercontinental anyway) was restricted almost exclusively to luxury goods. And Europe didn't have to export in that regard besides glassware up until the 19th century. Transportation costs were way too high to export/import anything that might have taken up more space across long distances (especially over land).
After the industrial revolution imports to China remained at relatively very low levels due to heavily protectionist policies by the imperial government until the opium wars.
Obviously opium was the most egregious example and by modern standards China clearly had the right to restrict its imports. Opium just happened to be the most profitable one, however importing anything else (like cotton, furs, steel tools, mechanical items) besides gold/silver was very hard as well which why (amongst other thing) many Chinese people living on the coast weren't that keen on supporting the government (of course China was in sate of near permanent civil war and endless revolts during most of the century).