Who succeeds when the prime minister dies?

"The deputy Prime Minister immediately takes on the duties of the PM until the monarch invites someone to be the new Prime Minister."

This is incorrect if you are referring to the UK office of the Prime Minister. The Deputy Prime Minister is an honorary post which carries no responsibilities or right of succession. If the British Prime Minister died in office or was otherwise removed, the majority party would have to elect a new leader and then present him or her for approval to the Monarch.