When a parachain lease ends, it becomes a parathread, and its existing state root and Wasm stays on the relay chain.
When the parathread protocol is complete, a chain in this state would still be able to produce new blocks, but it may need to pay per block, rather than being guaranteed to get a new block for free like a parachain.
As such, a parathread can also simply win a new auction and be re-upgraded to a parachain, and in this case, everything moves forward like normal.
So your statement:
How does the parachain re-connect to the relay without losing it previous state?
Assumes that some state is lost, but this is not true.
If a parathread was fully offboard, and all state deleted, it would be possible to re-onboard with the old state root and Wasm, and things would appear to work just like before. The only potential issue here would be that they may have a different ParaId
, and so other chains that interacted with them would need to migrate their past storage, or we could use governance to try and let parachains re-register their old ID.