Whatever happens when Taiwan’s voters go to the polls on Saturday, its president, Tsai Ing-wen, has made a truly remarkable comeback. Just over two years ago, her Democratic Progressive party (DPP) was humiliated in the midterm local elections. A year ago, her prospects of reelection looked so dim that senior party figures urged her not to run again. Yet for months, polls have given her a hefty lead over her main challenger.

Ms Tsai can take some credit. The shock of 2018’s result was a wake-up call. The impact of controversial pension reforms which fuelled that defeat has largely been absorbed. The economy is improving, with wage growth and high employment.

Yet her resurgence is also down to the men she faces: Han Kuo-yu of the Kuomintang (KMT) in the election, and in the broader sense, Xi Jinping, the Chinese president. Han, a socially conservative, populist figure seized the mayoralty of Kaohsiung as an energetic campaigner. But the “Han wave” has ebbed and while some remain devoted, he has proved deeply polarising – while his performance in office has impaired the KMT’s positioning as the party of competence and good management. His calls for closer ties with Beijing have been toned down as he slides in the polls. While domestic issues tend to loom larger in the simultaneous parliamentary contest, Ms Tsai has ensured that cross-straits relations have dominated the presidential race. Her party has campaigned on the slogan “Resist China, Defend Taiwan”.

Though the self-ruled island has never been under the jurisdiction of the People’s Republic of China, Beijing regards it as a renegade province which must return to the fold. The KMT fled there after losing the civil war in 1949, but since the decades of one-party rule ended, it has increasingly emphasised its capacity to manage good relations with Beijing. Ms Tsai’s predecessor, the KMT’s Ma Ying-jeou, oversaw a significant thaw. But when the DPP returned to power Beijing turned up the pressure, clamping down on tourism and signing up more of Taiwan’s few remaining allies.

In January, Mr Xi gave a speech telling Taiwan that unification was inevitable, and that Beijing reserved the right to use military force to achieve it. Though the content was not a departure from previous statements, it unsettled and angered many in Taiwan, where a generation has grown up taking democracy as a given, and where many watch the trajectory of Mr Xi’s China with fear. Hong Kong’s protest movement, and the response of authorities, have sharpened those anxieties and solidified support for Ms Tsai. Concerns about Beijing’s impact have been exacerbated by a Russian-style influence and misinformation campaign during the election itself and by the KMT’s choice of strongly pro-unification candidates for its party list in the legislative contest.

Should Ms Tsai win on Saturday as expected, and especially if her party wins the parliamentary election, this will be an astonishing turnaround. It will also be the easy part. Negotiating cross-straits relations in the next term will be a far harder task. Yet Beijing too has a problem. It has pinned its hopes to the KMT: another bad defeat for the party will be confirmation that its strategy has failed. What next?