That's not generally a requirement of operating in China. It's much more of a trope than actual reality. Many, many large foreign companies have operated in China for decades, without losing their IP.
They will if the US threatens them with sanctions or requires export licenses and they see their value in the US market being greater than the CN market.