GOP leaders should have thought this through before now.

Donald Trump’s post-convention meltdown has cost him in the polls and led some high-profile Republicans to disavow his campaign. Already, there is pie-in-the-sky talk among Republicans that Trump will drop out of the race. While this may seem unlikely — the 2016 presidential race has already seen more than its share of unlikely events and historic firsts — it highlights a serious problem for our political system. The political parties' plans for what to do in a worst case scenario, in which they need to replace a candidate, might cause them great trouble in November.

Replacing a candidate is not an unheard of scenario. No candidate has ever dropped out before the popular vote takes place, but in 1872 Horace Greeley died at the end of November — well before the Electoral College cast its ballot. Candidates for president or other offices — from Paul Wellstone to Robert Kennedy — have died or were assassinated during their run for office. George Wallace was shot in 1972 while making a strong bid for the Democratic nomination. Teddy Roosevelt was wounded during his unsuccessful run in 1912. It has also happened repeatedly in other countries, including in Mexico in 1994. Today, terrorists are always looking for a big moment.

And twice, we have had to replace vice presidential candidates. President Taft’s vice president, James Sherman, died before the vote in 1912. As Taft finished third in November, there was no great focus on his replacement. George McGovern's running mate selection, Thomas Eagleton, resigned post-convention after revelations that he had undergone electroshock therapy for depression. In that instance, the Democratic National Committee held an emergency meeting and ratified Sargent Shriver. But a VP is not the same position as a president. The DNC acted as a rubber stamp for the presidential nominee traditionally empowered to choose his running mate.

If the party actually had to select a new presidential nominee, we would likely see a chaotic scramble for a replacement and a tanked presidential race that could damage the party down ballot.

Based on votes and national convention delegates, it may seem that there is a clear second choice candidate in each party: Bernie Sanders for the Democrats and Ted Cruz for the Republicans. But the primary runner-up frequently gets the most votes by an obstinate refusal to drop out — we saw this in 2008 and 2012 on the Republican side. Often, the result is bad blood between supporters of the winner in each party and supporters of each runner-up. That's certainly the case this year.

Now that the conventions are over, if Trump were to drop out the Republican Party’s national committee would presumably be making the choice. The committee's dozens of members are not familiar to most Americans, and party insiders are not a particularly popular group these days. The fact that they are the ones making the choice might make it less chaotic but no less controversial, particularly if they choose a replacement who was not among the top vote-getters in the primaries.

The parties would also run into legal issues of replacing the candidate on the ballot. Each state has its own ballot replacement laws, and after a certain period, a change cannot be made.

Even worse is a situation in which there is a replacement needed between the popular vote in November and the Electoral College ballots being cast and then counted in January. It’s not clear that a replacement can be named, which may result in the election being thrown to the House of Representatives.

If Trump or even Clinton would somehow drop out of the race, their party would be faced with a historic mess. While it’s not clear what party leaders can do to prevent it, they probably should have spent some more time thinking about before now.

Joshua Spivak is a senior fellow at the Hugh L. Carey Institute for Government Reform at Wagner College. He writes the Recall Elections Blog.