I discussed before on this blog just how expensive it is for the U.S. to have a military commitment to protect Taiwan from China. In fact, it costs us $3,000 per person who lives in Taiwan per year, or so, to protect it.
This said, this expenditure will have the desired effect as long as it remains in place. China simply has too much to lose. If China attack Taiwan, U.S. trade with China stops instantly. All merchant ships en route are rerouted to Japan. All accounts not settled are not paid. U.S. Treasury bonds owned by China are cancelled as punishment and all Chinese assets in the U.S. or in the possession of its allies are frozen. Even if Taiwan is taken, it is after a pitched and bloody battle including U.S. strikes on Chines missile bases, ports, ships and airfields. Chinese trade with any other nation by sea, including Japan and S. Korea, becomes impossible. Oil and gas pipelines into China are bombed. China must either let U.S. nationals leave, which they (and most foreign nationals) will, or there will be an epic hostage crisis. If there is a hostage crisis, China can kiss all foreign investment for the next decade or two goodbye. If the U.S. or its military bases were directly attacked, one can imagine a U.S. stance towards China being even more punitive. In short, China has little to gain and would see its entire economy crumble for decades as a result. Ergo, China will not invade Taiwan, despite its bluster to the contrary, unless it feels that it can make a threat of nuclear attack on the U.S. viable enough to prevent U.S. intervention (unlikely).
The more likely scenario might be instead for the Chinese Navy to, after warning ships off, blockade Taiwan's ports. If a Chinese submarine sunk a Liberian flagged merchant ship off the coast of Taiwan, a full fledge military response from the United States would be much less likely. The U.S. Navy might move in with anti-submarine warfare ships to aid Taiwan, and trade sanctions might be imposed. But, this kind of situation might not escalate quite as far. As a result, this kind of incident is actually more probable.
How a blockade situation would play out militarily is hard to predict. One of the main "lessons learned" from the Falkland's War between the United Kingdom and Argentina, is that it is extremely hard to find and destroy a submarine will a skilled crew. Some modern diesel submarines are far quieter than the noisy Russian nuclear submarines that our attack submarine fleet was designed to catch, and there were a number of incidents during the Cold War when foreign submarines got close enough to U.S. Navy surface ships to sink them. China's submarine fleet is second only to those of Russia and the United States, and is growing rapidly in both number and sophistication. Also, even if China were to refrain from attacking ships bound for Taiwan with military escorts, the increased cost and risk associated with shipping goods to Taiwan (which as a small island is heavily dependent upon seaborne imports) would be crushing. On the other hand, the U.S. could easily counterblockade China. Whether such a standoff would result in one side or the other backing down, or would escalate might easily depend upon the personalities involved on each side.