> Treaty
When Taiwan peacefully became a democracy (at the end of authoritarian rule by the Nationalists) it became very hard for the USA to just abandon Taiwan to the loving hands of the Communist mainland.
Second, my understanding, is that the population of Taiwan is about 50% indigenous Taiwanese and 50% descendants of Nationalist Chinese who fled the mainland in 1949. The indigenous Taiwanese want nothing to do with mainland Red China and it's the descendants of the Nationalists that are more ambivalent about reuniting with the mainland. This may have changed after China's heavy hand in Hong Kong.