You can place a bit more blame on the US companies that let it happen. The people running them are short-sighted and unpatriotic.
The real problem is that the law allows companies to be in a race to the bottom that is ultimately self-destructive. Allowing non-citizens to get access to the IP should be illegal. If it were, then bringing that IP to a location controlled by China's contradictory law would be a violation.
You can't fully stop spies, but you sure can make it illegal to simply hand things over without a fight.
Samuel Slater is a fine example. He was a spy. He broke the law. The USA would have gotten the technology years earlier if the UK had simply handed it over. Picture that: the USA demands that textile factories be built in the USA, as joint partnerships with technology transfer. The UK wasn't that stupid.