There will be no chance of the United Kingdom making a success of Brexit if Scotland votes to break up the kingdom. And although the immediate danger of that happening appears to have passed — the Scottish National Party lost ground in the general election and Nicola Sturgeon doesn’t speak anywhere near as much about independence nowadays — this could change if Brexit is mishandled.

When Britain leaves the EU then Scotland leaves too — those are the rules, and Spain, which is not too keen on the idea of secession, will insist upon them. So Brexit in itself will make Scottish independence an even bigger risk. It will knock on the head the idea of ‘independence in Europe’ and force Scottish voters to make a choice between staying in the UK single market or applying to join the EU one.

The EU exit talks are acting as a reminder of just how complicated breaking up the United Kingdom would be. If disentangling yourself from a 40-year-old trade pact with some political aspects is this difficult, imagine what breaking up a 300-year economic, political and defence union would be like. But it would be foolish to think the Nationalist threat has gone away.

About two in five Scots still support independence and the SNP, as a party, is in better shape than any of its Westminster counterparts. It holds a majority of the Scottish seats in the Commons, governs at Holyrood and is still set to be largest party after the next devolved elections. The SNP might lose its majority for independence, but Ms Sturgeon is likely to be in Bute House for some time.

This is why it is so important not to mess up the EU withdrawal bill, which is currently paused as the whips try to work out how to avoid losing any votes on it. When the UK reclaims powers over, say, farm subsidies and fishing, to whom should these powers accrue? It ought to be obvious. If agriculture is devolved to Holyrood, then any new powers over farming ought to go there too. So the nationalists would have to admit that Brexit had led to a more powerful Scottish parliament and Welsh assembly.

But there’s a catch. As so often, the problem can be traced to the ill-thought-through Blair devolution settlement. When the Scotland Act and the Government of Wales Act were passed in 1998, no one gave any thought to what would happen if Britain left the EU. So if all of the 111 powers that are coming back from Brussels went to Holyrood, it could end up disrupting the UK single market. What if Scotland adopts different standards in food safety? Such concerns are reinforcing Whitehall’s instinctive desire to accumulate as many powers as possible. This has led to Clause 11 of the Withdrawal Bill which looks like an attempt to claim back previously devolved powers. This would allow the SNP to claim, with some justification, that Brexit looks like a London power grab.

Instead, it should be made clear that the overwhelming majority of these powers will go to Holyrood and Cardiff Bay. Armed with such ammunition, Ruth Davidson would be able to mock any SNP attempt to block the Brexit bill. She could ask: don’t they want these extra powers? Do they think Holyrood can’t be trusted with them?

Another complication is the Department for International Trade’s worry that trade deals would be harder to sign if Scotland and Wales don’t go along with various concessions that a UK government might make. But this fear is misplaced. The 1998 Scotland Act gives UK ministers the power to force their counterparts at Holyrood to comply with the UK’s international obligations. So trade deals can’t be derailed by what the devolved bodies do. There is no reason for Whitehall to keep hold of all but a handful of the powers coming back from Brussels.

Some cabinet members have been amazed at the extent to which civil servants are determined not to pass on any extra powers they acquire. But this might mean the EU withdrawal bill being blocked in Edinburgh or Cardiff. Legally, this could be overridden — but that would cause a damaging clash; one that could be exploited by the nationalists and would weaken the UK’s negotiating hand in Brussels. It could also provide the House of Lords with the justification that many peers are looking for to block the whole withdrawal bill.

But if the UK government is explicit about which powers would go where it will find itself in a far stronger position. It ought to be easy to satisfy the Labour-run Welsh government — which is, after all, unionist. The Scots would feel much less confident acting without the cover that the Welsh are currently giving them. Secondly, the SNP would find it hard to block extra powers for the Scottish parliament. If Sturgeon and her MSPs were to vote against, say, 80 new powers going to Holyrood, they would look ridiculous. They would, as they did with their precipitate push for a second independence referendum, fail the reasonableness test.

When the UK and devolved ministers met this week, they made progress. But London still plans to pass the EU withdrawal bill without making clear which powers would be devolved — in which case the Scots and Welsh would be voting blind. You don’t have to be a nationalist to think this a little unfair.

The depressing truth is that Scotland and Wales are the relatively simple aspects of Brexit and devolution. The Northern Ireland question is more complicated. The lack of an executive at Stormont and the fact that the Irish border is part of the first round of the UK-EU talks means that it has become detached from this parliamentary process. But it is nigh on impossible to see how some sort of border can be avoided, given that the UK will be outside the single market and the customs union, and the Republic inside them. The challenge will be to make border controls as light-touch as possible.

It is not a coincidence that the EU’s development has coincided with a rise of separatist sentiment in much of Europe. The EU offers an alternative to the nation-state — a different way to expand your market and pool risks. This is the reason why so many Catalan and Scots nationalists are such Europhiles. But once the UK has left, this argument will vanish and the traditional case for the Union may begin to assert itself again. In this way, a stronger union could be one of the many dividends of leaving the EU — but if, and only if, Whitehall gets the Brexit legislation right.